Skip to main content

Chi

The Chi v5 router is supported by Gleece's routes generator.

Set Router Engine

In the Gleece configuration (usually gleece.config.json), set the routesConfig->engine to chi.

Configure Security Function

In the Gleece configuration, set the full package path in routesConfig->authorizationConfig->authFileFullPackageName (e.g., github.com/gopher-fleece/gleece/security).

Generate Routes File

Gleece CLI will generate a routes file from your annotated controllers. The output file path is specified in the routesConfig->outputPath property of your Gleece configuration file.

Import and Register Routes

In your main.go file, import the generated routes file and call the RegisterRoutes function to register the routes with the Chi router instance.

Routing Example

package main

import (
"net/http"

"github.com/go-chi/chi/v5"
"<package>/routes" // Import the generated routes file
)

func main() {
// Create a new Chi router
r := chi.NewRouter()

// Register Gleece routes
routes.RegisterRoutes(r)

// Start the server on port 8080
http.ListenAndServe(":8080", r)
}

Authentication Function

package security

import (
"net/http"

"github.com/gopher-fleece/runtime"
)

func GleeceRequestAuthorization(r *http.Request, check runtime.SecurityCheck) *runtime.SecurityError {
return nil
}