util

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package util provides utilities which includes type conversion, HTTP shortcuts, string manipulcation & time parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPAbort

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

HTTPAbort writes headers and JSON body with corresponding message and code.

func HTTPRespond

func HTTPRespond(w http.ResponseWriter, data []byte)

HTTPRespond writes body with HTTP code of 200.

func HTTPRespondJSON

func HTTPRespondJSON(w http.ResponseWriter, message string, data interface{})

HTTPRespondJSON writes headers and JSON body.

func Int64FromString

func Int64FromString(s string) (int64, error)

Int64FromString interprets a string s in base 64 with bit size of 64.

func NormalizeString

func NormalizeString(str string) string

NormalizeString transforms an unicode string str to ASCII form.

func ParseDuration

func ParseDuration(str string) (duration time.Duration, err error)

ParseDuration parses a duration string.

func ReverseAny added in v0.1.1

func ReverseAny(s interface{})

ReverseAny takes a slice of anything and reverse it.

Types

type HTTPError

type HTTPError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

HTTPError represents a response of an error with code and message.

type HTTPResponse

type HTTPResponse struct {
	HTTPError `json:",inline"`
	Data      interface{} `json:"data"`
}

HTTPResponse represents a response with data and error.

Jump to

Keyboard shortcuts

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