Documentation
¶
Overview ¶
Package restapi provides a lightweight HTTP/HTTPS server built on Gin with optional multi-address listening and helper utilities.
Index ¶
- Variables
- func CleanupGeneratedTLSFiles()
- func ClientIP(c *gin.Context) string
- func DisablePing()
- func RegisterRouters(registrars ...func(r *gin.Engine))
- func ShutdownHttpServer() error
- func ShutdownHttpsServer() error
- func StartHttpServer()
- func StartHttpsServer(certFile, keyFile string, autoSelfSigned bool)
Constants ¶
This section is empty.
Variables ¶
var ( // Legacy single-address configuration (still supported) ListeningAddress = "0.0.0.0:5555" HTTPSListeningAddress = "0.0.0.0:5556" // New: optional plural address config; if non-empty, takes precedence over the single address ListeningAddresses []string HTTPSListeningAddresses []string )
httpApp is the instance of the Gin Engine used for HTTP routing and handling.
httpServer represents the HTTP server that will serve requests over the network.
ListeningAddress is the address and port the server listens on for incoming HTTP connections.
Functions ¶
func CleanupGeneratedTLSFiles ¶ added in v0.2.1
func CleanupGeneratedTLSFiles()
CleanupGeneratedTLSFiles removes any self-signed cert/key files generated by StartHttpsServer. Intended for applications to call (e.g., via defer) if they want to ensure cleanup even without calling ShutdownHttpsServer.
func ClientIP ¶
ClientIP retrieves the client IP address from the request context. It checks the "X-Forwarded-For" header first and returns its value if present; otherwise, it falls back to using c.ClientIP().
func DisablePing ¶
func DisablePing()
DisablePing sets the internal `disablePing` variable to true, effectively disabling the ping functionality.
func RegisterRouters ¶
RegisterRouters registers multiple router configurations to the HTTP application engine. It accepts a variadic number of functions, each receiving the *gin.Engine instance for adding routes and middleware.
func ShutdownHttpServer ¶
func ShutdownHttpServer() error
ShutdownHttpServer gracefully shuts down all running HTTP servers. Returns the first error encountered (if any).
func ShutdownHttpsServer ¶ added in v0.2.1
func ShutdownHttpsServer() error
ShutdownHttpsServer gracefully shuts down all running HTTPS servers and cleans up any generated cert/key files. Returns the first error encountered (if any).
func StartHttpServer ¶
func StartHttpServer()
StartHttpServer initializes and starts one or more HTTP servers at the configured listening addresses. If `ListeningAddresses` is non-empty, a server is started for each address; otherwise, the legacy single `ListeningAddress` is used. Servers run in separate goroutines for non-blocking operation.
func StartHttpsServer ¶ added in v0.2.1
StartHttpsServer initializes and starts one or more HTTPS servers with TLS using the provided certificate and key files. If `HTTPSListeningAddresses` is non-empty, a server is started for each address; otherwise, the legacy single `HTTPSListeningAddress` is used. Servers run asynchronously and log startup/errors.
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package middlewares contains Gin HTTP middlewares used by the restapi server (CORS, logging, no-cache).
|
Package middlewares contains Gin HTTP middlewares used by the restapi server (CORS, logging, no-cache). |
|
Package restresponse defines response codes and helpers for consistent JSON API responses.
|
Package restresponse defines response codes and helpers for consistent JSON API responses. |