feat: initial implementation of go-kite
Core framework: - Kite router with full HTTP method support (GET, POST, PUT, DELETE, HEAD, OPTIONS, CONNECT, TRACE) - Nestable route groups with prefix and middleware inheritance - Global, group, and route-level middleware with onion ordering - Centralized error, not-found, and method-not-allowed handlers - Graceful shutdown on SIGTERM/SIGINT with configurable timeout - Configurable server read, write, and idle timeouts - Context with typed request/response helpers, value store, cookie, form, and body binding support - Response writer wrapper for status code tracking Middleware: - Logger with configurable output, format, and skip function - Recovery with configurable panic handler - RequestID with configurable header and generator, forwards incoming IDs - CORS with configurable origins, methods, headers, credentials, and max age - MaxBodySize with configurable byte limit Docs: - README with quickstart, routing, middleware, context API reference, and TLS guide
This commit is contained in:
57
group.go
Normal file
57
group.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package kite
|
||||
|
||||
import "net/http"
|
||||
|
||||
type Group struct {
|
||||
k *Kite
|
||||
prefix string
|
||||
mws []Middleware
|
||||
}
|
||||
|
||||
func (g *Group) Group(prefix string, mws ...Middleware) *Group {
|
||||
return &Group{
|
||||
k: g.k,
|
||||
prefix: g.prefix + prefix,
|
||||
mws: append(append([]Middleware{}, g.mws...), mws...),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Group) Use(mws ...Middleware) {
|
||||
g.mws = append(g.mws, mws...)
|
||||
}
|
||||
|
||||
func (g *Group) CONNECT(path string, h Handler, mws ...Middleware) {
|
||||
g.handle(http.MethodConnect, path, h, mws...)
|
||||
}
|
||||
|
||||
func (g *Group) DELETE(path string, h Handler, mws ...Middleware) {
|
||||
g.handle(http.MethodDelete, path, h, mws...)
|
||||
}
|
||||
|
||||
func (g *Group) GET(path string, h Handler, mws ...Middleware) {
|
||||
g.handle(http.MethodGet, path, h, mws...)
|
||||
}
|
||||
|
||||
func (g *Group) HEAD(path string, h Handler, mws ...Middleware) {
|
||||
g.handle(http.MethodHead, path, h, mws...)
|
||||
}
|
||||
|
||||
func (g *Group) OPTIONS(path string, h Handler, mws ...Middleware) {
|
||||
g.handle(http.MethodOptions, path, h, mws...)
|
||||
}
|
||||
|
||||
func (g *Group) POST(path string, h Handler, mws ...Middleware) {
|
||||
g.handle(http.MethodPost, path, h, mws...)
|
||||
}
|
||||
|
||||
func (g *Group) PUT(path string, h Handler, mws ...Middleware) {
|
||||
g.handle(http.MethodPut, path, h, mws...)
|
||||
}
|
||||
|
||||
func (g *Group) TRACE(path string, h Handler, mws ...Middleware) {
|
||||
g.handle(http.MethodTrace, path, h, mws...)
|
||||
}
|
||||
|
||||
func (g *Group) handle(method, path string, h Handler, mws ...Middleware) {
|
||||
g.k.handle(method, g.prefix+path, h, append(g.mws, mws...)...)
|
||||
}
|
||||
Reference in New Issue
Block a user