From 88b1f1d1d14a8fe9e3dde2f363a89d821fc0e641 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期四, 26 九月 2024 20:19:49 +0800
Subject: [PATCH] code format

---
 config/config.go |   65 +++++++++++---------------------
 1 files changed, 22 insertions(+), 43 deletions(-)

diff --git a/config/config.go b/config/config.go
index b528065..b71dc57 100644
--- a/config/config.go
+++ b/config/config.go
@@ -1,54 +1,26 @@
 package config
 
 import (
+	"fmt"
+
 	"basic.com/valib/logger.git"
 	"github.com/fsnotify/fsnotify"
 	"github.com/spf13/viper"
-	"log"
 )
 
-type server struct {
-	AnalyServerId  string `mapstructure:"analyServerId"`
-	NetworkAdapter string `mapstructure:"networkAdapter"`
-}
-
-var Server = &server{}
-
-type esinfo struct {
-	EsIndex esindexlist `mapstructure:"index"`
-}
-
-type esindexlist struct {
-	AiOcean index `mapstructure:"aiOcean"`
-}
-
-type index struct {
-	IndexName string `mapstructure:"index"`
-	IndexType string `mapstructure:"type"`
-}
-
-type dbpersoncompare struct {
+type mainConfig struct {
+	ServePort   int    `mapstructure:"servePort"`
+	WorkerNum   int    `mapstructure:"workerNum"`
 	MysqlAddr   string `mapstructure:"mysqlAddr"`
 	Username    string `mapstructure:"username"`
 	Password    string `mapstructure:"password"`
 	Database    string `mapstructure:"database"`
 	PersonTable string `mapstructure:"personTable"`
-	ServePort   int    `mapstructure:"servePort"`
 }
 
-type espersoncompare struct {
-	ServePort int    `mapstructure:"servePort"`
-	ESIP      string `mapstructure:"esip"`
-	ESPort    string `mapstructure:"esPort"`
-}
+var MainConf = &mainConfig{}
 
-var DbPersonCompInfo = &dbpersoncompare{}
-
-var EsCompServerInfo = &espersoncompare{}
-
-var EsInfo = &esinfo{}
-
-type LogConfig struct {
+type logConfig struct {
 	Path       string `mapstructure:"path"`       //鏃ュ織瀛樺偍璺緞
 	Level      int    `mapstructure:"level"`      //鏃ュ織绛夌骇
 	MaxSize    int    `mapstructure:"maxSize"`    //鏃ュ織鏂囦欢澶у皬涓婇檺
@@ -56,31 +28,38 @@
 	MaxAge     int    `mapstructure:"maxAge"`     //淇濈暀鍘嬬缉鍖呭ぉ鏁�
 }
 
-var LogConf = &LogConfig{}
+var LogConf = &logConfig{}
 
-func Init(env string) {
+func Init() error {
 	var err error
 	v := viper.New()
 	v.SetConfigType("yaml")
-	v.SetConfigName(env)
+	v.SetConfigName("compare")
 	v.AddConfigPath("./")
 	v.AddConfigPath("./config/")
+	v.AddConfigPath("../config/")
 	err = v.ReadInConfig()
 	if err != nil {
-		log.Fatal("error on parsing configuration file")
+		fmt.Printf("error on parsing configuration file, %s, config file compare.yaml\n", err.Error())
+		return err
 	}
+
 	read2Conf(v)
 	v.WatchConfig()
 	v.OnConfigChange(func(in fsnotify.Event) {
 		read2Conf(v)
 	})
+
+	return nil
 }
 
 func read2Conf(v *viper.Viper) {
-	v.UnmarshalKey("es", EsInfo)
-	v.UnmarshalKey("server", Server)
-	v.UnmarshalKey("dbpersoncompare", DbPersonCompInfo)
-	v.UnmarshalKey("espersoncompare", EsCompServerInfo)
+	v.UnmarshalKey("main", MainConf)
 	v.UnmarshalKey("log", LogConf)
+
 	logger.SetLevel(LogConf.Level)
+
+	if MainConf.WorkerNum == 0 {
+		MainConf.WorkerNum = 30
+	}
 }

--
Gitblit v1.8.0