MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / NewAPI

Function NewAPI

api/api.go:153–176  ·  view source on GitHub ↗

NewAPI creates a new Api instance with the provided LedgerForge service and sets up the router. Parameters: - b: The LedgerForge service used to interact with business logic. Returns: - *Api: A new instance of the Api with the configured router.

(b *ledgerforge.LedgerForge)

Source from the content-addressed store, hash-verified

151// Returns:
152// - *Api: A new instance of the Api with the configured router.
153func NewAPI(b *ledgerforge.LedgerForge) *Api {
154 gin.SetMode(gin.ReleaseMode)
155 conf, err := config.Fetch()
156 if err != nil {
157 return nil
158 }
159 r := gin.Default()
160 auth := middleware.NewAuthMiddleware(b)
161 r.Use(middleware.RateLimitMiddleware(conf))
162 r.Use(middleware.SecurityHeaders())
163 r.Use(otelgin.Middleware("LEDGERFORGE",
164 otelgin.WithFilter(func(r *http.Request) bool {
165 // Exclude high-frequency operational endpoints from tracing
166 // to avoid polluting the trace feed with noise.
167 return r.URL.Path != "/metrics"
168 }),
169 ))
170
171 r.GET("/", func(c *gin.Context) {
172 c.JSON(200, "server running...")
173 })
174
175 return &Api{ledgerforge: b, router: r, auth: auth}
176}
177
178// Search performs a search query on a specified collection.
179// It binds the incoming JSON request to a SearchCollectionParams object,

Callers 2

initializeRouterFunction · 0.92
setupRouterFunction · 0.85

Calls 4

FetchFunction · 0.92
NewAuthMiddlewareFunction · 0.92
RateLimitMiddlewareFunction · 0.92
SecurityHeadersFunction · 0.92

Tested by 1

setupRouterFunction · 0.68