librespeed / librespeed/speedtest-go

Command line flag support 添加更多命令行选项支持

Open
#34 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
875
Forks
183
PR merge metrics
No merged PRs in 30d

Description

Description

Support more flag than -c, and maybe overriding config file? : )
添加配置文件里的选项到命令行参数中,比如可以运行speedtest -p 80指定网页端口号为80
默认优先级高于配置文件(?)

Why it should be implemented

  1. Benefit who don‘t want to edit config file. 懒得写配置文件Orz
  2. More easy way to set up some background service. 方便搭建后台

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))
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with main.go, especially the existing pflag setup, config.Load, viper.Unmarshal, and the calls that pass configuration to web, results, and database. Compare the settings loaded from the config file with the options listed in the issue. Done means the supported configuration options can be supplied on the command line and their precedence over the config file is defined and works consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.