diff --git a/api/router.go b/api/router.go index 60a5a0c..b1c69e1 100644 --- a/api/router.go +++ b/api/router.go @@ -5,10 +5,9 @@ import ( "net/http" "os" - "github.com/zu1k/proxypool/config" - "github.com/gin-gonic/gin" _ "github.com/heroku/x/hmetrics/onload" + "github.com/zu1k/proxypool/config" "github.com/zu1k/proxypool/internal/cache" "github.com/zu1k/proxypool/pkg/provider" ) diff --git a/app.json b/app.json index 486904c..b184324 100644 --- a/app.json +++ b/app.json @@ -7,14 +7,19 @@ "logo": "https://raw.githubusercontent.com/zu1k/proxypool/master/assets/proxy.jpg", "keywords": ["golang", "ss", "ssr", "vmess", "shadowsocks", "shadowsocksr"], "env": { + "CONFIG_FILE": { + "description": "Path to config file, could be a url." + }, "DOMAIN": { "description": "Domain to use." }, "CF_API_EMAIL": { - "description": "Cloudflare Email." + "description": "Cloudflare Email.", + "required": false }, "CF_API_KEY": { - "description": "Cloudflare API key." + "description": "Cloudflare API key.", + "required": false } } } \ No newline at end of file diff --git a/config/config.go b/config/config.go index 24646cd..f81016b 100644 --- a/config/config.go +++ b/config/config.go @@ -9,6 +9,11 @@ import ( "github.com/zu1k/proxypool/pkg/tool" ) +var ( + NeedFetch = true + Url = "https://raw.githubusercontent.com/zu1k/proxypool/master/source.yaml" +) + type Source struct { Type string `json:"type" yaml:"type"` Options tool.Options `json:"options" yaml:"options"` diff --git a/internal/app/task.go b/internal/app/task.go index eca2b13..ffbc4a6 100644 --- a/internal/app/task.go +++ b/internal/app/task.go @@ -14,10 +14,8 @@ import ( "gopkg.in/yaml.v2" ) -var NeedFetchNewConfigFile = false - func CrawlGo() { - if NeedFetchNewConfigFile { + if config.NeedFetch { FetchNewConfigFileThenInit() } wg := &sync.WaitGroup{} @@ -57,7 +55,7 @@ func CrawlGo() { func FetchNewConfigFileThenInit() { fmt.Println("fetch new config file...") - resp, err := tool.GetHttpClient().Get("https://raw.githubusercontent.com/zu1k/proxypool/master/source.yaml") + resp, err := tool.GetHttpClient().Get(config.Url) if err != nil { return } diff --git a/main.go b/main.go index 6d589c0..f51b698 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,10 @@ import ( "fmt" "net/http" _ "net/http/pprof" + "os" + "strings" + + "github.com/zu1k/proxypool/config" "github.com/zu1k/proxypool/internal/cron" @@ -28,15 +32,17 @@ func main() { go pprof() } - if configFilePath == "" { - app.NeedFetchNewConfigFile = true - app.FetchNewConfigFileThenInit() - } else { - err := app.InitConfigAndGetters(configFilePath) - if err != nil { - fmt.Println(err) - } + envConfigFilePath := os.Getenv("CONFIG_FILE") + if envConfigFilePath == "" { + envConfigFilePath = "https://raw.githubusercontent.com/zu1k/proxypool/master/source.yaml" } + + if configFilePath != "" { + initConfigFile(configFilePath) + } else { + initConfigFile(envConfigFilePath) + } + proxy.InitGeoIpDB() go cron.Cron() @@ -45,6 +51,19 @@ func main() { api.Run() } +func initConfigFile(path string) { + if strings.HasPrefix(path, "http") { + config.Url = path + config.NeedFetch = true + app.FetchNewConfigFileThenInit() + } else { + err := app.InitConfigAndGetters(configFilePath) + if err != nil { + panic(err) + } + } +} + func pprof() { ip := "127.0.0.1:6060" if err := http.ListenAndServe(ip, nil); err != nil {