mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-23 01:50:29 +01:00
preparing for v0.5
This commit is contained in:
37
src/proxy/fields/scheme.go
Normal file
37
src/proxy/fields/scheme.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package fields
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
E "github.com/yusing/go-proxy/error"
|
||||
F "github.com/yusing/go-proxy/utils/functional"
|
||||
)
|
||||
|
||||
type Scheme struct{ F.Stringable }
|
||||
|
||||
func NewScheme(s string) (*Scheme, E.NestedError) {
|
||||
switch s {
|
||||
case "http", "https", "tcp", "udp":
|
||||
return &Scheme{F.NewStringable(s)}, E.Nil()
|
||||
}
|
||||
return nil, E.Invalid("scheme", s)
|
||||
}
|
||||
|
||||
func NewSchemeFromPort(p string) (*Scheme, E.NestedError) {
|
||||
var s string
|
||||
switch {
|
||||
case strings.ContainsRune(p, ':'):
|
||||
s = "tcp"
|
||||
case strings.HasSuffix(p, "443"):
|
||||
s = "https"
|
||||
default:
|
||||
s = "http"
|
||||
}
|
||||
return &Scheme{F.NewStringable(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) IsStream() bool { return s.IsTCP() || s.IsUDP() }
|
||||
Reference in New Issue
Block a user