api

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrMsgUnauthorized = "Not authorized to access the requested resource"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API is the root API structure.

func New

func New(cfg config.API, srv *server.Server) (*API, error)

New creates a new API.

func (*API) RegisterRoute

func (a *API) RegisterRoute(method string, p string, handler http.HandlerFunc)

RegisterRoute registers a new handler at the given path.

func (*API) Run

func (a *API) Run()

Run starts the API server.

func (*API) ServeHTTP

func (a *API) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves the API requests.

type DebugHandler

type DebugHandler struct{}

DebugHandler exposes debug routes.

func (DebugHandler) Append

func (g DebugHandler) Append(router *mux.Router)

Append adds debug routes to the specified router.

type IPFilter

type IPFilter struct {
	// contains filtered or unexported fields
}

IPFilter implements a simple IP filter. It is configured with an access control list containing IP and CIDR addresses that are allowed to access the specified resource. If the list of allowed addresses is empty, any request is granted access and bypasses the filter without any restrictions.

func NewIPFilter

func NewIPFilter(whitelist string) (*IPFilter, error)

NewIPFilter creates a new IP filter.

func (*IPFilter) IsAllowed

func (f *IPFilter) IsAllowed(ip netip.Addr) bool

IsAllowed checks if the given IP is allowed.

func (*IPFilter) Wrap

func (f *IPFilter) Wrap(next http.HandlerFunc) http.HandlerFunc

Wrap wraps the specified handler with an IP filter. It filters the request based on the configured access control list and allows or blocks the request according to the original IP. If the list of allowed IPs is empty, any request bypasses the filter.

type VersionHandler

type VersionHandler struct{}

VersionHandler exposes version routes.

func (VersionHandler) Append

func (v VersionHandler) Append(router *mux.Router)

Append adds version routes to the specified router.

Jump to

Keyboard shortcuts

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