web

package
v0.0.0-...-07d62d3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Context to use when logging
	Context = "WEBSERVER"

	// HeaderIpAddress to use to get the user's IP address
	HeaderIpAddress = `X-Forwarded-For`

	// HeaderCors is used to enable CORS without needing intermediating
	// proxy code
	HeaderCorsAllowOrigin = `Access-Control-Allow-Origin`

	// HeaderCorsAllowHeaders is also used to support permissive CORS
	HeaderCorsAllowHeaders = `Access-Control-Allow-Headers`

	// EnvHttpListenAddress to use to listen on
	EnvHttpListenAddress = `FLU_WEB_LISTEN_ADDR`
)
View Source
const StatusValidationFuncFailed = 403

StatusValidationFuncFailed is returned when the validation func returns a non-nil exit code!

Variables

This section is empty.

Functions

func AuthenticatedEndpoint

func AuthenticatedEndpoint(endpoint, headerName string, validateFunc func(string) error, handler HttpFunction)

AuthenticatedEndpoint listens using http.HandleFunc on a specific endpoint, with some overhead for logging and a pass to validate whether the connection should continue. Also enables CORS!

func Endpoint

func Endpoint(endpoint string, handler HttpFunction)

Endpoint adds some logging code to handle user requests. Also enables CORS!

func GetIpAddress

func GetIpAddress(r *http.Request) string

GetIpAddress from a request with HeaderIpAddress

func JsonEndpoint

func JsonEndpoint(endpoint string, handler func(http.ResponseWriter, *http.Request) interface{})

JsonEndpoint adds some logging code and marshals the return value of the handler and sends to the client. If the interface{} is nil, then nothing happens.

func Listen

func Listen()

Listen gets the listen address from the environment variable and runs ListenAndServe

Types

type HttpFunction

type HttpFunction func(http.ResponseWriter, *http.Request)

HttpFunction to destink function definitions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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