Skip to content

Commit

Permalink
make options a pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
tsawler committed May 6, 2024
1 parent 1cd1e24 commit 6ab8e59
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions v2/remember.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ type Options struct {
type CacheEntry map[string]any

// New is a factory method which returns an instance of a CacheInterface.
func New(cacheType string, o ...Options) (CacheInterface, error) {
var ops Options
func New(cacheType string, o ...*Options) (CacheInterface, error) {
var ops *Options
if len(o) > 0 {
ops = o[0]
} else {
switch cacheType {
case "redis":
ops = Options{
ops = &Options{
Server: "localhost",
Port: "6379",
Password: "",
Expand All @@ -67,12 +67,12 @@ func New(cacheType string, o ...Options) (CacheInterface, error) {
}

case "badger":
ops = Options{
ops = &Options{
BadgerPath: "./badger",
}

case "buntdb":
ops = Options{
ops = &Options{
BuntDBPath: ":memory:",
}
}
Expand Down
2 changes: 1 addition & 1 deletion v2/remember_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestNew(t *testing.T) {
ops := Options{
ops := &Options{
Server: testRedis.Host(),
Port: testRedis.Port(),
Prefix: "test_cache",
Expand Down
4 changes: 2 additions & 2 deletions v2/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func TestMain(m *testing.M) {
Port: testRedis.Port(),
Prefix: "test_cache",
}
testRedisCache, _ = New("redis", ops)
testRedisCache, _ = New("redis", &ops)
defer testRedisCache.Close()

testBadgerCache, _ = New("badger", Options{BadgerPath: "./testdata/badger"})
testBadgerCache, _ = New("badger", &Options{BadgerPath: "./testdata/badger"})
defer testBadgerCache.Close()

testBuntdbCache, _ = New("buntdb")
Expand Down

0 comments on commit 6ab8e59

Please sign in to comment.