feat: Implement basic API server with mTLS for leader join endpoint
This commit is contained in:
48
internal/api/router.go
Normal file
48
internal/api/router.go
Normal file
@ -0,0 +1,48 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Route represents a single API route
|
||||
type Route struct {
|
||||
Method string
|
||||
Path string
|
||||
Handler http.HandlerFunc
|
||||
}
|
||||
|
||||
// Router is a simple HTTP router for the KAT API
|
||||
type Router struct {
|
||||
routes []Route
|
||||
}
|
||||
|
||||
// NewRouter creates a new router instance
|
||||
func NewRouter() *Router {
|
||||
return &Router{
|
||||
routes: []Route{},
|
||||
}
|
||||
}
|
||||
|
||||
// HandleFunc registers a new route with the router
|
||||
func (r *Router) HandleFunc(method, path string, handler http.HandlerFunc) {
|
||||
r.routes = append(r.routes, Route{
|
||||
Method: strings.ToUpper(method),
|
||||
Path: path,
|
||||
Handler: handler,
|
||||
})
|
||||
}
|
||||
|
||||
// ServeHTTP implements the http.Handler interface
|
||||
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
// Find matching route
|
||||
for _, route := range r.routes {
|
||||
if route.Method == req.Method && route.Path == req.URL.Path {
|
||||
route.Handler(w, req)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// No route matched
|
||||
http.NotFound(w, req)
|
||||
}
|
Reference in New Issue
Block a user