httputil

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIHandler

func APIHandler(fn func(ctx context.Context, w http.ResponseWriter, r *http.Request) error) http.HandlerFunc

APIHandler transforms a handler func with a returning error into Go's http.Handler

func CheckClusterNoAuth

func CheckClusterNoAuth(next http.Handler) http.Handler

CheckClusterNoAuth pulls the cluster information out of the request, doing no auth{nz} checks.

func ClusterNameFromContext

func ClusterNameFromContext(ctx context.Context) string

ClusterNameFromContext returns the cluster name from a context. It panics if context doesn't have one.

func ContextWithClusterName

func ContextWithClusterName(ctx context.Context, clusterName string) context.Context

ContextWithOrgID returns a context with the given cluster name.

func Error

func Error(w http.ResponseWriter, r *http.Request, err error)

func ErrorTypeToHTTPCode

func ErrorTypeToHTTPCode(typ lfsb.ErrorType) int

func HTTPCodeToErrorType

func HTTPCodeToErrorType(code int) lfsb.ErrorType

func RenderResponse

func RenderResponse(w http.ResponseWriter, resp any) error

RenderResponse renders API response as JSON.

Types

type ErrorResponse

type ErrorResponse struct {
	Code  string   `json:"code"`
	Error string   `json:"error"`
	Pos   *ltx.Pos `json:"pos,omitempty"`
}

func (*ErrorResponse) Err

func (r *ErrorResponse) Err(statusCode int) error

Err returns an LFSC error from an error response.

Jump to

Keyboard shortcuts

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