go configor配置檔案支援熱載入

2021-10-01 12:33:00 字數 918 閱讀 3658

在編寫go程式的時候我們載入配置有多中方式,比較常用的還是配置檔案。我們需要配置檔案能夠熱載入(當配置發生變化後)不用重新啟動程式,就能夠使配置生效。

我們採用的是開源的配置檔案方式 

好,下面上貨。

//無reload模式

configfilename)

fmt.printf("config: %#v\r\n", config)

}//配置類

var config = struct

contacts struct

}{}在main函式中讀取

package main

import (

"fmt"

"selfcommon/src/common/config"

"time"

)func main()

配置檔案

db: name: test

user: root

password: 123456

port: 3306

contacts:

- name: i test

email: [email protected]

- name: i test2

email: [email protected]

在執行期間我們修改配置檔案

test

& [ ]} changed

testa

drbd配置檔案 drbd配置檔案

drbd配置檔案 vim usr local drbd etc drbd.d global common.conf global usage count yes 是否參加drbd使用者統計 common protocol c 使用drbd的第三種同步協議 disk 使用dpod功能保證在數 on i...

Spring配置檔案載入外部配置檔案

有時,應用程式可能需要從不同的位置 例如 檔案系統 classpath或者url 讀取外部資源 例如 文字檔案 xml檔案 屬性檔案或或者影象檔案 通常,為了從不同位置載入資源,需要和不同的api打交道。spring的資源載入器提供了乙個統一的getresource 方法,使用這個方法可以通過資源路...

mysql簡單配置檔案 MySQL配置檔案

mysql配置檔案 在windows下是my.ini,而在linux下是my.cnf。基本引數 port 3306 埠號 server id 1 basedir c program files mysql mysql server 5.5 基準路徑,其他路徑都相對於這個路徑 datadir c pr...