Skip to main content

App

App is Zinc’s main application type.

Create an app​

app := zinc.New()
app := zinc.NewWithConfig(zinc.Config{StrictRouting: true})

Core responsibilities​

App is responsible for:

  • route registration
  • middleware registration
  • mounting sub-handlers
  • lifecycle methods such as Listen, Serve, and Shutdown
  • route introspection and named route lookup

Common methods​

MethodPurpose
Get, Post, Put, Patch, Delete, Head, Options, Connect, TraceRegister routes
Add, Match, All, AnyRegister routes more generically
Use, UsePrefixRegister middleware
Group, RouteCreate grouped route trees
Mount, Wrap, WrapFuncIntegrate stdlib or external handlers
Static, StaticFS, File, FileFSServe files and directories
NotFound, RouteNotFound, MethodNotAllowedCustomize error routing
Routes, FindRoute, RouteByName, URLInspect routes and generate URLs
Listen, ListenTLS, Serve, ShutdownRun and stop the app

Route methods accept a handler chain. Middleware goes before the final handler.

app.Post("/posts", authUser, requireRole("editor"), createPost)

Get also accepts a literal string for quick static text responses.

app.Get("/health", "ok")

Named route registration​

Use Handle(RouteSpec) when you want route naming and reverse URL generation.

if err := app.Handle(zinc.RouteSpec{
Name: "users.show",
Method: zinc.MethodGet,
Path: "/users/:id",
Handler: showUser,
}); err != nil {
log.Fatal(err)
}

Introspection​

routes := app.Routes()
route, ok := app.FindRoute("GET", "/users/42")
named, ok := app.RouteByName("users.show")
url, err := app.URL("users.show", "42")

Routes() returns RouteInfo values containing:

  • Name
  • Method
  • Path
  • Params
  • Mounted
  • Handler

Advanced lifecycle helpers​

Listen is the shortest way to start an app. With no address, it listens on :8080.

app.Listen()
app.Listen(":3000")

Most apps do not need these directly, but Zinc exposes:

  • AcquireContext
  • ReleaseContext

They are useful for adapters, framework integration, and low-level tests.

For normal applications, register routes and let Zinc manage context lifecycle.