http

package
v0.0.0-...-7f33b96 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeFilesGroupsMapRequest

func DecodeFilesGroupsMapRequest(w http.ResponseWriter, r *http.Request) (maps.FilesGroupsMap, int)

DecodeFilesGroupsMapRequest decodes the api request into a slice responds with decode error if occurs status

0 => ok || status 1 => error

func DecodeStringRequest

func DecodeStringRequest(w http.ResponseWriter, r *http.Request, t *string) (*string, int)

DecodeStringRequest decodes the api request into the passed slice defers request.body.close responds with decode error if occurs status 0 => ok || status 1 => error

func DecodeStringsRequest

func DecodeStringsRequest(w http.ResponseWriter, r *http.Request, t []string) ([]string, int)

DecodeStringsRequest decodes the api request into the passed slice responds with decode error if occurs status 0 => ok || status 1 => error

func DecodeTagMediaMapRequest

func DecodeTagMediaMapRequest(w http.ResponseWriter, r *http.Request) (models.TagMediaMap, int)

DecodeTagMediaMapRequest decodes the api request into the passed slice responds with decode error if occurs status 0 => ok || status 1 => error

func GenerateHTTPClient

func GenerateHTTPClient(caCert string, insecure bool) (*http.Client, *tls.Config)

GenerateHTTPClient parses the passed cert and adds it to the certpool of a custom http client. if insecure enabled, it skips cert validation.

func GetUsernameFromHeader

func GetUsernameFromHeader(w http.ResponseWriter) string

GetUsernameFromHeader returns the "user" header value

func ParseBody

func ParseBody(body io.ReadCloser, logfields log.Fields) (string, int)

ParseBody parses the passed readcloser to a string

0 -> ok || 1 -> could not parse body

func ParsePathID

func ParsePathID(w http.ResponseWriter, r *http.Request, identifier string) primitive.ObjectID

ParsePathID parses the id from the route and returns it returns primitive.NilObjectID if an error occured sends a respond if an error occured

func ParsePathString

func ParsePathString(w http.ResponseWriter, r *http.Request, key string) (string, int)

ParsePathString parses the string value from the route and returns it stats 0 -> ok || status 1 -> error

func ParseQueryBool

func ParseQueryBool(w http.ResponseWriter, r *http.Request, key string, optional bool) (bool, int)

ParseQueryBool parses the string value from the route and converts it into bool. If Optional true and value not set, it defaults to false 0 -> ok 1 -> could not parse string 2 -> could not convert to bool

func ParseQueryString

func ParseQueryString(w http.ResponseWriter, r *http.Request, key string, optional bool) (string, int)

ParseQueryString parses the string value from the route and returns it stats 0 -> ok status 1 -> error

func ReadCookie

func ReadCookie(r *http.Request, title string) string

ReadCookie reads the stoken cookie from the request and returns the value

func RespondWithError

func RespondWithError(w http.ResponseWriter, code int, message string)

RespondWithError Creates an error payload and adds the error message to be returned

func RespondWithJSON

func RespondWithJSON(w http.ResponseWriter, code int, payload interface{})

RespondWithJSON parses the passed payload and returns it with the specified code to the client

func SendRequest

func SendRequest(client *http.Client, method string, endpoint string, bearer string, content io.Reader, contentType string) (*http.Response, int, string)

SendRequest sends a request to an endpoint with specified content and type

Types

type ErrorJSON

type ErrorJSON struct {
	Error   string      `json:"error"`
	Payload interface{} `json:"payload"`
}

ErrorJSON is an return object to pass data as error response

Jump to

Keyboard shortcuts

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