Skip to content

Commit

Permalink
feat(bypass-init): Adding compile time init() function bypass mechanism
Browse files Browse the repository at this point in the history
 This feature allows a user to bypass the default command line flags that livego assumes.

 This is useful for projects that are vendoring the code directly, and do not want to assume the same command line flags as the main project.

Signed-off-by: Kris Nóva <[email protected]>
  • Loading branch information
krisnova committed Sep 26, 2021
1 parent a654392 commit 59394b0
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions configure/liveconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ type ServerCfg struct {
// default config
var defaultConf = ServerCfg{
ConfigFile: "livego.yaml",
FLVArchive: false,
RTMPNoAuth: false,
FLVArchive: false,
RTMPNoAuth: false,
RTMPAddr: ":1935",
HTTPFLVAddr: ":7001",
HLSAddr: ":7002",
Expand All @@ -82,7 +82,15 @@ var defaultConf = ServerCfg{
}},
}

var Config = viper.New()
var (
Config = viper.New()

// BypassInit can be used to bypass the init() function by setting this
// value to True at compile time.
//
// go build -ldflags "-X 'github.com/gwuhaolin/livego/configure.BypassInit=true'" -o livego main.go
BypassInit string = ""
)

func initLog() {
if l, err := log.ParseLevel(Config.GetString("level")); err == nil {
Expand All @@ -92,6 +100,12 @@ func initLog() {
}

func init() {
if BypassInit == "" {
initDefault()
}
}

func initDefault() {
defer Init()

// Default config
Expand Down

0 comments on commit 59394b0

Please sign in to comment.