mirror of https://github.com/statping/statping
fixed ENV merge with flags.
parent
d3d1f9d2a0
commit
4f268edc10
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
|
||||||
"github.com/statping/statping/utils"
|
"github.com/statping/statping/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,14 +14,14 @@ var (
|
||||||
|
|
||||||
func parseFlags(cmd *cobra.Command) {
|
func parseFlags(cmd *cobra.Command) {
|
||||||
cmd.PersistentFlags().StringVarP(&ipAddress, "ip", "s", "0.0.0.0", "server run on host")
|
cmd.PersistentFlags().StringVarP(&ipAddress, "ip", "s", "0.0.0.0", "server run on host")
|
||||||
viper.BindPFlag("ip", cmd.PersistentFlags().Lookup("ip"))
|
utils.Params.BindPFlag("ip", cmd.PersistentFlags().Lookup("ip"))
|
||||||
|
|
||||||
cmd.PersistentFlags().IntVarP(&port, "port", "p", 8080, "server port")
|
cmd.PersistentFlags().IntVarP(&port, "port", "p", 8080, "server port")
|
||||||
viper.BindPFlag("port", cmd.PersistentFlags().Lookup("port"))
|
utils.Params.BindPFlag("port", cmd.PersistentFlags().Lookup("port"))
|
||||||
|
|
||||||
cmd.PersistentFlags().IntVarP(&verboseMode, "verbose", "v", 2, "verbose logging")
|
cmd.PersistentFlags().IntVarP(&verboseMode, "verbose", "v", 2, "verbose logging")
|
||||||
viper.BindPFlag("verbose", cmd.PersistentFlags().Lookup("verbose"))
|
utils.Params.BindPFlag("VERBOSE", cmd.PersistentFlags().Lookup("verbose"))
|
||||||
|
|
||||||
cmd.PersistentFlags().StringVarP(&configFile, "config", "c", utils.Directory+"/config.yml", "path to config.yml file")
|
cmd.PersistentFlags().StringVarP(&configFile, "config", "c", utils.Directory+"/config.yml", "path to config.yml file")
|
||||||
viper.BindPFlag("config", cmd.PersistentFlags().Lookup("config"))
|
utils.Params.BindPFlag("config", cmd.PersistentFlags().Lookup("config"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ var (
|
||||||
func init() {
|
func init() {
|
||||||
process = make(chan struct{})
|
process = make(chan struct{})
|
||||||
core.New(VERSION)
|
core.New(VERSION)
|
||||||
|
utils.InitEnvs()
|
||||||
|
|
||||||
rootCmd.AddCommand(versionCmd)
|
rootCmd.AddCommand(versionCmd)
|
||||||
rootCmd.AddCommand(assetsCmd)
|
rootCmd.AddCommand(assetsCmd)
|
||||||
rootCmd.AddCommand(exportCmd)
|
rootCmd.AddCommand(exportCmd)
|
||||||
|
@ -37,7 +39,7 @@ func init() {
|
||||||
rootCmd.AddCommand(onceCmd)
|
rootCmd.AddCommand(onceCmd)
|
||||||
rootCmd.AddCommand(envCmd)
|
rootCmd.AddCommand(envCmd)
|
||||||
rootCmd.AddCommand(resetCmd)
|
rootCmd.AddCommand(resetCmd)
|
||||||
utils.InitLogs()
|
|
||||||
parseFlags(rootCmd)
|
parseFlags(rootCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +59,7 @@ func Close() {
|
||||||
|
|
||||||
// main will run the Statping application
|
// main will run the Statping application
|
||||||
func main() {
|
func main() {
|
||||||
|
utils.InitLogs()
|
||||||
go Execute()
|
go Execute()
|
||||||
<-process
|
<-process
|
||||||
Close()
|
Close()
|
||||||
|
|
|
@ -41,7 +41,7 @@ func RunHTTPServer() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
ip := utils.Params.GetString("HOST")
|
ip := utils.Params.GetString("HOST")
|
||||||
host := fmt.Sprintf("%v:%v", ip, utils.Params.GetInt64("PORT"))
|
host := fmt.Sprintf("%v:%v", ip, utils.Params.GetInt("PORT"))
|
||||||
key := utils.FileExists(utils.Directory + "/server.key")
|
key := utils.FileExists(utils.Directory + "/server.key")
|
||||||
cert := utils.FileExists(utils.Directory + "/server.crt")
|
cert := utils.FileExists(utils.Directory + "/server.crt")
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ func RunHTTPServer() error {
|
||||||
|
|
||||||
router = Router()
|
router = Router()
|
||||||
resetCookies()
|
resetCookies()
|
||||||
|
httpError = make(chan error)
|
||||||
|
|
||||||
if usingSSL {
|
if usingSSL {
|
||||||
go startSSLServer(ip)
|
go startSSLServer(ip)
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func startServer(host string) {
|
func startServer(host string) {
|
||||||
httpError = make(chan error)
|
|
||||||
httpServer = &http.Server{
|
httpServer = &http.Server{
|
||||||
Addr: host,
|
Addr: host,
|
||||||
WriteTimeout: timeout,
|
WriteTimeout: timeout,
|
||||||
|
@ -23,7 +22,6 @@ func startServer(host string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func startSSLServer(ip string) {
|
func startSSLServer(ip string) {
|
||||||
httpError = make(chan error)
|
|
||||||
cfg := &tls.Config{
|
cfg := &tls.Config{
|
||||||
MinVersion: tls.VersionTLS12,
|
MinVersion: tls.VersionTLS12,
|
||||||
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
|
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
|
||||||
|
|
|
@ -11,7 +11,10 @@ var (
|
||||||
Params *viper.Viper
|
Params *viper.Viper
|
||||||
)
|
)
|
||||||
|
|
||||||
func initEnvs() {
|
func InitEnvs() {
|
||||||
|
if Params != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
Params = viper.New()
|
Params = viper.New()
|
||||||
Params.AutomaticEnv()
|
Params.AutomaticEnv()
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ func createLog(dir string) error {
|
||||||
|
|
||||||
// InitLogs will create the '/logs' directory and creates a file '/logs/statup.log' for application logging
|
// InitLogs will create the '/logs' directory and creates a file '/logs/statup.log' for application logging
|
||||||
func InitLogs() error {
|
func InitLogs() error {
|
||||||
initEnvs()
|
InitEnvs()
|
||||||
if Params.GetBool("DISABLE_LOGS") {
|
if Params.GetBool("DISABLE_LOGS") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue