v0.5: (BREAKING) simplified config format, improved output formatting, fixed docker watcher

This commit is contained in:
yusing
2024-09-16 03:48:39 +08:00
parent 719693deb7
commit 5be8659a99
34 changed files with 165 additions and 343 deletions

View File

@@ -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() }