diff --git a/contents/main.go b/contents/main.go new file mode 100644 index 0000000..dcd4b19 --- /dev/null +++ b/contents/main.go @@ -0,0 +1,15 @@ +package contents + +type Type string + + + +const ( + // Using the UTF-8 by default. + Unknown Type = "application/octet-stream" + Binary = Unknown + Plain Type = "text/plain; charset=utf-8" + Css Type = "text/css" + Html Type = "text/html" + Json Type = "application/json" +) diff --git a/method.go b/method.go new file mode 100644 index 0000000..a4905a2 --- /dev/null +++ b/method.go @@ -0,0 +1,40 @@ +package bond + +import ( + "net/http" + "github.com/di4f/bond/methods" +) + +// The type implements functionality for multiplexing +// the methods. +type MethodRouter struct { + methodMap map[methods.Method] Handler +} + +func Method() *MethodRouter { + ret := &MethodRouter{} + ret.methodMap = make(map[methods.Method] Handler) + return ret +} + +func (mr *MethodRouter) Def( + method methods.Method, + handler Handler, +) *MethodRouter { + _, dup := mr.methodMap[method] + if dup { + panic("got the duplicate method") + } + + mr.methodMap[method] = handler + return mr +} + +func (mr *MethodRouter) ServeHTTP(w ResponseWriter, r *Request) { + handler, ok := mr.methodMap[methods.Method(r.Method)] + if !ok { + http.NotFound(w, r) + return + } + handler.ServeHTTP(w, r) +} diff --git a/methods/main.go b/methods/main.go new file mode 100644 index 0000000..8e5dee6 --- /dev/null +++ b/methods/main.go @@ -0,0 +1,24 @@ +package methods + +import ( + "net/http" +) + +type Method string + +const ( + Get Method = http.MethodGet + Post Method = http.MethodPost + Put Method = http.MethodPut + Head Method = http.MethodHead + Patch Method = http.MethodPatch + Delete Method = http.MethodDelete + Connect Method = http.MethodConnect + Options Method = http.MethodOptions + Trace Method = http.MethodTrace +) + +func (m Method) String() string { + return string(m) +} + diff --git a/re.go b/re.go new file mode 100644 index 0000000..a4e719b --- /dev/null +++ b/re.go @@ -0,0 +1,29 @@ +package bond + +import ( + //"regexp" +) + +/*type ReChecker struct { + re *regexp.Regexp + handler ContextHandler +} + +func Re(re string, handler ContextHandler) *ReChecker { + ret := &ReChecker{} + ret.re = regexp.MustCompile(re) + ret.handler = handler + return ret +} + +func (rr *ReChecker) ServeHttp(c *Context) { + match := rr.re.MatchString(c.Path()) + if !match { + c.NotFound() + return + } + c.re = rr.re + c.reSubmatches = c.re.FindStringSubmatch(c.Path()) + rr.handler.ServeHttp(c) +}*/ +