// protects 'routes' if dynamic routes are enabled routesLock sync.RWMutex }
1 2 3 4 5 6 7 8 9 10
// Path specifies the root URL template path of the WebService. // All Routes will be relative to this path. func(w *WebService)Path(root string) *WebService { w.rootPath = root iflen(w.rootPath) == 0 { w.rootPath = "/" } w.compilePathExpression() return w }
1 2 3 4 5 6 7 8
// Route creates a new Route using the RouteBuilder and add to the ordered list of Routes. func (w *WebService) Route(builder*RouteBuilder) *WebService { w.routesLock.Lock() defer w.routesLock.Unlock() builder.copyDefaults(w.produces, w.consumes) w.routes = append(w.routes, builder.Build()) return w }
// cached values for dispatching relativePath string pathParts []string pathExpr *pathExpression // cached compilation of relativePath as RegExp ... }
1 2
// RouteFunction declares the signature of a function that can be bound to a Route. type RouteFunction func(*Request, *Response)
1 2 3 4 5 6
// To bind the route to a function. // If this route is matched with the incoming Http Request thencall this functionwith the *Request,*Response pair. Required. func (b *RouteBuilder) To(function RouteFunction) *RouteBuilder { b.function = function return b }
1. ResourceMethod and ResourceMethodContainer
2: Apply Builder pattern to reduce clutter
3: Introduce defaults on the Resource and override per method if needed