utils

package
v0.0.0-...-20679a4 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Empty is empty/blank string.
	Empty = ""
)

Variables

This section is empty.

Functions

func AppendError

func AppendError(value string, err error) string

AppendError appends the error message to the value.

func BuildHTTPError

func BuildHTTPError(err error, msg string) *echo.HTTPError

BuildHTTPError converts error object to http error by checking internal http status code.

func CheckLocalhostURL

func CheckLocalhostURL(u string) error

CheckLocalhostURL validates the url. The url must be a valid and localhost url.

func ClientWithJSON

func ClientWithJSON(j string, code int) *http.Client

ClientWithJSON creates a new http client. It has an internal transport function which build custom response with the specified json and http status code. It is useful for testing http calls.

func ClientWithToken

func ClientWithToken(accessToken string) *http.Client

ClientWithToken creates a new http client and injects the access token in the authorization header.

func Error

func Error(value string, inner error) error

Error creates a new error by injecting/formatting the inner error.

func GetStatusCode

func GetStatusCode(err error) int

GetStatusCode extracts http status code from the error object.

func GetValueString

func GetValueString(value, def string) string

GetValueString returns the specified value, but if the specified value is empty, it returns the default value.

func Sanitize

func Sanitize(m map[string]string) map[string]string

Sanitize removes the leading and trailing spaces from each map items. If the map key contains only spaces, the key/value pair is removed from the map.

func ValidateStruct

func ValidateStruct(s interface{}, m map[string]string) error

ValidateStruct checks all validation rules on struct fields. It returns error on any validation failure.

Types

type TransportFunc

type TransportFunc func(*http.Request) (*http.Response, error)

TransportFunc is used to customize the http client's transport layer. User can inject a hook function to change the request and response params.

func (TransportFunc) RoundTrip

func (f TransportFunc) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip forwards the incoming http call to the used defined hook function.

Jump to

Keyboard shortcuts

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