util

package
v0.0.0-...-54ff246 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2016 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserId = "2013011187"
)

Variables

View Source
var (
	Password = os.Getenv("thu_pass")
)

Functions

func AuthNeededHandler

func AuthNeededHandler(h http.Handler) http.Handler

func Error

func Error(rw http.ResponseWriter, err string, status int)

func ExpectDeepEqual

func ExpectDeepEqual(t *testing.T, actual, expected interface{}) bool

func ExpectStatus

func ExpectStatus(t *testing.T, actual, expected int) bool

func HeadersHandler

func HeadersHandler(h http.Handler) http.Handler

func JSON

func JSON(rw http.ResponseWriter, v interface{}, status int, err error)

func Language

func Language(req *http.Request) language.Tag

func NewFloat32

func NewFloat32(f float32) *float32

func NotFound

func NotFound(rw http.ResponseWriter, _ *http.Request)

func TrimmedTexts

func TrimmedTexts(s *goquery.Selection) []string

Types

type Client

type Client struct{ http.Client }

func (*Client) FileInfo

func (client *Client) FileInfo(url string, encoding encoding.Encoding) (filename string, size int, status int, errMsg error)

func (*Client) GetDocument

func (client *Client) GetDocument(url string) (doc *goquery.Document, errMsg error)

func (*Client) GetJSON

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

func (*Client) PostFormJSON

func (client *Client) PostFormJSON(url string, data url.Values, v interface{}) error

func (*Client) WithJar

func (client *Client) WithJar()

type Limiter

type Limiter struct {
	sync.Mutex
	Window    int64 // In seconds.
	RateLimit int
	Count     map[string]int
	Reset     int64
}

func NewLimiter

func NewLimiter(window int64, rate int) *Limiter

func (*Limiter) Handler

func (l *Limiter) Handler() func(http.Handler) http.Handler

func (*Limiter) Request

func (l *Limiter) Request(id string) (ok bool, remain int, reset int64)

type StatusGroup

type StatusGroup struct {
	sync.WaitGroup
	sync.Mutex
	Status int
	Err    error
}

func NewStatusGroup

func NewStatusGroup() *StatusGroup

func (*StatusGroup) Done

func (sg *StatusGroup) Done(statusPtr *int, errPtr *error)

func (*StatusGroup) Go

func (sg *StatusGroup) Go(f func(*int, *error))

func (*StatusGroup) Wait

func (sg *StatusGroup) Wait() (int, error)

Jump to

Keyboard shortcuts

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