A lightweight, modular Go server framework.
go get github.com/a-digi/coco-server- Simple server configuration
- Routing and middleware support
- Request and response handling
- Dependency injection
- Logging
- Security layer (request authorization)
package main
import (
"github.com/a-digi/coco-server/server"
"github.com/a-digi/coco-server/server/security"
)
type MySecurityLayer struct{}
func (s *MySecurityLayer) Authorize(w http.ResponseWriter, r *http.Request, ctx *server.Context) error {
// Implement your authorization logic here
// Return an error to deny access
return nil // Allow all requests
}
func main() {
srv := server.New()
srv.SecurityLayer = &MySecurityLayer{}
srv.GET("/", func(ctx *server.Context) {
ctx.String(200, "Hello, world!")
})
srv.Run(8080)
}The security layer allows you to add custom request authorization logic. Implement the Authorize method and assign your security layer to the server. If Authorize returns an error, the request is denied with HTTP 403 Forbidden.
server/– Main framework logicconfig.go– Configurationlog.go– Loggingpid.go– Process managementport.go– Port managementserver.go– Server logicdi/– Dependency injectionrequest/– Request handlingresponse/– Response handlingrouting/– Routing and route managementsecurity/– Security layer logic
Full documentation can be found at pkg.go.dev.
MIT License – see LICENSE