//Converts a string representation of the method type into the internal constant func ToMethod(method string) Method { switch method { case "GET": return GET case "POST": return POST case "PUT": return PUT case "HEAD": return HEAD case "DELETE": return DELETE default: log.Error("Unable to decode Http method " + method) return GET } }
// Registers a new handler // Will check that it does not conflict with a route that is already configured func Register(path string, method Method, consumes []string, produces []string, handler func(Request) (int, []byte)) bool { //Trim trailing slash if it exits var trailingSlash, _ = regexp.MatchString(".+/$", path) if trailingSlash { path = path[0 : len(path)-1] } regRoute := Route{path, method, consumes, produces, handler} for _, route := range routes { var match, status, _, _ = route.matchRoute(regRoute) if match && status == http.StatusOK { log.Error("Route %v already registered, ignoring ", regRoute) return false } } log.Debug("Route %v registered.", regRoute) routes = append(routes, regRoute) return true }