gorest

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2019 License: MIT Imports: 10 Imported by: 12

README

go-rest

Restful Utilities for Golang

NOTE: this is not a generic utility toolset for Golang. It is tailored to FTC restful API needs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseJSON

func ParseJSON(data io.ReadCloser, v interface{}) error

ParseJSON parses input data to struct

func RandomBase64

func RandomBase64(len int) (string, error)

RandomBase64 returns a base64 url encoded, unpadded string of random bytes. len is the length of bytes. It should be the multiple of 3 to get a string without padding: len * 8 / 6. 3 bytes -- 4 chars 6 bytes -- 8 chars 9 bytes -- 12 chars Wechat OAuth code has 32 characters, which is 24 bytes long; Wechat Access Token has 110 chars, which is 82.5 bytes? Wechat Refresh Token has 110 chars. OpenID has 28 chars, which is 21 bytes UnionID has 28 chars.

func RandomHex

func RandomHex(len int) (string, error)

RandomHex generates a random hexadecimal number of 2*len chars

func Stringify

func Stringify(v interface{}) ([]byte, error)

Stringify turn an interface into json string

Types

type Pagination added in v0.0.13

type Pagination struct {
	Limit int64 // How many items per page.
	// contains filtered or unexported fields
}

Pagination is used to calculate limit and offset parameter used int sql statement.

func GetPagination added in v0.0.13

func GetPagination(req *http.Request) Pagination

GetPagination extracts pagination information from query parameter

func NewPagination added in v0.0.13

func NewPagination(p, limit int64) Pagination

NewPagination creates a new Pagination instance. p is the page number, r is the rows to retrieve.

func (Pagination) Offset added in v0.0.13

func (p Pagination) Offset() int64

Offset calculate the offset for SQL.

type Param

type Param struct {
	// contains filtered or unexported fields
}

Param represents a pair of query parameter from URL.

func GetQueryParam

func GetQueryParam(req *http.Request, key string) Param

GetQueryParam get a pair of query parameter from URL.

func NewParam added in v0.0.14

func NewParam(key, value string) Param

NewParam creates a new instance of Param.

func (Param) ToBool

func (p Param) ToBool() (bool, error)

ToBool converts a query parameter to boolean value.

func (Param) ToInt added in v0.0.12

func (p Param) ToInt() (int64, error)

ToInt converts the value of a query parameter to int64

func (Param) ToString

func (p Param) ToString() (string, error)

ToString converts a query parameter to string value. Returns error for an empty value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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