package ss // The type implements method routing. type MethodRouter struct { methodMap map[ReqMethod] Handler def Handler } // Returns new empty MethodRouter. func Method(def Handler) *MethodRouter { ret := &MethodRouter{} ret.methodMap = make(map[ReqMethod]Handler) ret.def = def return ret } // Define new handler for the specified method. func (mr *MethodRouter) Case( method ReqMethod, handler Handler, ) *MethodRouter { _, dup := mr.methodMap[method] if dup { panic("got the duplicate method") } mr.methodMap[method] = handler return mr } // Implementing the Handler. func (mr *MethodRouter) Handle(c *Context) { handler, ok := mr.methodMap[c.Method()] if !ok { if mr.def == nil { c.NotFound() } else { mr.def.Handle(c) } return } handler.Handle(c) }