core

package
v1.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2025 License: MIT Imports: 16 Imported by: 0

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

View Source
const (
	Ready    = 1
	NotReady = 0
)
View Source
const (
	AppName   = "TSDProxy"
	AppAuthor = "Paulo Almeida <almeidapaulopt@gmail.com>"
)
View Source
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

View Source
var (
	AppNameVersion = AppName + "-" + GetVersion()
)

Functions

func GetVersion

func GetVersion() string

func LoggerMiddleware added in v1.0.0

func LoggerMiddleware(l zerolog.Logger, next http.Handler) http.Handler

LoggerMiddleware is a middleware function that logs incoming HTTP requests.

func NewLog

func NewLog() zerolog.Logger

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.

func (*HTTPServer) Use

func (a *HTTPServer) Use(mw Middleware)

Use adds middleware to the chain.

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) AddRoutes

func (h *Health) AddRoutes()

func (*Health) Ready

func (h *Health) Ready() http.HandlerFunc

func (*Health) SetNotReady

func (h *Health) SetNotReady()

func (*Health) SetReady

func (h *Health) SetReady()

type LogRecord

type LogRecord struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

LogRecord warps a http.ResponseWriter and records the status.

func (*LogRecord) Hijack added in v0.3.2

func (r *LogRecord) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*LogRecord) Write

func (r *LogRecord) Write(data []byte) (int, error)

func (*LogRecord) WriteHeader

func (r *LogRecord) WriteHeader(status int)

WriteHeader overrides ResponseWriter.WriteHeader to keep track of the response code.

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware type as before.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL