github.com/zly-app/zapp@v1.3.3/component/gpool/gpools.go (about)

     1  /*
     2  -------------------------------------------------
     3     Author :       zlyuancn
     4     date:         2021/3/19
     5     Description :
     6  -------------------------------------------------
     7  */
     8  
     9  package gpool
    10  
    11  import (
    12  	"go.uber.org/zap"
    13  
    14  	"github.com/zly-app/zapp/component/conn"
    15  	"github.com/zly-app/zapp/config"
    16  	"github.com/zly-app/zapp/consts"
    17  	"github.com/zly-app/zapp/core"
    18  	"github.com/zly-app/zapp/logger"
    19  	"github.com/zly-app/zapp/pkg/utils"
    20  )
    21  
    22  type gpools struct {
    23  	conn *conn.Conn
    24  }
    25  
    26  func NewGPools() core.IGPools {
    27  	return &gpools{
    28  		conn: conn.NewConn(),
    29  	}
    30  }
    31  
    32  func (g *gpools) GetGPool(name ...string) core.IGPool {
    33  	return g.conn.GetInstance(g.makeGPoolGroup, name...).(core.IGPool)
    34  }
    35  
    36  func (g *gpools) makeGPoolGroup(name string) (conn.IInstance, error) {
    37  	componentName := utils.Ternary.Or(name, consts.DefaultComponentName).(string)
    38  
    39  	conf := new(GPoolConfig)
    40  	err := config.Conf.ParseComponentConfig(DefaultComponentType, componentName, conf, true)
    41  	if err != nil {
    42  		logger.Log.Warn("gpool组件配置解析失败, 将使用默认配置", zap.String("name", componentName), zap.Error(err))
    43  	}
    44  	conf.check()
    45  
    46  	return NewGPool(conf), nil
    47  }
    48  
    49  func (g *gpools) Close() {
    50  	g.conn.CloseAll()
    51  }