feat(cmd): allow custom mmdb download url

allow custom mmdb download url

Signed-off-by: mritd <mritd@linux.com>
This commit is contained in:
mritd 2022-02-06 16:54:40 +08:00
parent 8e6a9be5f7
commit 01dc2beb71
No known key found for this signature in database
GPG Key ID: 150E1851F767CDDD
2 changed files with 7 additions and 7 deletions

View File

@ -77,7 +77,7 @@ var rootCmd = &cobra.Command{
var clientCmd = &cobra.Command{
Use: "client",
Short: "Run as client mode",
Example: "./hysteria client --config /etc/client.json",
Example: "./hysteria client --config /etc/hysteria/client.json",
Run: func(cmd *cobra.Command, args []string) {
cbs, err := ioutil.ReadFile(viper.GetString("config"))
if err != nil {
@ -101,7 +101,7 @@ var clientCmd = &cobra.Command{
var serverCmd = &cobra.Command{
Use: "server",
Short: "Run as server mode",
Example: "./hysteria server --config /etc/server.json",
Example: "./hysteria server --config /etc/hysteria/server.json",
Run: func(cmd *cobra.Command, args []string) {
cbs, err := ioutil.ReadFile(viper.GetString("config"))
if err != nil {
@ -125,6 +125,7 @@ var serverCmd = &cobra.Command{
func init() {
// add global flags
rootCmd.PersistentFlags().StringP("config", "c", "./config.json", "config file")
rootCmd.PersistentFlags().String("mmdb-url", "https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-Country.mmdb", "mmdb download url")
rootCmd.PersistentFlags().String("log-level", "debug", "log level")
rootCmd.PersistentFlags().String("log-timestamp", time.RFC3339, "log timestamp format")
rootCmd.PersistentFlags().String("log-format", "txt", "log output format")
@ -135,6 +136,7 @@ func init() {
// bind flag
_ = viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
_ = viper.BindPFlag("mmdb-url", rootCmd.PersistentFlags().Lookup("mmdb-url"))
_ = viper.BindPFlag("log-level", rootCmd.PersistentFlags().Lookup("log-level"))
_ = viper.BindPFlag("log-timestamp", rootCmd.PersistentFlags().Lookup("log-timestamp"))
_ = viper.BindPFlag("log-format", rootCmd.PersistentFlags().Lookup("log-format"))
@ -142,6 +144,7 @@ func init() {
// bind env
_ = viper.BindEnv("config", "HYSTERIA_CONFIG")
_ = viper.BindEnv("mmdb-url", "HYSTERIA_MMDB_URL")
_ = viper.BindEnv("log-level", "HYSTERIA_LOG_LEVEL", "LOGGING_LEVEL")
_ = viper.BindEnv("log-timestamp", "HYSTERIA_LOG_TIMESTAMP", "LOGGING_TIMESTAMP_FORMAT")
_ = viper.BindEnv("log-format", "HYSTERIA_LOG_FORMAT", "LOGGING_FORMATTER")

View File

@ -3,17 +3,14 @@ package main
import (
"github.com/oschwald/geoip2-golang"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"io"
"net/http"
"os"
)
const (
mmdbURL = "https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-Country.mmdb"
)
func downloadMMDB(filename string) error {
resp, err := http.Get(mmdbURL)
resp, err := http.Get(viper.GetString("mmdb-url"))
if err != nil {
return err
}