mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-26 19:31:46 +01:00
v0.5.0-rc5: check release
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
. "github.com/yusing/go-proxy/common"
|
||||
D "github.com/yusing/go-proxy/docker"
|
||||
F "github.com/yusing/go-proxy/utils/functional"
|
||||
)
|
||||
|
||||
type (
|
||||
ProxyEntry struct {
|
||||
ProxyEntry struct { // raw entry object before validation
|
||||
Alias string `yaml:"-" json:"-"`
|
||||
Scheme string `yaml:"scheme" json:"scheme"`
|
||||
Host string `yaml:"host" json:"host"`
|
||||
@@ -16,35 +19,66 @@ type (
|
||||
PathPatterns []string `yaml:"path_patterns" json:"path_patterns"` // http(s) proxy only
|
||||
SetHeaders map[string]string `yaml:"set_headers" json:"set_headers"` // http(s) proxy only
|
||||
HideHeaders []string `yaml:"hide_headers" json:"hide_headers"` // http(s) proxy only
|
||||
|
||||
/* Docker only */
|
||||
*D.ProxyProperties `yaml:"-" json:"-"`
|
||||
}
|
||||
|
||||
ProxyEntries = *F.Map[string, *ProxyEntry]
|
||||
ProxyEntries = F.Map[string, *ProxyEntry]
|
||||
)
|
||||
|
||||
var NewProxyEntries = F.NewMap[string, *ProxyEntry]
|
||||
var NewProxyEntries = F.NewMapOf[string, *ProxyEntry]
|
||||
|
||||
func (e *ProxyEntry) SetDefaults() {
|
||||
if e.Scheme == "" {
|
||||
if strings.ContainsRune(e.Port, ':') {
|
||||
switch {
|
||||
case strings.ContainsRune(e.Port, ':'):
|
||||
e.Scheme = "tcp"
|
||||
} else {
|
||||
switch e.Port {
|
||||
case "443", "8443":
|
||||
e.Scheme = "https"
|
||||
default:
|
||||
e.Scheme = "http"
|
||||
case e.ProxyProperties != nil:
|
||||
if _, ok := ServiceNamePortMapTCP[e.ImageName]; ok {
|
||||
e.Scheme = "tcp"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if e.Scheme == "" {
|
||||
switch e.Port {
|
||||
case "443", "8443":
|
||||
e.Scheme = "https"
|
||||
default:
|
||||
e.Scheme = "http"
|
||||
}
|
||||
}
|
||||
if e.Host == "" {
|
||||
e.Host = "localhost"
|
||||
}
|
||||
if e.Port == "" {
|
||||
switch e.Scheme {
|
||||
case "http":
|
||||
e.Port = "80"
|
||||
case "https":
|
||||
e.Port = "443"
|
||||
e.Port = e.FirstPort
|
||||
}
|
||||
if e.Port == "" {
|
||||
if port, ok := ServiceNamePortMapTCP[e.Port]; ok {
|
||||
e.Port = strconv.Itoa(port)
|
||||
} else if port, ok := ImageNamePortMapHTTP[e.Port]; ok {
|
||||
e.Port = strconv.Itoa(port)
|
||||
} else {
|
||||
switch e.Scheme {
|
||||
case "http":
|
||||
e.Port = "80"
|
||||
case "https":
|
||||
e.Port = "443"
|
||||
}
|
||||
}
|
||||
}
|
||||
if e.IdleTimeout == "" {
|
||||
e.IdleTimeout = IdleTimeoutDefault
|
||||
}
|
||||
if e.WakeTimeout == "" {
|
||||
e.WakeTimeout = WakeTimeoutDefault
|
||||
}
|
||||
if e.StopTimeout == "" {
|
||||
e.StopTimeout = StopTimeoutDefault
|
||||
}
|
||||
if e.StopMethod == "" {
|
||||
e.StopMethod = StopMethodDefault
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user