gousuchi

package module
v2.0.0-...-b383d62 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 14 Imported by: 1

README

Chi(HTTP)-Integration for Go Universal Service Utilities

Full docu for go-gousu on https://github.com/indece-official/go-gousu

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AbstractController

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

func NewAbstractController

func NewAbstractController(
	log *logger.Log,
) *AbstractController

func (*AbstractController) GetLog

func (c *AbstractController) GetLog(r *http.Request) *logger.Log

func (*AbstractController) Health

func (c *AbstractController) Health() error

Health checks if the api server has thrown unresolvable internal errors

func (*AbstractController) Start

func (c *AbstractController) Start() error

Start starts the api server in a new go-func

func (*AbstractController) Stop

func (c *AbstractController) Stop() error

Stop currently does nothing

func (*AbstractController) UseHost

func (c *AbstractController) UseHost(host string)

func (*AbstractController) UsePort

func (c *AbstractController) UsePort(port int)

func (*AbstractController) UseRouter

func (c *AbstractController) UseRouter(router chi.Router)

func (*AbstractController) UseTlsConfig

func (c *AbstractController) UseTlsConfig(tlsConfig *tls.Config)

func (*AbstractController) WithExtra

func (c *AbstractController) WithExtra(r *http.Request, key string, value interface{}) *http.Request

func (*AbstractController) Wrap

type ContentType

type ContentType string
const (
	ContentTypeApplicationJSON        ContentType = "application/json"
	ContentTypeApplicationOctetStream ContentType = "application/octet-stream"
	ContentTypeApplicationPDF         ContentType = "application/pdf"
	ContentTypeTextPlain              ContentType = "text/plain"
	ContentTypeTextHTML               ContentType = "text/html"
	ContentTypeTextCSV                ContentType = "text/csv"
	ContentTypeImagePNG               ContentType = "image/png"
	ContentTypeImageJPEG              ContentType = "image/jpeg"
	ContentTypeImageBMP               ContentType = "image/bmp"
)

type HandlerFunction

type HandlerFunction func(w http.ResponseWriter, r *http.Request) IResponse

type IResponse

type IResponse interface {
	GetRequest() *http.Request
	Write(w http.ResponseWriter) IResponse
	Log(log *logger.Log)
}

func OptionalQueryParamBool

func OptionalQueryParamBool(request *http.Request, name string) (null.Bool, IResponse)

OptionalQueryParamBool loads a parameter from the url's query and parses it as bool

If the parameter is not empty and not a valid bool a BadRequest-Response is returned, else the response is nil. Accepted values are 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False

func OptionalQueryParamInt64

func OptionalQueryParamInt64(request *http.Request, name string) (null.Int, IResponse)

OptionalQueryParamInt64 loads a parameter from the url's query and parses it as int64

If the parameter is not empty and not a valid int64 a BadRequest-Response is returned, else the response is nil

func OptionalQueryParamString

func OptionalQueryParamString(request *http.Request, name string) (null.String, IResponse)

OptionalQueryParamString loads a parameter from the url's query

Response is always nil and only returned for compatiblity here

func OptionalURLParamBool

func OptionalURLParamBool(request *http.Request, name string) (null.Bool, IResponse)

OptionalURLParamBool loads a parameter from the url and parses it as bool

If the parameter is not empty and not a valid bool a BadRequest-Response is returned, else the response is nil. Accepted values are 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False

func OptionalURLParamInt64

func OptionalURLParamInt64(request *http.Request, name string) (null.Int, IResponse)

OptionalURLParamInt64 loads a parameter from the url and parses it as int64

If the parameter is not empty and not a valid int64 a BadRequest-Response is returned, else the response is nil

func OptionalURLParamString

func OptionalURLParamString(request *http.Request, name string) (null.String, IResponse)

OptionalURLParamString loads a parameter from the url

Response is always nil and only returned for compatiblity here

func QueryParamBool

func QueryParamBool(request *http.Request, name string) (bool, IResponse)

QueryParamBool loads a parameter from the url's query and parses it as bool

If the parameter is not a valid bool a BadRequest-Response is returned, else the response is nil. Accepted values are 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False

func QueryParamInt64

func QueryParamInt64(request *http.Request, name string) (int64, IResponse)

QueryParamInt64 loads a parameter from the url's query and parses it as int64

If the parameter is not a valid int64 a BadRequest-Response is returned, else the response is nil

func QueryParamString

func QueryParamString(request *http.Request, name string) (string, IResponse)

QueryParamString loads a parameter from the url's query

If the parameter is empty a BadRequest-Response is returned, else the response is nil

func URLParamBool

func URLParamBool(request *http.Request, name string) (bool, IResponse)

URLParamBool loads a parameter from the url and parses it as bool

If the parameter is not a valid bool a BadRequest-Response is returned, else the response is nil. Accepted values are 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False

func URLParamInt64

func URLParamInt64(request *http.Request, name string) (int64, IResponse)

URLParamInt64 loads a parameter from the url and parses it as int64

If the parameter is not a valid int64 a BadRequest-Response is returned, else the response is nil

func URLParamInt64Slice

func URLParamInt64Slice(request *http.Request, name string) ([]int64, IResponse)

URLParamInt64Slice loads a parameter from the url and parses it as a comma-separated list of int64

If the parameter is not a valid int64 a BadRequest-Response is returned, else the response is nil

func URLParamString

func URLParamString(request *http.Request, name string) (string, IResponse)

URLParamString loads a parameter from the url

If the parameter empty a BadRequest-Response is returned, else the response is nil

type Response

type Response struct {
	Request         *http.Request
	StatusCode      int
	Header          http.Header
	ContentType     ContentType
	Body            []byte
	BodyReader      io.Reader
	DetailedMessage string
	DisableLogging  bool
	// contains filtered or unexported fields
}

func HTML

func HTML(request *http.Request, body string) *Response

HTML creates a new RestResponse of type text/html

func JSON

func JSON(request *http.Request, obj interface{}) *Response

JSON creates a new RestResponse of type application/json

func NewResponse

func NewResponse(
	request *http.Request,
	statusCode int,
	contentType ContentType,
	body []byte,
) *Response

func NewStreamResponse

func NewStreamResponse(
	request *http.Request,
	statusCode int,
	contentType ContentType,
	bodyReader io.Reader,
) *Response

func Text

func Text(request *http.Request, body string) *Response

Text creates a new RestResponse of type text/plain

func (*Response) GetRequest

func (r *Response) GetRequest() *http.Request

func (*Response) Log

func (r *Response) Log(log *logger.Log)

func (*Response) WithDetailedMessage

func (r *Response) WithDetailedMessage(detailedMessage string, args ...interface{}) *Response

func (*Response) WithHeader

func (r *Response) WithHeader(key string, value string) *Response

func (*Response) WithHeaders

func (r *Response) WithHeaders(headers http.Header) *Response

func (*Response) WithStatusCode

func (r *Response) WithStatusCode(statusCode int) *Response

func (*Response) WithoutLogging

func (r *Response) WithoutLogging() *Response

func (*Response) Write

func (r *Response) Write(w http.ResponseWriter) IResponse

type ResponseError

type ResponseError struct {
	Request       *http.Request
	StatusCode    int
	PublicMessage string
	DetailedError error
}

func BadRequest

func BadRequest(request *http.Request, detailedMessage string, args ...interface{}) *ResponseError

func Forbidden

func Forbidden(request *http.Request, detailedMessage string, args ...interface{}) *ResponseError

func InternalServerError

func InternalServerError(request *http.Request, detailedMessage string, args ...interface{}) *ResponseError

func NotFound

func NotFound(request *http.Request, detailedMessage string, args ...interface{}) *ResponseError

func Unauthorized

func Unauthorized(request *http.Request, detailedMessage string, args ...interface{}) *ResponseError

func (*ResponseError) GetRequest

func (r *ResponseError) GetRequest() *http.Request

func (*ResponseError) Log

func (r *ResponseError) Log(log *logger.Log)

func (*ResponseError) Write

Jump to

Keyboard shortcuts

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