fn: remove redundant httprouter code (#532)

*) tree from https://github.com/julienschmidt/httprouter
is already in Gin and this only seems to be parsing
parameters from URI.
This commit is contained in:
Tolga Ceylan
2017-11-22 11:58:10 -08:00
committed by Reed Allman
parent d8a1431418
commit 89dc79f0b0
4 changed files with 29 additions and 682 deletions

View File

@@ -41,7 +41,13 @@ type Call interface {
// TODO build w/o closures... lazy
type CallOpt func(a *agent, c *call) error
func FromRequest(appName, path string, req *http.Request) CallOpt {
type Param struct {
Key string
Value string
}
type Params []Param
func FromRequest(appName, path string, req *http.Request, params Params) CallOpt {
return func(a *agent, c *call) error {
app, err := a.ds.GetApp(req.Context(), appName)
if err != nil {
@@ -53,11 +59,6 @@ func FromRequest(appName, path string, req *http.Request) CallOpt {
return err
}
params, match := matchRoute(route.Path, path)
if !match {
return errors.New("route does not match") // TODO wtf, can we ignore match?
}
if route.Format == "" {
route.Format = "default"
}
@@ -368,20 +369,6 @@ func (c *call) End(ctx context.Context, errIn error, t callTrigger) error {
return errIn
}
func fakeHandler(http.ResponseWriter, *http.Request, Params) {}
// TODO what is this stuff anyway?
func matchRoute(baseRoute, route string) (Params, bool) {
tree := &node{}
tree.addRoute(baseRoute, fakeHandler)
handler, p, _ := tree.getValue(route)
if handler == nil {
return nil, false
}
return p, true
}
func toEnvName(envtype, name string) string {
name = strings.Replace(name, "-", "_", -1)
if envtype == "" {