We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support more flag than -c, and maybe overriding config file? : ) 添加配置文件里的选项到命令行参数中,比如可以运行speedtest -p 80指定网页端口号为80 默认优先级高于配置文件(?)
-c
speedtest -p 80
Maybe using pflag:
package main
import ( _ "time/tzdata" "github.com/spf13/pflag" "github.com/spf13/viper" "github.com/librespeed/speedtest/config" "github.com/librespeed/speedtest/database" "github.com/librespeed/speedtest/results" "github.com/librespeed/speedtest/web" _ "github.com/breml/rootcerts" log "github.com/sirupsen/logrus" )
var ( optConfig = pflag.StringP("configfilepath", "c", "", "config file to be used, defaults to settings.toml in the same directory") )
func init() { pflag.StringP("listen_port", "p", "", "Listening Port") pflag.StringP("proxyprotocol_port", "", "", "") pflag.StringP("download_chunks", "d", "", "") pflag.StringP("distance_unit", "", "", "") pflag.StringP("enable_cors", "e", "", "") pflag.StringP("statistics_password", "s", "", "") pflag.StringP("redact_ip_addresses", "r", "", "") pflag.StringP("database_type", "", "", "") pflag.StringP("database_hostname", "", "", "") pflag.StringP("database_name", "", "", "") pflag.StringP("database_username", "", "", "") viper.BindPFlags(pflag.CommandLine) }
func main() { pflag.Parse() conf := config.Load(*optConfig) viper.Unmarshal(&conf) web.SetServerLocation(&conf) results.Initialize(&conf) database.SetDBInfo(&conf) log.Fatal(web.ListenAndServe(&conf)) }
The text was updated successfully, but these errors were encountered:
PR welcome :)
Sorry, something went wrong.
No branches or pull requests
Description
Support more flag than
-c
, and maybe overriding config file? : )添加配置文件里的选项到命令行参数中,比如可以运行
speedtest -p 80
指定网页端口号为80默认优先级高于配置文件(?)
Why it should be implemented
e.g
Maybe using pflag:
main.go
package main
import (
_ "time/tzdata"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/librespeed/speedtest/config"
"github.com/librespeed/speedtest/database"
"github.com/librespeed/speedtest/results"
"github.com/librespeed/speedtest/web"
_ "github.com/breml/rootcerts"
log "github.com/sirupsen/logrus"
)
var (
optConfig = pflag.StringP("configfilepath", "c", "", "config file to be used, defaults to settings.toml in the same directory")
)
func init() {
pflag.StringP("listen_port", "p", "", "Listening Port")
pflag.StringP("proxyprotocol_port", "", "", "")
pflag.StringP("download_chunks", "d", "", "")
pflag.StringP("distance_unit", "", "", "")
pflag.StringP("enable_cors", "e", "", "")
pflag.StringP("statistics_password", "s", "", "")
pflag.StringP("redact_ip_addresses", "r", "", "")
pflag.StringP("database_type", "", "", "")
pflag.StringP("database_hostname", "", "", "")
pflag.StringP("database_name", "", "", "")
pflag.StringP("database_username", "", "", "")
viper.BindPFlags(pflag.CommandLine)
}
func main() {
pflag.Parse()
conf := config.Load(*optConfig)
viper.Unmarshal(&conf)
web.SetServerLocation(&conf)
results.Initialize(&conf)
database.SetDBInfo(&conf)
log.Fatal(web.ListenAndServe(&conf))
}
The text was updated successfully, but these errors were encountered: