utils

package
v0.0.0-...-79855c9 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func Capitalize

func Capitalize(word string) string

capitalize capitalizes the first letter of a word

func ContainedIn

func ContainedIn(value string, list []string) bool

containedIn checks if a value in a list of a strings

func ContainsSubString

func ContainsSubString(value string, list []string) bool

containsSubString checks if substring exists

func DecodeKeyPairs

func DecodeKeyPairs(list []string) (map[string]string, error)

decodeKeyPairs converts a list of strings (key=pair) to a map

func DefaultTo

func DefaultTo(v, d string) string

defaultTo returns the value of the default

func DialAddress

func DialAddress(location *url.URL) string

dialAddress extracts the dial address from the url

func FileExists

func FileExists(filename string) bool

fileExists check if a file exists

func FindCookie

func FindCookie(name string, cookies []*http.Cookie) *http.Cookie

findCookie looks for a cookie in a list of cookies

func GenerateHmac

func GenerateHmac(req *http.Request, encKey string) (string, error)

func GetHashKey

func GetHashKey(token string) string

getHashKey returns a hash of the encodes jwt token

func GetRefreshTokenFromCookie

func GetRefreshTokenFromCookie(req *http.Request, cookieName string) (string, error)

GetRefreshTokenFromCookie returns the refresh token from the cookie if any

func GetRequestHostURL

func GetRequestHostURL(req *http.Request) string

getRequestHostURL returns the hostname from the request

func GetTokenInBearer

func GetTokenInBearer(req *http.Request) (string, error)

getTokenInBearer retrieves a access token from the authorization header

func GetTokenInCookie

func GetTokenInCookie(req *http.Request, name string) (string, error)

getTokenInCookie retrieves the access token from the request cookies

func GetTokenInHeader

func GetTokenInHeader(req *http.Request, headerName string) (string, error)

getTokenInHeader retrieves a token from the header

func GetTokenInRequest

func GetTokenInRequest(
	req *http.Request,
	name string,
	skipAuthorizationHeaderIdentity bool,
	tokenHeader string,
) (string, bool, error)

getTokenInRequest returns the token from the http request

func GetWithin

func GetWithin(expires time.Time, within float64) time.Duration

getWithin calculates a duration of x percent of the time period, i.e. something expires in 1 hours, get me a duration within 80%

func HasAccess

func HasAccess(need, have []string, all bool) bool

hasAccess checks we have all or any of the needed items in the list

func IsUpgradedConnection

func IsUpgradedConnection(req *http.Request) bool

isUpgradedConnection checks to see if the request is requesting

func IsValidHTTPMethod

func IsValidHTTPMethod(method string) bool

IsValidHTTPMethod ensure this is a valid http method type

func MergeMaps

func MergeMaps(dest, source map[string]string) map[string]string

mergeMaps simples copies the keys from source to destination

func PrintError

func PrintError(message string, args ...interface{}) cli.ExitCoder

printError display the command line usage and error

func RealIP

func RealIP(req *http.Request) string

realIP retrieves the client ip address from a http request

func ToHeader

func ToHeader(v string) string

toHeader is a helper method to play nice in the headers

func TransferBytes

func TransferBytes(src io.Reader, dest io.Writer, wg *sync.WaitGroup) (int64, error)

transferBytes transfers bytes between the sink and source

func TryDialEndpoint

func TryDialEndpoint(location *url.URL) (net.Conn, error)

tryDialEndpoint dials the upstream endpoint via plain HTTP

func TryUpdateConnection

func TryUpdateConnection(req *http.Request, writer http.ResponseWriter, endpoint *url.URL) error

tryUpdateConnection attempt to upgrade the connection to a http pdy stream

Types

This section is empty.

Jump to

Keyboard shortcuts

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