git.zd.zone/hrpc/hrpc@v0.0.12/database/mysql/option.go (about) 1 package mysql 2 3 type Options struct { 4 Address string `json:"address"` 5 DBName string `json:"dbname"` 6 Username string `json:"username"` 7 Password string `json:"password"` 8 Port int `json:"port"` 9 10 // customized 11 customized bool 12 13 // MaxOpenConns sets the maximum number of open connections to the database 14 MaxOpenConns int `json:"max_open_conns"` 15 // MaxIdleConns sets the maximum number of connections in the idle connection pool. 16 MaxIdleConns int `json:"max_idle_conns"` 17 } 18 19 type Option func(o *Options) 20 21 // WithCustomized will use your own configurations. 22 // To be reminder that you should make sure the values of Address, DB, Auth, Port have been assigned correctly. 23 func WithCustomized() Option { 24 return func(o *Options) { 25 o.customized = true 26 } 27 } 28 29 func WithAddress(s string) Option { 30 return func(o *Options) { 31 o.Address = s 32 } 33 } 34 35 func WithDB(name string) Option { 36 return func(o *Options) { 37 o.DBName = name 38 } 39 } 40 41 func WithAuth(username, password string) Option { 42 return func(o *Options) { 43 o.Username = username 44 o.Password = password 45 } 46 } 47 48 func WithPort(port int) Option { 49 return func(o *Options) { 50 o.Port = port 51 } 52 } 53 54 func WithMaxOpenConns(i int) Option { 55 return func(o *Options) { 56 o.MaxOpenConns = i 57 } 58 } 59 60 func WithMaxIdleConns(i int) Option { 61 return func(o *Options) { 62 o.MaxIdleConns = i 63 } 64 }