mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-18 23:33:51 +01:00
46 lines
830 B
Go
Executable File
46 lines
830 B
Go
Executable File
package main
|
|
|
|
type Route interface {
|
|
Start()
|
|
Stop()
|
|
}
|
|
|
|
func NewRoute(cfg *ProxyConfig) (Route, error) {
|
|
if isStreamScheme(cfg.Scheme) {
|
|
id := cfg.GetID()
|
|
if streamRoutes.Contains(id) {
|
|
return nil, NewNestedError("duplicated stream").Subject(cfg.Alias)
|
|
}
|
|
route, err := NewStreamRoute(cfg)
|
|
if err != nil {
|
|
return nil, NewNestedErrorFrom(err).Subject(cfg.Alias)
|
|
}
|
|
return route, nil
|
|
} else {
|
|
httpRoutes.Ensure(cfg.Alias)
|
|
route, err := NewHTTPRoute(cfg)
|
|
if err != nil {
|
|
return nil, NewNestedErrorFrom(err).Subject(cfg.Alias)
|
|
}
|
|
return route, nil
|
|
}
|
|
}
|
|
|
|
func isValidScheme(s string) bool {
|
|
for _, v := range ValidSchemes {
|
|
if v == s {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func isStreamScheme(s string) bool {
|
|
for _, v := range StreamSchemes {
|
|
if v == s {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|