You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

50 lines
892 B

// Copyright 2018 Lars Hoogestraat
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package handler
import (
"net/http"
"strconv"
"git.hoogi.eu/snafu/go-blog/logger"
"github.com/gorilla/mux"
)
func getVar(r *http.Request, key string) string {
v := mux.Vars(r)[key]
if len(v) > 0 {
return v
}
return r.Header.Get("X-Unit-Testing-Value-" + key)
}
func parseInt(v string) (int, error) {
i, err := strconv.Atoi(v)
if err != nil {
return -1, err
}
return i, nil
}
func getPageParam(r *http.Request) int {
var page = 1
if len(getVar(r, "page")) > 0 {
i, err := strconv.Atoi(getVar(r, "page"))
if err != nil {
logger.Log.Errorf("could not parse page number %v\n", err)
return 1
}
page = i
}
return page
}
func convertCheckbox(r *http.Request, name string) bool {
return r.FormValue(name) == "on"
}