Documentation
¶
Overview ¶
SPDX-FileCopyrightText: 2024 Paulo Almeida <almeidapaulopt@gmail.com> SPDX-License-Identifier: MIT
SPDX-FileCopyrightText: 2024 Paulo Almeida <almeidapaulopt@gmail.com> SPDX-License-Identifier: MIT
Index ¶
- Constants
- Variables
- func GetVersion() string
- func LoggerMiddleware(l zerolog.Logger, next http.Handler) http.Handler
- func NewLog() zerolog.Logger
- type HTTPServer
- func (a *HTTPServer) ErrorResponse(w http.ResponseWriter, _ *http.Request, span trace.Span, returnError string, ...)
- func (a *HTTPServer) Get(pattern string, handler http.Handler)
- func (a *HTTPServer) Handle(pattern string, handler http.Handler)
- func (a *HTTPServer) JSONResponse(w http.ResponseWriter, _ *http.Request, result interface{})
- func (a *HTTPServer) JSONResponseCode(w http.ResponseWriter, _ *http.Request, result interface{}, responseCode int)
- func (a *HTTPServer) Post(pattern string, handler http.Handler)
- func (a *HTTPServer) StartServer(s *http.Server) error
- func (a *HTTPServer) Use(mw Middleware)
- type Health
- type LogRecord
- type Middleware
Constants ¶
const ( Ready = 1 NotReady = 0 )
const ( AppName = "TSDProxy" AppAuthor = "Paulo Almeida <almeidapaulopt@gmail.com>" )
const ( // G112 (CWE-400): Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server (Confidence: LOW, Severity: MEDIUM. ReadHeaderTimeout = 5 * time.Second )
Variables ¶
var (
AppNameVersion = AppName + "-" + GetVersion()
)
Functions ¶
func GetVersion ¶
func GetVersion() string
func LoggerMiddleware ¶ added in v1.0.0
LoggerMiddleware is a middleware function that logs incoming HTTP requests.
Types ¶
type HTTPServer ¶
type HTTPServer struct { Log zerolog.Logger Mux *http.ServeMux // contains filtered or unexported fields }
HTTPServer struct to hold our routes and middleware.
func NewHTTPServer ¶
func NewHTTPServer(log zerolog.Logger) *HTTPServer
NewHTTPServer creates and returns a new App with an initialized ServeMux and middleware slice.
func (*HTTPServer) ErrorResponse ¶
func (a *HTTPServer) ErrorResponse(w http.ResponseWriter, _ *http.Request, span trace.Span, returnError string, code int)
func (*HTTPServer) Get ¶ added in v1.2.0
func (a *HTTPServer) Get(pattern string, handler http.Handler)
Get method add a GET handler
func (*HTTPServer) Handle ¶
func (a *HTTPServer) Handle(pattern string, handler http.Handler)
Handle registers a handler for a specific route, applying all middleware.
func (*HTTPServer) JSONResponse ¶
func (a *HTTPServer) JSONResponse(w http.ResponseWriter, _ *http.Request, result interface{})
func (*HTTPServer) JSONResponseCode ¶
func (a *HTTPServer) JSONResponseCode(w http.ResponseWriter, _ *http.Request, result interface{}, responseCode int)
func (*HTTPServer) Post ¶ added in v1.2.0
func (a *HTTPServer) Post(pattern string, handler http.Handler)
Post method add a POST handler
func (*HTTPServer) StartServer ¶
func (a *HTTPServer) StartServer(s *http.Server) error
StartServer starts a custom http server.
type Health ¶
type Health struct { HTTP *HTTPServer Log zerolog.Logger // contains filtered or unexported fields }
func NewHealthHandler ¶
func NewHealthHandler(http *HTTPServer, log zerolog.Logger) *Health
func (*Health) Ready ¶
func (h *Health) Ready() http.HandlerFunc
func (*Health) SetNotReady ¶
func (h *Health) SetNotReady()
type LogRecord ¶
type LogRecord struct { http.ResponseWriter // contains filtered or unexported fields }
LogRecord warps a http.ResponseWriter and records the status.
func (*LogRecord) WriteHeader ¶
WriteHeader overrides ResponseWriter.WriteHeader to keep track of the response code.