httpx

package
v0.0.0-...-aba061b Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: GPL-3.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(definitions HandlersDefinition) http.Handler

NewHandler is a constructor

func ReadRequest

func ReadRequest(w http.ResponseWriter, r *http.Request, req interface{}) error

func RunServer

func RunServer(ctx context.Context, serverURL string, httpHandler http.Handler, corsOpt *CORSOpt) error

RunServer execute http server

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, statusCode int, errs ...Error)

func WriteResponse

func WriteResponse(w http.ResponseWriter, statusCode int, body []byte)

Types

type CORSOpt

type CORSOpt struct {
	AllowedOrigins     []string
	AllowedMethods     []string
	AllowedHeaders     []string
	OptionsPassthrough bool
}

CORSOpt is a set of CORS options

type Error

type Error struct {
	// Code corresponds to the JSON schema field "code".
	Code ErrorCode `json:"code"`

	// Message corresponds to the JSON schema field "message".
	Message string `json:"message"`
}

type ErrorCode

type ErrorCode string
const ErrorCodeInvalidRequest ErrorCode = "invalid_request"

type ErrorResponseJson

type ErrorResponseJson struct {
	// Errors corresponds to the JSON schema field "errors".
	Errors []Error `json:"errors,omitempty"`
}

type HandlerDefinition

type HandlerDefinition struct {
	Endpoint, Method string
	HandlerFunc      http.HandlerFunc
}

HandlerDefinition used to declare endpoints and http handlers

type HandlersDefinition

type HandlersDefinition []HandlerDefinition

HandlersDefinition is self-described

Jump to

Keyboard shortcuts

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