예제 #1
0
func Handler() *mux.Router {
	m := router.API()
	m.Get(router.Post).Handler(handler(servePost))
	m.Get(router.SubmitPost).Handler(handler(serveSubmitPost))
	m.Get(router.Posts).Handler(handler(servePosts))
	return m
}
예제 #2
0
	return (o.PageOrDefault() - 1) * o.PerPageOrDefault()
}

func (o ListOptions) PerPageOrDefault() int {
	if o.PerPage <= 0 {
		return DefaultPerPage
	}
	return o.PerPage
}

// DefaultPerPage is the default number of items to return per page in
// a paginated result set.
const DefaultPerPage = 10

// apiRouter is used to generate URLs for thesrc's HTTP API.
var apiRouter = router.API()

// url generates the URL to the named thesrc API endpoint, using the
// specified route variables and query options.
func (c *Client) url(apiRouteName string, routeVars map[string]string, opt interface{}) (*url.URL, error) {
	route := apiRouter.Get(apiRouteName)
	if route == nil {
		return nil, fmt.Errorf("no API route named %q", apiRouteName)
	}

	routeVarsList := make([]string, 2*len(routeVars))
	i := 0
	for name, val := range routeVars {
		routeVarsList[i*2] = name
		routeVarsList[i*2+1] = val
		i++