refactor: Update models to use DatabaseV2 instead of DataSourceV2

This commit is contained in:
Marvin Zhang
2024-08-05 13:14:57 +08:00
parent f38b11e7ed
commit fc28a742de
21 changed files with 44 additions and 54 deletions

View File

@@ -33,10 +33,10 @@ func GetMongoClient(opts ...ClientOption) (c *mongo.Client, err error) {
_opts.Host = "localhost"
}
}
if _opts.Port == "" {
_opts.Port = viper.GetString("mongo.port")
if _opts.Port == "" {
_opts.Port = "27017"
if _opts.Port == 0 {
_opts.Port = viper.GetInt("mongo.port")
if _opts.Port == 0 {
_opts.Port = 27017
}
}
if _opts.Db == "" {
@@ -123,7 +123,7 @@ func newMongoClient(ctx context.Context, _opts *ClientOptions) (c *mongo.Client,
mongoOpts.SetHosts(_opts.Hosts)
} else {
// hosts are unset
mongoOpts.ApplyURI(fmt.Sprintf("mongodb://%s:%s/%s", _opts.Host, _opts.Port, _opts.Db))
mongoOpts.ApplyURI(fmt.Sprintf("mongodb://%s:%d/%s", _opts.Host, _opts.Port, _opts.Db))
}
}

View File

@@ -8,7 +8,7 @@ type ClientOptions struct {
Context context.Context
Uri string
Host string
Port string
Port int
Db string
Hosts []string
Username string
@@ -36,7 +36,7 @@ func WithHost(value string) ClientOption {
}
}
func WithPort(value string) ClientOption {
func WithPort(value int) ClientOption {
return func(options *ClientOptions) {
options.Port = value
}