8000 Merge pull request #91 from GNURub/fix_default_config · invisiblecoder99/livego@bd7debe · GitHub
[go: up one dir, main page]

Skip to content

Commit bd7debe

Browse files
authored
Merge pull request gwuhaolin#91 from GNURub/fix_default_config
Fix default config
2 parents 2b9df25 + 256f2e0 commit bd7debe

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

configure/liveconfig.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var defaultConf = ServerCfg{
6464
WriteTimeout: 10,
6565
ReadTimeout: 10,
6666
GopNum: 1,
67-
Server: []Application{{
67+
Server: Applications{{
6868
Appname: "live",
6969
Live: true,
7070
Hls: true,
@@ -81,13 +81,15 @@ func initLog() {
8181
}
8282
}
8383

84-
func LoadConfig() {
84+
func init() {
8585
defer Init()
8686

8787
// Default config
8888
b, _ := json.Marshal(defaultConf)
8989
defaultConfig := bytes.NewReader(b)
90-
Config.MergeConfig(defaultConfig)
90+
viper.SetConfigType("json")
91+
viper.ReadConfig(defaultConfig)
92+
Config.MergeConfigMap(viper.AllSettings())
9193

9294
// Flags
9395
pflag.String("rtmp_addr", ":1935", "RTMP server listen address")
@@ -110,6 +112,8 @@ func LoadConfig() {
110112
if err != nil {
111113
log.Warning(err)
112114
log.Info("Using default config")
115+
} else {
116+
Config.MergeInConfig()
113117
}
114118

115119
// Environment
@@ -121,6 +125,7 @@ func LoadConfig() {
121125
// Log
122126
initLog()
123127

128+
// Print final config
124129
c := ServerCfg{}
125130
Config.Unmarshal(&c)
126131
log.Debugf("Current configurations: \n%# v", pretty.Formatter(c))

main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ func main() {
125125
}
126126
}()
127127

128-
configure.LoadConfig()
129-
130128
log.Infof(`
131129
_ _ ____
132130
| | (_)_ _____ / ___| ___

0 commit comments

Comments
 (0)
0