初始化项目
This commit is contained in:
54
trunk/goutil/yamlUtil/config.yaml
Normal file
54
trunk/goutil/yamlUtil/config.yaml
Normal file
@@ -0,0 +1,54 @@
|
||||
# 配置根节点
|
||||
root:
|
||||
# 是否是调试模式
|
||||
debug: true
|
||||
|
||||
# Web服务监听地址和端口
|
||||
web_server_address: "192.168.50.85:10051"
|
||||
|
||||
# Elasticsearch 地址
|
||||
es_urls: "http://10.252.0.70:18099"
|
||||
|
||||
# 数据库配置
|
||||
db_config:
|
||||
admin_db:
|
||||
# 最大处于开启状态的连接数
|
||||
max_open_conns: 0
|
||||
|
||||
# 最大处于空闲状态的连接数
|
||||
max_idle_conns: 0
|
||||
|
||||
# 数据库连接字符串
|
||||
connection_string: "root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true"
|
||||
|
||||
user_db:
|
||||
# 最大处于开启状态的连接数
|
||||
max_open_conns: 0
|
||||
|
||||
# 最大处于空闲状态的连接数
|
||||
max_idle_conns: 0
|
||||
|
||||
# 数据库连接字符串
|
||||
connection_string: "root:Qq5201530300@tcp(192.168.50.110:3306)/user?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true"
|
||||
|
||||
redis_config:
|
||||
# 数据库连接字符串
|
||||
connection_string: "192.168.50.110:6379"
|
||||
|
||||
# 密码, 如果要设置用户Id,则密码设置为:"UserId:Password"
|
||||
password: ""
|
||||
|
||||
# 数据库序号
|
||||
database: 5
|
||||
|
||||
# 最大活跃连接数
|
||||
max_active: 500
|
||||
|
||||
# 最大空闲的连接数
|
||||
max_idle: 200
|
||||
|
||||
# 连接空闲超时时间,单位:秒
|
||||
idle_timeout: 300
|
||||
|
||||
# 连接超时时间, 单位:秒
|
||||
dial_connect_timeout: 10
|
||||
18
trunk/goutil/yamlUtil/load.go
Normal file
18
trunk/goutil/yamlUtil/load.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package yamlUtil
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
)
|
||||
|
||||
// LoadFromFile 加载配置文件(这里不反序列化)
|
||||
func LoadFromFile(filePath string) ([]byte, error) {
|
||||
// 读取 YAML 文件
|
||||
yamlFile, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading config.yaml file: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return yamlFile, nil
|
||||
}
|
||||
14
trunk/goutil/yamlUtil/load_test.go
Normal file
14
trunk/goutil/yamlUtil/load_test.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package yamlUtil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"goutil/jsonUtil"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoadYaml(t *testing.T) {
|
||||
config, _ := LoadFromFile("config.yaml")
|
||||
configStr, _ := jsonUtil.DeepClone(config)
|
||||
|
||||
fmt.Print(configStr)
|
||||
}
|
||||
Reference in New Issue
Block a user