helpers

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetEnv

func GetEnv(key, fallback string) string

func GetLocalHostname

func GetLocalHostname() string

func GetLocalIP

func GetLocalIP() string

func GetLocalUsername

func GetLocalUsername() string

func HttpHelperRemovePort

func HttpHelperRemovePort(s string) string

if r.RemoteAddr contains port, remove it like: "127.0.0.1:53956" => "127.0.0.1"

func HttpHelperReturnClientIp

func HttpHelperReturnClientIp(r *http.Request) string

func HttpHelperReturnReferer

func HttpHelperReturnReferer(r *http.Request) string

func HttpJsonResponse

func HttpJsonResponse(w http.ResponseWriter, r *http.Request, httpStatusCode int, httpResponse interface{})

func HttpLog

func HttpLog(w http.ResponseWriter, r *http.Request, httpStatusCode int)

Mimic NGINX Log Format

func HttpRoute404

func HttpRoute404(w http.ResponseWriter, r *http.Request)

func HttpRouteDefault

func HttpRouteDefault(w http.ResponseWriter, r *http.Request)

func HttpRoutePing

func HttpRoutePing(w http.ResponseWriter, r *http.Request)

not using jsonResponse, but writing byte style. Doing this as an example

func IsStringInSlice

func IsStringInSlice(a string, list []string) bool

func PrettyPrintStruct

func PrettyPrintStruct(i interface{}) string

consume like: fmt.Println(helpers.PrettyPrintStruct(response))

func RandomBool

func RandomBool() bool

func RandomNumberInRange

func RandomNumberInRange(minNum int, maxNum int) int

func RestGetUrl

func RestGetUrl(url string, expectedReturnCode int) map[string]interface{}

Takes URL and returns JSON Params (string) of URL Params (int) of expected HTTP Response Code Returns (map[string]interface{}) of JSON response

func RestJsonMarshalData

func RestJsonMarshalData(payload map[string]interface{}) []byte

func RestJsonUnmarshalData

func RestJsonUnmarshalData(response []byte) map[string]interface{}

func RestPerformGetUrl

func RestPerformGetUrl(url string) *http.Response

func RestPerformPostUrl

func RestPerformPostUrl(url string, jsonData []byte) *http.Response

func RestPostUrl

func RestPostUrl(url string, payload map[string]interface{}, expectedReturnCode int) map[string]interface{}

func RestResponseBody

func RestResponseBody(resp *http.Response) []byte

func RestResponseCodeAnalysis

func RestResponseCodeAnalysis(resp *http.Response, expectedReturnCode int) bool

Get HTTP response Status Code

func RestResponseGetHeader

func RestResponseGetHeader(resp *http.Response, name string) (string, error)

Get specific Response Header

func RestResponseReturnCode

func RestResponseReturnCode(resp *http.Response) int

Get HTTP response Status Code

func StringToInt

func StringToInt(theString string, quit bool) int

Takes a string and returns an int. Params (string) to convert, (bool) if conversion fails, should program exit Returns (int) of string

func TimeNow

func TimeNow() string

Types

This section is empty.

Jump to

Keyboard shortcuts

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