mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-21 17:10:14 +01:00
v0.5: (BREAKING) simplified config format, improved output formatting, fixed docker watcher
This commit is contained in:
@@ -6,11 +6,11 @@ import (
|
||||
F "github.com/yusing/go-proxy/utils/functional"
|
||||
)
|
||||
|
||||
type Alias struct{ F.Stringable }
|
||||
type Alias string
|
||||
type Aliases struct{ *F.Slice[Alias] }
|
||||
|
||||
func NewAlias(s string) Alias {
|
||||
return Alias{F.NewStringable(s)}
|
||||
return Alias(s)
|
||||
}
|
||||
|
||||
func NewAliases(s string) Aliases {
|
||||
|
||||
@@ -2,19 +2,11 @@ package fields
|
||||
|
||||
import (
|
||||
E "github.com/yusing/go-proxy/error"
|
||||
F "github.com/yusing/go-proxy/utils/functional"
|
||||
)
|
||||
|
||||
type Host struct{ F.Stringable }
|
||||
type Host string
|
||||
type Subdomain = Alias
|
||||
|
||||
func NewHost(s string) (Host, E.NestedError) {
|
||||
return Host{F.NewStringable(s)}, E.Nil()
|
||||
}
|
||||
|
||||
func (h Host) Subdomain() (*Subdomain, E.NestedError) {
|
||||
if i := h.IndexRune(':'); i != -1 {
|
||||
return &Subdomain{h.SubStr(0, i)}, E.Nil()
|
||||
}
|
||||
return nil, E.Invalid("host", h)
|
||||
return Host(s), E.Nil()
|
||||
}
|
||||
|
||||
@@ -2,14 +2,13 @@ package fields
|
||||
|
||||
import (
|
||||
E "github.com/yusing/go-proxy/error"
|
||||
F "github.com/yusing/go-proxy/utils/functional"
|
||||
)
|
||||
|
||||
type Path struct{ F.Stringable }
|
||||
type Path string
|
||||
|
||||
func NewPath(s string) (Path, E.NestedError) {
|
||||
if s == "" || s[0] == '/' {
|
||||
return Path{F.NewStringable(s)}, E.Nil()
|
||||
return Path(s), E.Nil()
|
||||
}
|
||||
return Path{}, E.Invalid("path", s).With("must be empty or start with '/'")
|
||||
return "", E.Invalid("path", s).With("must be empty or start with '/'")
|
||||
}
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
package fields
|
||||
|
||||
import (
|
||||
F "github.com/yusing/go-proxy/utils/functional"
|
||||
E "github.com/yusing/go-proxy/error"
|
||||
)
|
||||
|
||||
type PathMode struct{ F.Stringable }
|
||||
type PathMode string
|
||||
|
||||
func NewPathMode(pm string) (PathMode, E.NestedError) {
|
||||
switch pm {
|
||||
case "", "forward":
|
||||
return PathMode{F.NewStringable(pm)}, E.Nil()
|
||||
return PathMode(pm), E.Nil()
|
||||
default:
|
||||
return PathMode{}, E.Invalid("path mode", pm)
|
||||
return "", E.Invalid("path mode", pm)
|
||||
}
|
||||
}
|
||||
|
||||
func (p PathMode) IsRemove() bool {
|
||||
return p.String() == ""
|
||||
return p == ""
|
||||
}
|
||||
|
||||
func (p PathMode) IsForward() bool {
|
||||
return p.String() == "forward"
|
||||
return p == "forward"
|
||||
}
|
||||
|
||||
@@ -4,20 +4,19 @@ import (
|
||||
"strings"
|
||||
|
||||
E "github.com/yusing/go-proxy/error"
|
||||
F "github.com/yusing/go-proxy/utils/functional"
|
||||
)
|
||||
|
||||
type Scheme struct{ F.Stringable }
|
||||
type Scheme string
|
||||
|
||||
func NewScheme(s string) (*Scheme, E.NestedError) {
|
||||
func NewScheme(s string) (Scheme, E.NestedError) {
|
||||
switch s {
|
||||
case "http", "https", "tcp", "udp":
|
||||
return &Scheme{F.NewStringable(s)}, E.Nil()
|
||||
return Scheme(s), E.Nil()
|
||||
}
|
||||
return nil, E.Invalid("scheme", s)
|
||||
return "", E.Invalid("scheme", s)
|
||||
}
|
||||
|
||||
func NewSchemeFromPort(p string) (*Scheme, E.NestedError) {
|
||||
func NewSchemeFromPort(p string) (Scheme, E.NestedError) {
|
||||
var s string
|
||||
switch {
|
||||
case strings.ContainsRune(p, ':'):
|
||||
@@ -27,11 +26,11 @@ func NewSchemeFromPort(p string) (*Scheme, E.NestedError) {
|
||||
default:
|
||||
s = "http"
|
||||
}
|
||||
return &Scheme{F.NewStringable(s)}, E.Nil()
|
||||
return Scheme(s), E.Nil()
|
||||
}
|
||||
|
||||
func (s Scheme) IsHTTP() bool { return s.String() == "http" }
|
||||
func (s Scheme) IsHTTPS() bool { return s.String() == "https" }
|
||||
func (s Scheme) IsTCP() bool { return s.String() == "tcp" }
|
||||
func (s Scheme) IsUDP() bool { return s.String() == "udp" }
|
||||
func (s Scheme) IsHTTP() bool { return s == "http" }
|
||||
func (s Scheme) IsHTTPS() bool { return s == "https" }
|
||||
func (s Scheme) IsTCP() bool { return s == "tcp" }
|
||||
func (s Scheme) IsUDP() bool { return s == "udp" }
|
||||
func (s Scheme) IsStream() bool { return s.IsTCP() || s.IsUDP() }
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package fields
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
E "github.com/yusing/go-proxy/error"
|
||||
)
|
||||
|
||||
type StreamScheme struct {
|
||||
ListeningScheme *Scheme `json:"listening"`
|
||||
ProxyScheme *Scheme `json:"proxy"`
|
||||
ListeningScheme Scheme `json:"listening"`
|
||||
ProxyScheme Scheme `json:"proxy"`
|
||||
}
|
||||
|
||||
func NewStreamScheme(s string) (ss *StreamScheme, err E.NestedError) {
|
||||
@@ -31,12 +32,12 @@ func NewStreamScheme(s string) (ss *StreamScheme, err E.NestedError) {
|
||||
}
|
||||
|
||||
func (s StreamScheme) String() string {
|
||||
return s.ListeningScheme.String() + " -> " + s.ProxyScheme.String()
|
||||
return fmt.Sprintf("%s -> %s", s.ListeningScheme, s.ProxyScheme)
|
||||
}
|
||||
|
||||
// IsCoherent checks if the ListeningScheme and ProxyScheme of the StreamScheme are equal.
|
||||
//
|
||||
// It returns a boolean value indicating whether the ListeningScheme and ProxyScheme are equal.
|
||||
func (s StreamScheme) IsCoherent() bool {
|
||||
return *s.ListeningScheme == *s.ProxyScheme
|
||||
return s.ListeningScheme == s.ProxyScheme
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user