package db import ( "errors" "go_dreamfactory/lego/utils/mapstructure" ) type Option func(*Options) type Options struct { MongodbUrl string MongodbDatabase string } func Set_MongodbUrl(v string) Option { return func(o *Options) { o.MongodbUrl = v } } func Set_MongodbDatabase(v string) Option { return func(o *Options) { o.MongodbDatabase = v } } func newOptions(config map[string]interface{}, opts ...Option) (Options, error) { options := Options{} if config != nil { mapstructure.Decode(config, &options) } for _, o := range opts { o(&options) } if len(options.MongodbUrl) == 0 || len(options.MongodbDatabase) == 0 { return options, errors.New("MongodbUrl or MongodbDatabase is null") } return options, nil } func newOptionsByOption(opts ...Option) (Options, error) { options := Options{} for _, o := range opts { o(&options) } if len(options.MongodbUrl) == 0 || len(options.MongodbDatabase) == 0 { return options, errors.New("MongodbUrl or MongodbDatabase is null") } return options, nil }