mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-31 22:53:24 +02:00
Initial abstract implementation of middlewares
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
U "github.com/yusing/go-proxy/utils"
|
||||
)
|
||||
|
||||
@@ -12,6 +14,10 @@ var (
|
||||
ProxyHTTPAddr = GetEnv("GOPROXY_HTTP_ADDR", ":80")
|
||||
ProxyHTTPSAddr = GetEnv("GOPROXY_HTTPS_ADDR", ":443")
|
||||
APIHTTPAddr = GetEnv("GOPROXY_API_ADDR", "127.0.0.1:8888")
|
||||
|
||||
ProxyHTTPPort = getPort(ProxyHTTPAddr)
|
||||
ProxyHTTPSPort = getPort(ProxyHTTPSAddr)
|
||||
ProxyAPIPort = getPort(APIHTTPAddr)
|
||||
)
|
||||
|
||||
func GetEnvBool(key string) bool {
|
||||
@@ -25,3 +31,11 @@ func GetEnv(key string, defaultValue string) string {
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func getPort(addr string) string {
|
||||
_, port, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Invalid address: %s", addr)
|
||||
}
|
||||
return port
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user