add config file path param
This commit is contained in:
@@ -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"
|
||||
)
|
||||
|
||||
9
app.json
9
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"`
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
35
main.go
35
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 {
|
||||
|
||||
Reference in New Issue
Block a user