4
This commit is contained in:
parent
f7ca358b21
commit
c35eceb9db
2 changed files with 218 additions and 104 deletions
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
"github.com/zeevdiukman/go-config"
|
"github.com/zeevdiukman/go-config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -16,6 +17,7 @@ const ENTRYPOINTS_KEY string = "entrypoints"
|
||||||
const TLS_KEY string = "tls.certproviders"
|
const TLS_KEY string = "tls.certproviders"
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Viper *viper.Viper
|
||||||
HTTP *HTTP
|
HTTP *HTTP
|
||||||
TLS *TLS
|
TLS *TLS
|
||||||
EntryPoints EntryPoints
|
EntryPoints EntryPoints
|
||||||
|
|
@ -71,6 +73,7 @@ func New() *Config {
|
||||||
c.Load()
|
c.Load()
|
||||||
|
|
||||||
appConfig := &Config{
|
appConfig := &Config{
|
||||||
|
Viper: c.Viper,
|
||||||
HTTP: &HTTP{
|
HTTP: &HTTP{
|
||||||
Routers: Routers{},
|
Routers: Routers{},
|
||||||
Services: Services{},
|
Services: Services{},
|
||||||
|
|
@ -88,17 +91,28 @@ func New() *Config {
|
||||||
|
|
||||||
return appConfig
|
return appConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r Rules) Get(ruleName string) string {
|
||||||
|
if _, ok := r.Map[ruleName]; !ok {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return r.Map[ruleName].Value
|
||||||
|
}
|
||||||
|
|
||||||
func (r Routers) ForEach(fn func(routerName string, routerConfig *Router)) {
|
func (r Routers) ForEach(fn func(routerName string, routerConfig *Router)) {
|
||||||
for k, v := range r {
|
for k, v := range r {
|
||||||
fn(k, v)
|
fn(k, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ep EntryPoints) ForEach(fn func(entryPointName string, entryPointConfig *EntryPoint)) {
|
func (ep EntryPoints) ForEach(fn func(entryPointName string, entryPointConfig *EntryPoint)) {
|
||||||
forEach(ep, fn)
|
forEach(ep, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Services) ForEach(fn func(serviceName string, serviceConfig *Service)) {
|
func (s Services) ForEach(fn func(serviceName string, serviceConfig *Service)) {
|
||||||
forEach(s, fn)
|
forEach(s, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) InitRouters(vConfig *config.Config) {
|
func (c *Config) InitRouters(vConfig *config.Config) {
|
||||||
c.HTTP.Routers = make(Routers)
|
c.HTTP.Routers = make(Routers)
|
||||||
for k, v := range vConfig.Sub(ROUTERS_KEY).AllSettings() {
|
for k, v := range vConfig.Sub(ROUTERS_KEY).AllSettings() {
|
||||||
|
|
@ -132,22 +146,61 @@ func (c *Config) InitRouters(vConfig *config.Config) {
|
||||||
EntryPoint: entryPoint,
|
EntryPoint: entryPoint,
|
||||||
TLS: &RouterTLS{CertProvider: tls},
|
TLS: &RouterTLS{CertProvider: tls},
|
||||||
}
|
}
|
||||||
r.ForRuleFunc("Domain", func(domain string) {
|
|
||||||
r.Rules.Map["Domain"] = &Rule{
|
|
||||||
Name: "Domain",
|
|
||||||
Value: domain,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
r.ForRuleFunc("Path", func(path string) {
|
|
||||||
r.Rules.Map["Path"] = &Rule{
|
|
||||||
Name: "Path",
|
|
||||||
Value: path,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
r.RuleInit("Domain")
|
||||||
|
r.RuleInit("Path")
|
||||||
|
r.RuleInit("PathPrefix")
|
||||||
|
// r.RuleInit("Path")
|
||||||
|
// r.ForRuleFunc("Domain", func(domain string) {
|
||||||
|
// r.Rules.Map["Domain"] = &Rule{
|
||||||
|
// Name: "Domain",
|
||||||
|
// Value: domain,
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// r.ForRuleFunc("Path", func(path string) {
|
||||||
|
// r.Rules.Map["Path"] = &Rule{
|
||||||
|
// Name: "Path",
|
||||||
|
// Value: path,
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// r.ForRuleFunc("PathPrefix", func(path string) {
|
||||||
|
// r.Rules.Map["PathPrefix"] = &Rule{
|
||||||
|
// Name: "PathPrefix",
|
||||||
|
// Value: path,
|
||||||
|
// }
|
||||||
|
// })
|
||||||
c.HTTP.Routers[k] = r
|
c.HTTP.Routers[k] = r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Router) RuleInit(ruleName string) {
|
||||||
|
r.ForRuleFunc(ruleName, func(ruleValue string) {
|
||||||
|
// _, ok := isOK(r.Rules.Map, ruleName)
|
||||||
|
// if ok {
|
||||||
|
r.Rules.Map[ruleName] = &Rule{
|
||||||
|
Name: ruleName,
|
||||||
|
Value: ruleValue,
|
||||||
|
}
|
||||||
|
// }
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Router) ForRuleFunc(ruleName string, fn func(rValue string)) {
|
||||||
|
rules := r.Rules.Raw
|
||||||
|
rulesSlice := splitStatementByRegex(rules, "\\(`(.*?)`\\)")
|
||||||
|
for idx, rule := range rulesSlice {
|
||||||
|
rule, _ = strings.CutPrefix(rule, ".")
|
||||||
|
if rule == ruleName {
|
||||||
|
valueIdx := idx + 1
|
||||||
|
// if len(rulesSlice) < valueIdx {
|
||||||
|
v := rulesSlice[valueIdx]
|
||||||
|
fn(v)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Config) InitServices(vConfig *config.Config) {
|
func (c *Config) InitServices(vConfig *config.Config) {
|
||||||
c.HTTP.Services = make(map[string]*Service)
|
c.HTTP.Services = make(map[string]*Service)
|
||||||
for k, v := range vConfig.Sub(SERVICES_KEY).AllSettings() {
|
for k, v := range vConfig.Sub(SERVICES_KEY).AllSettings() {
|
||||||
|
|
@ -156,6 +209,7 @@ func (c *Config) InitServices(vConfig *config.Config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) InitEntryPoints(vConfig *config.Config) {
|
func (c *Config) InitEntryPoints(vConfig *config.Config) {
|
||||||
c.EntryPoints = make(EntryPoints)
|
c.EntryPoints = make(EntryPoints)
|
||||||
for k, v := range vConfig.Sub(ENTRYPOINTS_KEY).AllSettings() {
|
for k, v := range vConfig.Sub(ENTRYPOINTS_KEY).AllSettings() {
|
||||||
|
|
@ -192,23 +246,13 @@ func (c *Config) InitTLS(vConfig *config.Config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func forEach[K comparable, V comparable](mp map[K]V, fn func(key K, value V)) {
|
func forEach[K comparable, V comparable](mp map[K]V, fn func(key K, value V)) {
|
||||||
for k, v := range mp {
|
for k, v := range mp {
|
||||||
fn(k, v)
|
fn(k, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) ForRuleFunc(ruleName string, fn func(string)) {
|
|
||||||
rules := r.Rules.Raw
|
|
||||||
rulesSlice := splitStatementByRegex(rules, "\\(`(.*?)`\\)")
|
|
||||||
for idx, rule := range rulesSlice {
|
|
||||||
rule, _ = strings.CutPrefix(rule, ".")
|
|
||||||
if rule == ruleName {
|
|
||||||
fn(rulesSlice[idx+1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func splitStatementByRegex(str string, regx string) []string {
|
func splitStatementByRegex(str string, regx string) []string {
|
||||||
|
|
||||||
input := str
|
input := str
|
||||||
|
|
@ -239,3 +283,19 @@ func splitStatementByRegex(str string, regx string) []string {
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isOK[K comparable, V comparable](mp map[K]V, key K) (V, bool) {
|
||||||
|
if v, ok := mp[key]; ok {
|
||||||
|
return v, true
|
||||||
|
} else {
|
||||||
|
return v, false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func OK[K comparable, V comparable](mp map[K]V, key K) bool {
|
||||||
|
if _, ok := mp[key]; ok {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
214
zgate.go
214
zgate.go
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"github.com/zeevdiukman/go-reverseproxy"
|
"github.com/zeevdiukman/go-reverseproxy"
|
||||||
"github.com/zeevdiukman/go-router"
|
"github.com/zeevdiukman/go-router"
|
||||||
"github.com/zeevdiukman/go-server"
|
"github.com/zeevdiukman/go-server"
|
||||||
|
|
@ -17,37 +18,45 @@ const CERTS_PATH string = "./assets/certs/"
|
||||||
|
|
||||||
type Zgate struct {
|
type Zgate struct {
|
||||||
Context context.Context
|
Context context.Context
|
||||||
// Routers struct {
|
|
||||||
// Maps map[string]*router.HostRouter
|
|
||||||
// }
|
|
||||||
// map[string]*router.HostRouter
|
|
||||||
// Rules map[string]map[string]string
|
|
||||||
// Services map[string]string
|
|
||||||
Config *config.Config
|
Config *config.Config
|
||||||
DomainRouters DomainRouters
|
// DomainRouters DomainRouters
|
||||||
EntryPoints EntryPoints
|
EntryPoints EntryPoints
|
||||||
ActiveEntryPoints ActiveEntryPoints
|
ActiveEntryPoints ActiveEntryPoints
|
||||||
}
|
}
|
||||||
type ActiveEntryPoints map[string]bool
|
type ActiveEntryPoints map[string]bool
|
||||||
type DomainRouters map[string]*router.DomainRouter
|
|
||||||
|
// type DomainRouters map[string]*mux.Router
|
||||||
type EntryPoints map[string]*EntryPoint
|
type EntryPoints map[string]*EntryPoint
|
||||||
type EntryPoint struct {
|
type EntryPoint struct {
|
||||||
*server.Server
|
IsTLS bool
|
||||||
*router.Router
|
Server *server.Server
|
||||||
|
Router *mux.Router
|
||||||
|
// Router *router.Router
|
||||||
|
|
||||||
HostRouters HostRouters
|
HostRouters HostRouters
|
||||||
|
Name string
|
||||||
}
|
}
|
||||||
type HostRouters map[string]*router.DomainRouter
|
type HostRouters map[string]*router.DomainRouter
|
||||||
|
|
||||||
func New() *Zgate {
|
func New() *Zgate {
|
||||||
zGate := &Zgate{}
|
zGate := &Zgate{
|
||||||
zGate.Context = context.Background()
|
Context: context.Background(),
|
||||||
zGate.Config = config.New()
|
Config: config.New(),
|
||||||
|
// DomainRouters: DomainRouters{},
|
||||||
|
EntryPoints: EntryPoints{},
|
||||||
|
ActiveEntryPoints: ActiveEntryPoints{},
|
||||||
|
}
|
||||||
zGate.initActiveEntryPoints()
|
zGate.initActiveEntryPoints()
|
||||||
zGate.DomainRouters = make(DomainRouters)
|
zGate.Config.Viper.WatchConfig()
|
||||||
zGate.EntryPoints = make(EntryPoints)
|
|
||||||
return zGate
|
return zGate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (zGate *Zgate) NewReverseProxy(serviceName string) *reverseproxy.ReverseProxy {
|
||||||
|
serviceURL := zGate.Config.HTTP.Services[serviceName].URL
|
||||||
|
newReverseProxy := reverseproxy.New(zGate.Context, serviceURL)
|
||||||
|
return newReverseProxy
|
||||||
|
}
|
||||||
|
|
||||||
func (ep EntryPoints) ForEach(f func(string, *EntryPoint)) {
|
func (ep EntryPoints) ForEach(f func(string, *EntryPoint)) {
|
||||||
forEach(ep, f)
|
forEach(ep, f)
|
||||||
}
|
}
|
||||||
|
|
@ -59,58 +68,109 @@ func forEach[K comparable, V any](mp map[K]V, f func(K, V)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zGate *Zgate) initActiveEntryPoints() {
|
func (zGate *Zgate) initActiveEntryPoints() {
|
||||||
activeEntryPoints := make(ActiveEntryPoints)
|
zGate.Config.EntryPoints.ForEach(func(epName string, epConfig *config.EntryPoint) {
|
||||||
zGate.Config.EntryPoints.ForEach(func(entryPointName string, entryPointConfig *config.EntryPoint) {
|
|
||||||
zGate.Config.HTTP.Routers.ForEach(func(rName string, rConfig *config.Router) {
|
zGate.Config.HTTP.Routers.ForEach(func(rName string, rConfig *config.Router) {
|
||||||
if rConfig.EntryPoint == entryPointName {
|
if rConfig.EntryPoint == epName {
|
||||||
activeEntryPoints[entryPointName] = true
|
zGate.ActiveEntryPoints[epName] = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
zGate.ActiveEntryPoints = activeEntryPoints
|
|
||||||
}
|
|
||||||
func (zGate *Zgate) BuildActiveEntryPoints() {
|
|
||||||
zGate.Config.EntryPoints.ForEach(func(entryPointName string, entryPointConfig *config.EntryPoint) {
|
|
||||||
if isUsed, ok := zGate.ActiveEntryPoints[entryPointName]; ok && isUsed {
|
|
||||||
if !isOK(zGate.ActiveEntryPoints, entryPointName) {
|
|
||||||
zGate.EntryPoints = make(map[string]*EntryPoint)
|
|
||||||
}
|
|
||||||
r := router.NewRouter()
|
|
||||||
_, portStr, _ := strings.Cut(entryPointConfig.Address, ":")
|
|
||||||
port, _ := strconv.Atoi(portStr)
|
|
||||||
s := server.New().Name(entryPointName).Port(port)
|
|
||||||
s.Router(r)
|
|
||||||
zGate.EntryPoints[entryPointName] = &EntryPoint{
|
|
||||||
Server: s,
|
|
||||||
Router: r,
|
|
||||||
HostRouters: make(map[string]*router.DomainRouter),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zGate *Zgate) BuildRouters() {
|
// func (zGate *Zgate) BuildActiveEntryPoints() {
|
||||||
zGate.Config.HTTP.Routers.ForEach(func(rName string, rConfig *config.Router) {
|
// zGate.Config.EntryPoints.ForEach(func(entryPointName string, entryPointConfig *config.EntryPoint) {
|
||||||
if isUsed, ok := zGate.ActiveEntryPoints[rConfig.EntryPoint]; ok && isUsed {
|
// v, ok := isOK(zGate.ActiveEntryPoints, entryPointName)
|
||||||
domain := rConfig.Rules.Map["Domain"].Value
|
// if ok && v {
|
||||||
serviceURL := zGate.Config.HTTP.Services[rConfig.Service].URL
|
// port := strAddressPortToInt(entryPointConfig.Address)
|
||||||
if _, ok := zGate.EntryPoints[rConfig.EntryPoint]; ok {
|
// newEntryPoint := zGate.EntryPoints.NewEntryPoint(entryPointName)
|
||||||
entryPoint := zGate.EntryPoints[rConfig.EntryPoint]
|
// newEntryPoint.Server.Port(port).Name(entryPointName)
|
||||||
if _, ok := entryPoint.HostRouters[domain]; !ok {
|
// newEntryPoint.Server.Router(newEntryPoint.Router)
|
||||||
entryPoint.HostRouters = make(map[string]*router.DomainRouter)
|
// }
|
||||||
}
|
// })
|
||||||
rp := reverseproxy.New(zGate.Context, serviceURL)
|
// }
|
||||||
rp.DirectorFunc(func(jup reverseproxy.JoinURLPathFunc) reverseproxy.DirectorFunc {
|
|
||||||
return defaultDirector(rp, jup)
|
func (entryPoints EntryPoints) GetEntryPoint(name string) *EntryPoint {
|
||||||
})
|
return entryPoints[name]
|
||||||
r := zGate.EntryPoints[rConfig.EntryPoint].Router
|
|
||||||
hostRouter := r.NewDomainRouter(domain)
|
|
||||||
hostRouter.Handler(rp)
|
|
||||||
zGate.EntryPoints[rConfig.EntryPoint].HostRouters[domain] = hostRouter
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (entryPoints EntryPoints) NewEntryPoint(name string) *EntryPoint {
|
||||||
|
entryPoints[name] = &EntryPoint{
|
||||||
|
Server: server.New(),
|
||||||
|
Router: mux.NewRouter(),
|
||||||
|
HostRouters: HostRouters{},
|
||||||
|
Name: name,
|
||||||
|
IsTLS: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
return entryPoints[name]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entryPoint *EntryPoint) SetName(name string) *EntryPoint {
|
||||||
|
entryPoint.Name = name
|
||||||
|
return entryPoint
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entryPoint *EntryPoint) NewServer() *EntryPoint {
|
||||||
|
entryPoint.Server = server.New()
|
||||||
|
entryPoint.Server.Name(entryPoint.Name)
|
||||||
|
return entryPoint
|
||||||
|
}
|
||||||
|
func (entryPoint *EntryPoint) Port(port int) *EntryPoint {
|
||||||
|
entryPoint.Server.Port(port)
|
||||||
|
return entryPoint
|
||||||
|
}
|
||||||
|
func (entryPoint *EntryPoint) SetServer(s *server.Server) *EntryPoint {
|
||||||
|
entryPoint.Server = s
|
||||||
|
return entryPoint
|
||||||
|
}
|
||||||
|
func (entryPoints EntryPoints) GetServer(name string) *server.Server {
|
||||||
|
return entryPoints[name].Server
|
||||||
|
}
|
||||||
|
func (entryPoints EntryPoints) GetRouter(name string) *mux.Router {
|
||||||
|
return entryPoints[name].Router
|
||||||
|
}
|
||||||
|
func (entryPoint *EntryPoint) NewRouter() *EntryPoint {
|
||||||
|
r := mux.NewRouter()
|
||||||
|
entryPoint.SetRouter(r)
|
||||||
|
entryPoint.Router.Name(entryPoint.Name)
|
||||||
|
return entryPoint
|
||||||
|
}
|
||||||
|
func (entryPoint *EntryPoint) SetRouter(r *mux.Router) *EntryPoint {
|
||||||
|
entryPoint.Server.Handler = r
|
||||||
|
entryPoint.Router = r
|
||||||
|
return entryPoint
|
||||||
|
}
|
||||||
|
|
||||||
|
// func (entryPoint *EntryPoint) IsEntryPointTLS() bool {
|
||||||
|
|
||||||
|
// name := entryPoint.IsTLS
|
||||||
|
// z
|
||||||
|
// return entryPoint
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (zGate *Zgate) BuildRouters() {
|
||||||
|
// zGate.Config.HTTP.Routers.ForEach(func(rName string, rConfig *config.Router) {
|
||||||
|
// v, ok := isOK(zGate.ActiveEntryPoints, rConfig.EntryPoint)
|
||||||
|
// if ok && v {
|
||||||
|
// domain := rConfig.Rules.Map["Domain"].Value
|
||||||
|
// serviceURL := zGate.Config.HTTP.Services[rConfig.Service].URL
|
||||||
|
// if isOK(zGate.EntryPoints, rConfig.EntryPoint); ok {
|
||||||
|
// entryPoint := zGate.EntryPoints[rConfig.EntryPoint]
|
||||||
|
// if _, ok := entryPoint.HostRouters[domain]; !ok {
|
||||||
|
// entryPoint.HostRouters = make(map[string]*router.DomainRouter)
|
||||||
|
// }
|
||||||
|
// rp := reverseproxy.New(zGate.Context, serviceURL)
|
||||||
|
// rp.DirectorFunc(func(jup reverseproxy.JoinURLPathFunc) reverseproxy.DirectorFunc {
|
||||||
|
// return DefaultDirector(rp, jup)
|
||||||
|
// })
|
||||||
|
// r := zGate.EntryPoints[rConfig.EntryPoint].Router
|
||||||
|
// hostRouter := r.NewDomainRouter(domain)
|
||||||
|
// hostRouter.Handler(rp)
|
||||||
|
// zGate.EntryPoints[rConfig.EntryPoint].HostRouters[domain] = hostRouter
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// }
|
||||||
func (zGate *Zgate) ListenAndServe() {
|
func (zGate *Zgate) ListenAndServe() {
|
||||||
zGate.EntryPoints.ForEach(func(s string, zGateEntryPoint *EntryPoint) {
|
zGate.EntryPoints.ForEach(func(s string, zGateEntryPoint *EntryPoint) {
|
||||||
//TODO: TLS per domain
|
//TODO: TLS per domain
|
||||||
|
|
@ -119,32 +179,20 @@ func (zGate *Zgate) ListenAndServe() {
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
zGateEntryPoint.CertKey(CERTS_PATH, "z.com.cert.pem", "z.com.key.pem")
|
zGateEntryPoint.Server.CertKey(CERTS_PATH, "z.com.cert.pem", "z.com.key.pem")
|
||||||
go zGateEntryPoint.ListenAndServeTLS()
|
go zGateEntryPoint.Server.ListenAndServeTLS()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (activeEntryPoints ActiveEntryPoints) BuildActiveEntryPoint(entryPointName string, port int) {
|
func isOK[K comparable, V comparable](mp map[K]V, key K) (V, bool) {
|
||||||
// r := router.NewRouter()
|
if v, ok := mp[key]; ok {
|
||||||
// _, portStr, _ := strings.Cut(port, ":")
|
return v, true
|
||||||
// port, _ := strconv.Atoi(portStr)
|
} else {
|
||||||
// s := server.New().Name(entryPointName).Port(port)
|
return v, false
|
||||||
// s.Router(r)
|
|
||||||
// entryPoint = &EntryPoint{
|
|
||||||
// Server: s,
|
|
||||||
// Router: r,
|
|
||||||
// HostRouters: make(map[string]*router.DomainRouter),
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
func isOK[K comparable, V comparable](mp map[K]V, key K) bool {
|
|
||||||
if _, ok := mp[key]; !ok {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultDirector(rpHandler *reverseproxy.ReverseProxy, jup reverseproxy.JoinURLPathFunc) func(*http.Request) {
|
func DefaultDirector(rpHandler *reverseproxy.ReverseProxy, jup reverseproxy.JoinURLPathFunc) func(*http.Request) {
|
||||||
return func(r *http.Request) {
|
return func(r *http.Request) {
|
||||||
r = r.WithContext(rpHandler.Context)
|
r = r.WithContext(rpHandler.Context)
|
||||||
ctxKey := reverseproxy.CtxKey("host")
|
ctxKey := reverseproxy.CtxKey("host")
|
||||||
|
|
@ -161,3 +209,9 @@ func defaultDirector(rpHandler *reverseproxy.ReverseProxy, jup reverseproxy.Join
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StrAddressPortToInt(addr string) int {
|
||||||
|
_, portStr, _ := strings.Cut(addr, ":")
|
||||||
|
port, _ := strconv.Atoi(portStr)
|
||||||
|
return port
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue