mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 01:38:30 +02:00
refactor: rename module route/types to route
This commit is contained in:
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/yusing/go-proxy/internal/net/gphttp/accesslog"
|
||||
loadbalance "github.com/yusing/go-proxy/internal/net/gphttp/loadbalancer/types"
|
||||
"github.com/yusing/go-proxy/internal/route/rules"
|
||||
"github.com/yusing/go-proxy/internal/route/types"
|
||||
route "github.com/yusing/go-proxy/internal/route/types"
|
||||
"github.com/yusing/go-proxy/internal/utils"
|
||||
)
|
||||
|
||||
@@ -30,12 +30,12 @@ type (
|
||||
_ utils.NoCopy
|
||||
|
||||
Alias string `json:"alias"`
|
||||
Scheme types.Scheme `json:"scheme,omitempty"`
|
||||
Scheme route.Scheme `json:"scheme,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Port types.Port `json:"port,omitempty"`
|
||||
Port route.Port `json:"port,omitempty"`
|
||||
Root string `json:"root,omitempty"`
|
||||
|
||||
types.HTTPConfig
|
||||
route.HTTPConfig
|
||||
PathPatterns []string `json:"path_patterns,omitempty"`
|
||||
Rules rules.Rules `json:"rules,omitempty" validate:"omitempty,unique=Name"`
|
||||
HealthCheck *health.HealthCheckConfig `json:"healthcheck,omitempty"`
|
||||
@@ -57,7 +57,7 @@ type (
|
||||
ProxyURL *net.URL `json:"purl,omitempty"`
|
||||
Idlewatcher *idlewatcher.Config `json:"idlewatcher,omitempty"`
|
||||
|
||||
impl types.Route
|
||||
impl route.Route
|
||||
isValidated bool
|
||||
}
|
||||
Routes map[string]*Route
|
||||
@@ -80,7 +80,7 @@ func (r *Route) Validate() (err gperr.Error) {
|
||||
case "localhost", "127.0.0.1":
|
||||
switch r.Port.Proxy {
|
||||
case common.ProxyHTTPPort, common.ProxyHTTPSPort, common.APIHTTPPort:
|
||||
if r.Scheme.IsReverseProxy() || r.Scheme == types.SchemeTCP {
|
||||
if r.Scheme.IsReverseProxy() || r.Scheme == route.SchemeTCP {
|
||||
return gperr.Errorf("localhost:%d is reserved for godoxy", r.Port.Proxy)
|
||||
}
|
||||
}
|
||||
@@ -89,17 +89,17 @@ func (r *Route) Validate() (err gperr.Error) {
|
||||
errs := gperr.NewBuilder("entry validation failed")
|
||||
|
||||
switch r.Scheme {
|
||||
case types.SchemeFileServer:
|
||||
case route.SchemeFileServer:
|
||||
r.impl, err = NewFileServer(r)
|
||||
if err != nil {
|
||||
errs.Add(err)
|
||||
}
|
||||
case types.SchemeHTTP, types.SchemeHTTPS:
|
||||
case route.SchemeHTTP, route.SchemeHTTPS:
|
||||
if r.Port.Listening != 0 {
|
||||
errs.Addf("unexpected listening port for %s scheme", r.Scheme)
|
||||
}
|
||||
fallthrough
|
||||
case types.SchemeTCP, types.SchemeUDP:
|
||||
case route.SchemeTCP, route.SchemeUDP:
|
||||
r.LisURL = gperr.Collect(errs, net.ParseURL, fmt.Sprintf("%s://:%d", r.Scheme, r.Port.Listening))
|
||||
fallthrough
|
||||
default:
|
||||
@@ -119,11 +119,11 @@ func (r *Route) Validate() (err gperr.Error) {
|
||||
}
|
||||
|
||||
switch r.Scheme {
|
||||
case types.SchemeFileServer:
|
||||
case route.SchemeFileServer:
|
||||
r.impl, err = NewFileServer(r)
|
||||
case types.SchemeHTTP, types.SchemeHTTPS:
|
||||
case route.SchemeHTTP, route.SchemeHTTPS:
|
||||
r.impl, err = NewReverseProxyRoute(r)
|
||||
case types.SchemeTCP, types.SchemeUDP:
|
||||
case route.SchemeTCP, route.SchemeUDP:
|
||||
r.impl, err = NewStreamRoute(r)
|
||||
default:
|
||||
panic(fmt.Errorf("unexpected scheme %s for alias %s", r.Scheme, r.Alias))
|
||||
@@ -164,12 +164,12 @@ func (r *Route) TargetURL() *net.URL {
|
||||
return r.ProxyURL
|
||||
}
|
||||
|
||||
func (r *Route) Type() types.RouteType {
|
||||
func (r *Route) Type() route.RouteType {
|
||||
switch r.Scheme {
|
||||
case types.SchemeHTTP, types.SchemeHTTPS, types.SchemeFileServer:
|
||||
return types.RouteTypeHTTP
|
||||
case types.SchemeTCP, types.SchemeUDP:
|
||||
return types.RouteTypeStream
|
||||
case route.SchemeHTTP, route.SchemeHTTPS, route.SchemeFileServer:
|
||||
return route.RouteTypeHTTP
|
||||
case route.SchemeTCP, route.SchemeUDP:
|
||||
return route.RouteTypeStream
|
||||
}
|
||||
panic(fmt.Errorf("unexpected scheme %s for alias %s", r.Scheme, r.Alias))
|
||||
}
|
||||
@@ -290,7 +290,7 @@ func (r *Route) Finalize() {
|
||||
scheme, port, ok := getSchemePortByImageName(cont.Image.Name)
|
||||
if ok {
|
||||
if r.Scheme == "" {
|
||||
r.Scheme = types.Scheme(scheme)
|
||||
r.Scheme = route.Scheme(scheme)
|
||||
}
|
||||
if pp == 0 {
|
||||
pp = port
|
||||
@@ -300,7 +300,7 @@ func (r *Route) Finalize() {
|
||||
|
||||
if scheme, port, ok := getSchemePortByAlias(r.Alias); ok {
|
||||
if r.Scheme == "" {
|
||||
r.Scheme = types.Scheme(scheme)
|
||||
r.Scheme = route.Scheme(scheme)
|
||||
}
|
||||
if pp == 0 {
|
||||
pp = port
|
||||
|
||||
Reference in New Issue
Block a user