common

package module
v0.0.0-...-d36a87a Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2015 License: Apache-2.0 Imports: 15 Imported by: 0

README

common

go common

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(val bool, err error)

Assert will panic with err if val is true.

func AssertFunc

func AssertFunc(val bool, fn func())

AssertFunc will call fn if val is true.

func FilterHandler

func FilterHandler(filter Filter, handler http.Handler) http.Handler

FilterHandler returns a new Handler which filters request before the Handler.

func GetJSON

func GetJSON(url string, v interface{}) error

func Handle

func Handle(pattern string, handler http.Handler, filters ...Filter)

Handle is a easy way to call http.Handle function.

func HandleFunc

func HandleFunc(pattern string, hf func(http.ResponseWriter, *http.Request), filters ...Filter)

HandleFunc is a easy way to call http.HandleFunc function.

func Handler

func Handler(handler http.Handler, filters ...Filter) http.Handler

Handler combine all Filters and the Handler into a new Handler which contains these Filters and calls Handler finally.

func HandlerFunc

func HandlerFunc(hf func(http.ResponseWriter, *http.Request), filters ...Filter) http.Handler

Handler combine all Filters and the HandlerFunc into a new Handler which contains these Filters and calls Handler finally.

func Hash

func Hash(h hash.Hash, r io.Reader) ([]byte, int64, error)

Hash computes the content from reader by the provided hash function and return the checksum, content length, and error.

func HashFile

func HashFile(h hash.Hash, name string) ([]byte, int64, error)

Hash computes the content from file by the provided hash function and return the checksum, content length, and error.

func MD5

func MD5(r io.Reader) ([]byte, int64, error)

MD5 computes the md5 checksum of the content of r

func MD5File

func MD5File(name string) ([]byte, int64, error)

MD5 computes the md5 checksum of file

func ParseJSON

func ParseJSON(req *http.Request, v interface{}) error

ParseJSON parses request body into v as json format.

func ParseXML

func ParseXML(req *http.Request, v interface{}) error

ParseXML parses request body into v as xml format.

func PostJSON

func PostJSON(url string, v interface{}) (*http.Response, error)

PostJSON sends post request to the url with v in json format

func PostXML

func PostXML(url string, v interface{}) (*http.Response, error)

PostXML sends post request to the url with v in xml format

func Serve

func Serve(s Service)

Serve starts a service, and stops it if recieve INT or TERM signal.

func Transform

func Transform(src string) (string, error)

Transform GBK string to UTF-8 string.

Types

type Filter

type Filter interface {
	Filter(http.ResponseWriter, *http.Request, http.Handler)
}

Filter processes request before handler.

func Combine2Filters

func Combine2Filters(first Filter, second Filter) Filter

Combine2Filters combines 2 Filters into a single Filter.

func CombineFilters

func CombineFilters(filters ...Filter) Filter

CombineFilters combines multi Filters into a single Filter.

type FilterFunc

type FilterFunc func(http.ResponseWriter, *http.Request, http.Handler)

FilterFunc is a function as a Filter.

func (FilterFunc) Filter

func (ff FilterFunc) Filter(w http.ResponseWriter, r *http.Request, next http.Handler)

Filter implements Filter interface.

type MutexWrapper

type MutexWrapper struct {
	sync.Mutex
}

func (*MutexWrapper) Wrap

func (wrapper *MutexWrapper) Wrap(fn func())

type Queue

type Queue interface {
	// contains filtered or unexported methods
}

func NewQueue

func NewQueue() Queue

type RWMutexWrapper

type RWMutexWrapper struct {
	sync.RWMutex
}

func (*RWMutexWrapper) RWrap

func (wrapper *RWMutexWrapper) RWrap(fn func())

func (*RWMutexWrapper) Wrap

func (wrapper *RWMutexWrapper) Wrap(fn func())

type Service

type Service interface {
	Name() string
	Start() error
	Stop() error
}

Service interface

type Stack

type Stack interface {
	// contains filtered or unexported methods
}

func NewStack

func NewStack() Stack

type WaitGroupWrapper

type WaitGroupWrapper struct {
	sync.WaitGroup
}

func (*WaitGroupWrapper) Wrap

func (wrapper *WaitGroupWrapper) Wrap(fn func())

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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