1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package db
- import (
- "log"
- "sfbase/core"
- "sfbase/elastic"
- "sfbase/global"
- )
- type EsConfig struct {
- Project struct {
- Addr string `mapstructure:"addr"`
- Index string `mapstructure:"index"`
- Itype string `mapstructure:"itype"`
- Pool int `mapstructure:"pool"`
- } `mapstructure:"project"`
- }
- var (
- Es *elastic.Elastic
- EsConfigs EsConfig
- )
- func InitEs() {
- //数据库属性定义在业务中,解析配置文件加载到结构体基本方法viper在spirit中
- _, err := core.Viper(global.EnvPathPrefix+"/"+global.Env+"/es.toml", &EsConfigs)
- if err != nil {
- log.Println("EsConfig:", err)
- return
- }
- Es = &elastic.Elastic{
- S_esurl: EsConfigs.Project.Addr,
- I_size: EsConfigs.Project.Pool,
- }
- Es.InitElasticSize()
- }
- func GetEs() *elastic.Elastic {
- if Es == nil {
- log.Printf("ERROR:Es 实例为空!请重新实例化.")
- }
- return Es
- }
|