github.com/jtzjtz/kit@v1.0.2/conn/mysql_pool/options.go (about)

     1  package mysql_pool
     2  
     3  import (
     4  	"errors"
     5  )
     6  
     7  var (
     8  	errInvalid = errors.New("invalid config")
     9  )
    10  
    11  //Options conn options
    12  type Options struct {
    13  	// init connection
    14  	InitCap int
    15  	// max connections
    16  	MaxCap int
    17  
    18  	IsDebug bool
    19  
    20  	User     string
    21  	Pass     string
    22  	Host     string
    23  	Port     string
    24  	DataBase string
    25  }
    26  
    27  // NewOptions returns a new newOptions instance with sane defaults.
    28  func NewOptions() *Options {
    29  	o := &Options{}
    30  	o.InitCap = 5
    31  	o.MaxCap = 100
    32  	o.IsDebug = true
    33  	return o
    34  }
    35  
    36  // validate checks a Config instance.
    37  func (o *Options) validate() error {
    38  	if o.InitCap <= 0 ||
    39  		o.MaxCap <= 0 ||
    40  		o.InitCap > o.MaxCap ||
    41  		o.User == "" ||
    42  		o.Pass == "" ||
    43  		o.Host == "" ||
    44  		o.Port == "" ||
    45  		o.DataBase == "" {
    46  		return errInvalid
    47  	}
    48  	return nil
    49  }