gorest

package module
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: MIT Imports: 12 Imported by: 6

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.

TODO

Create render package to replace view, providing both JSON and HTML rendering.

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 {
	Page  int64 `query:"page" schema:"page" json:"page"`          // Which page is requesting data.
	Limit int64 `query:"per_page" schema:"per_page" json:"limit"` // How many items per page.
}

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) Normalize added in v0.4.0

func (p *Pagination) Normalize()

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.

type SemVer added in v0.5.2

type SemVer struct {
	Major int
	Minor int
	Patch int
}

SemVer represents a parsed value of semantic version string.

func ParseSemVer added in v0.5.2

func ParseSemVer(v string) SemVer

ParseSemVer parsed a string into to SemVer

func (SemVer) Compare added in v0.5.2

func (s SemVer) Compare(other SemVer) int

Compare compares two semantic versions. Returns negative number if s should come before (is smaller) other; 0 if the two are equal; Positive number if s should come after (is larger than) other.

func (SemVer) Equal added in v0.5.2

func (s SemVer) Equal(other SemVer) bool

Equal tests if two semantic version string are the same.

func (SemVer) Larger added in v0.5.2

func (s SemVer) Larger(other SemVer) bool

Larger tests whether semantic version a is larger than b

func (SemVer) Smaller added in v0.5.2

func (s SemVer) Smaller(other SemVer) bool

Smaller tests whether semantic version a is smaller than b.

type StringSlice added in v0.5.2

type StringSlice []string

StringSlice implments Scanner and Valuer interface for a slice of strings.

func (*StringSlice) Scan added in v0.5.2

func (x *StringSlice) Scan(src interface{}) error

Scan retrieves a comma-separated string value from SQL to a Go string slice.

func (StringSlice) Value added in v0.5.2

func (x StringSlice) Value() (driver.Value, error)

Value turns a Go string slice to a comma-sparated string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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