mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-11 03:06:51 +02:00
preparing for v0.5
This commit is contained in:
34
src/route/route.go
Executable file
34
src/route/route.go
Executable file
@@ -0,0 +1,34 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
E "github.com/yusing/go-proxy/error"
|
||||
M "github.com/yusing/go-proxy/models"
|
||||
P "github.com/yusing/go-proxy/proxy"
|
||||
F "github.com/yusing/go-proxy/utils/functional"
|
||||
)
|
||||
|
||||
type (
|
||||
Route interface {
|
||||
Start() E.NestedError
|
||||
Stop() E.NestedError
|
||||
}
|
||||
Routes = F.Map[string, Route]
|
||||
)
|
||||
|
||||
// function alias
|
||||
var NewRoutes = F.NewMap[string, Route]
|
||||
|
||||
func NewRoute(en *M.ProxyEntry) (Route, E.NestedError) {
|
||||
entry, err := P.NewEntry(en)
|
||||
if err.IsNotNil() {
|
||||
return nil, err
|
||||
}
|
||||
switch e := entry.(type) {
|
||||
case *P.StreamEntry:
|
||||
return NewStreamRoute(e)
|
||||
case *P.Entry:
|
||||
return NewHTTPRoute(e)
|
||||
default:
|
||||
panic("bug: should not reach here")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user