fixed loadbalancer with idlewatcher, fixed reload issue

This commit is contained in:
yusing
2024-10-20 09:46:02 +08:00
parent 01ffe0d97c
commit a278711421
78 changed files with 906 additions and 609 deletions

View File

@@ -7,7 +7,7 @@ import (
E "github.com/yusing/go-proxy/internal/error"
)
func ValidateHTTPHeaders(headers map[string]string) (http.Header, E.NestedError) {
func ValidateHTTPHeaders(headers map[string]string) (http.Header, E.Error) {
h := make(http.Header)
for k, v := range headers {
vSplit := strings.Split(v, ",")

View File

@@ -9,6 +9,6 @@ type (
Subdomain = Alias
)
func ValidateHost[String ~string](s String) (Host, E.NestedError) {
func ValidateHost[String ~string](s String) (Host, E.Error) {
return Host(s), nil
}

View File

@@ -13,7 +13,7 @@ type (
var pathPattern = regexp.MustCompile(`^(/[-\w./]*({\$\})?|((GET|POST|DELETE|PUT|HEAD|OPTION) /[-\w./]*({\$\})?))$`)
func ValidatePathPattern(s string) (PathPattern, E.NestedError) {
func ValidatePathPattern(s string) (PathPattern, E.Error) {
if len(s) == 0 {
return "", E.Invalid("path", "must not be empty")
}
@@ -23,7 +23,7 @@ func ValidatePathPattern(s string) (PathPattern, E.NestedError) {
return PathPattern(s), nil
}
func ValidatePathPatterns(s []string) (PathPatterns, E.NestedError) {
func ValidatePathPatterns(s []string) (PathPatterns, E.Error) {
if len(s) == 0 {
return []PathPattern{"/"}, nil
}

View File

@@ -8,7 +8,7 @@ import (
type Port int
func ValidatePort[String ~string](v String) (Port, E.NestedError) {
func ValidatePort[String ~string](v String) (Port, E.Error) {
p, err := strconv.Atoi(string(v))
if err != nil {
return ErrPort, E.Invalid("port number", v).With(err)
@@ -16,7 +16,7 @@ func ValidatePort[String ~string](v String) (Port, E.NestedError) {
return ValidatePortInt(p)
}
func ValidatePortInt[Int int | uint16](v Int) (Port, E.NestedError) {
func ValidatePortInt[Int int | uint16](v Int) (Port, E.Error) {
p := Port(v)
if !p.inBound() {
return ErrPort, E.OutOfRange("port", p)

View File

@@ -6,7 +6,7 @@ import (
type Scheme string
func NewScheme[String ~string](s String) (Scheme, E.NestedError) {
func NewScheme[String ~string](s String) (Scheme, E.Error) {
switch s {
case "http", "https", "tcp", "udp":
return Scheme(s), nil

View File

@@ -12,7 +12,7 @@ type StreamPort struct {
ProxyPort Port `json:"proxy"`
}
func ValidateStreamPort(p string) (_ StreamPort, err E.NestedError) {
func ValidateStreamPort(p string) (_ StreamPort, err E.Error) {
split := strings.Split(p, ":")
switch len(split) {
@@ -47,7 +47,7 @@ func ValidateStreamPort(p string) (_ StreamPort, err E.NestedError) {
return StreamPort{listeningPort, proxyPort}, nil
}
func parseNameToPort(name string) (Port, E.NestedError) {
func parseNameToPort(name string) (Port, E.Error) {
port, ok := common.ServiceNamePortMapTCP[name]
if !ok {
return ErrPort, E.Invalid("service", name)

View File

@@ -12,7 +12,7 @@ type StreamScheme struct {
ProxyScheme Scheme `json:"proxy"`
}
func ValidateStreamScheme(s string) (ss *StreamScheme, err E.NestedError) {
func ValidateStreamScheme(s string) (ss *StreamScheme, err E.Error) {
ss = &StreamScheme{}
parts := strings.Split(s, ":")
if len(parts) == 1 {