# README
gin-utils
Tools and template for constructing applications using gin
.
Can provide:
- Graceful shutdown of
gin
server - Redirection of
gin
log messages tozerolog
- Some simple
gin
handlers - Template application using
gin
andzerolog
- System utility:
- Configuration struct with JSON and YAML struct tags.
Graceful Shutdown
Support graceful shutdown of gin
during an interrupt signal.
This tool captures the Linux interrupt
and kill
signals,
so it won't work (completely) with Apple or Windows.
There is a demo program located in demo/shutdown/shutdown.go
.
See package shutdown
documentation for more details.
Logging via zerolog
Support for connecting gin logging to zerolog
.
This includes request-logging middleware and
the capture and reprocessing of stderr
and stdout
streams.
There is a demo program located in demo/ginzero/ginzero.go
.
See package ginzero
documentation for more details.
Handlers
Various support elements for configuring gin
handlers are described in the following sections.
See package handler
documentation for more details.
Simple Handlers
A small collection of simpler gin
handlers is provided in the handler
package.
These include:
Ping
handler to return a 200 "Pong!" response.Exit
handler to send aSIGINT
signal to the current process, thereby ending the service.
Handler Wrapper
The handler.Wrapper
mechanism can encapsulate an arbitrary object instantiating handler.CanServe
.
Once created, this object can return a gin.HandlerFunc
to be used when configuring gin
.
The main use is to pass in options to be invoked within the handler function thus returned,
which at this time is just a Cross-Origin Resource Sharing (CORS) flag.
Results
The handler.ErrorResult
function will return a generic error page.
Application Template
There is an executable template application in cmd/template/template.go
.
The template utilizes:
ginzero
to redirect allgin
messaging throughzerolog
,shutdown
to implement graceful shutdown, andhandler
for a few simple handlers (remove later)
This template is intended to be copied into another project as a starting point.
System Utility
Configuration
The system.Config
struct collects gin
configuration items in one place.
At the current time there is only Port
.
The Config.AddFlagsToSet()
method will configure a port
flag in the
specified flag.FlagSet
.