Skip to content

Commit

Permalink
Passing all configs by value
Browse files Browse the repository at this point in the history
  • Loading branch information
coolwednesday committed Nov 29, 2024
1 parent c6071e7 commit c58b08c
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/advanced-guide/injecting-databases-drivers/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ type Person struct {
func main() {
app := gofr.New()

db := mongo.New(&mongo.Config{URI: "mongodb://localhost:27017", Database: "test",ConnectionTimeout: 4*time.Second})
db := mongo.New(mongo.Config{URI: "mongodb://localhost:27017", Database: "test",ConnectionTimeout: 4*time.Second})

// inject the mongo into gofr to use mongoDB across the application
// using gofr context
Expand Down Expand Up @@ -458,7 +458,7 @@ import (
func main() {
app := gofr.New()

app.AddSolr(solr.New(&solr.Config{
app.AddSolr(solr.New(solr.Config{
Host: "localhost",
Port: "2020",
}))
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-guide/key-value-store/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type User struct {
func main() {
app := gofr.New()

app.AddKVStore(badger.New(&badger.Configs{DirPath: "badger-example"}))
app.AddKVStore(badger.New(badger.Configs{DirPath: "badger-example"}))

app.POST("/user", Post)
app.GET("/user", Get)
Expand Down
6 changes: 3 additions & 3 deletions pkg/gofr/datasource/kv-store/badger/badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type Client struct {
tracer trace.Tracer
}

func New(configs *Configs) *Client {
return &Client{configs: configs}
func New(configs Configs) *Client {
return &Client{configs: &configs}
}

// UseLogger sets the logger for the BadgerDB client which asserts the Logger interface.
Expand All @@ -53,7 +53,7 @@ func (c *Client) UseTracer(tracer any) {
}

// Connect establishes a connection to BadgerDB and registers metrics using the provided configuration when the client was Created.
func (c *client) Connect() {
func (c *Client) Connect() {
c.logger.Debugf("connecting to BadgerDB at %v", c.configs.DirPath)

badgerBuckets := []float64{.05, .075, .1, .125, .15, .2, .3, .5, .75, 1, 2, 3, 4, 5, 7.5, 10}
Expand Down
2 changes: 1 addition & 1 deletion pkg/gofr/datasource/kv-store/badger/badger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func setupDB(t *testing.T) *Client {
t.Helper()
cl := New(&Configs{DirPath: t.TempDir()})
cl := New(Configs{DirPath: t.TempDir()})

ctrl := gomock.NewController(t)
mockMetrics := NewMockMetrics(ctrl)
Expand Down
4 changes: 2 additions & 2 deletions pkg/gofr/datasource/mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ i.e. by default observability features gets initialized when used with GoFr.
// client.UseLogger(loggerInstance)
// client.UseMetrics(metricsInstance)
// client.Connect().
func New(c *Config) *Client {
return &Client{config: c}
func New(c Config) *Client {
return &Client{config: &c}
}

// UseLogger sets the logger for the MongoDB client which asserts the Logger interface.
Expand Down
4 changes: 2 additions & 2 deletions pkg/gofr/datasource/mongo/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Test_NewMongoClient(t *testing.T) {

logger.EXPECT().Errorf(gomock.Any(), gomock.Any(), gomock.Any())

client := New(&Config{Database: "test", Host: "localhost", Port: 27017, User: "admin", ConnectionTimeout: 1 * time.Second})
client := New(Config{Database: "test", Host: "localhost", Port: 27017, User: "admin", ConnectionTimeout: 1 * time.Second})
client.Database = &mongo.Database{}
client.UseLogger(logger)
client.UseMetrics(metrics)
Expand All @@ -49,7 +49,7 @@ func Test_NewMongoClientError(t *testing.T) {
logger.EXPECT().Debugf("connecting to MongoDB at %v to database %v", "mongo", "test")
logger.EXPECT().Errorf("error while connecting to MongoDB, err:%v", gomock.Any())

client := New(&Config{URI: "mongo", Database: "test"})
client := New(Config{URI: "mongo", Database: "test"})
client.UseLogger(logger)
client.UseMetrics(metrics)
client.Connect()
Expand Down
2 changes: 1 addition & 1 deletion pkg/gofr/datasource/solr/solr.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Client struct {
// client.UseLogger(loggerInstance)
// client.UseMetrics(metricsInstance)
// client.Connect().
func New(conf *Config) *Client {
func New(conf Config) *Client {
s := &Client{}
s.url = "http://" + conf.Host + ":" + conf.Port + "/solr"
s.client = &http.Client{}
Expand Down

0 comments on commit c58b08c

Please sign in to comment.