Split app into subpages, persist ingame time, and add 14-month dashboard calendar
This commit is contained in:
49
cmd/server/helpers.go
Normal file
49
cmd/server/helpers.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func mustInt(v string, fallback int) int {
|
||||
n, err := strconv.Atoi(strings.TrimSpace(v))
|
||||
if err != nil {
|
||||
return fallback
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func mustInt64(v string, fallback int64) int64 {
|
||||
n, err := strconv.ParseInt(strings.TrimSpace(v), 10, 64)
|
||||
if err != nil {
|
||||
return fallback
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func parseInt64List(values []string) ([]int64, error) {
|
||||
var out []int64
|
||||
for _, v := range values {
|
||||
id := mustInt64(v, 0)
|
||||
if id <= 0 {
|
||||
return nil, errors.New("invalid id")
|
||||
}
|
||||
out = append(out, id)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func placeholders(n int) string {
|
||||
parts := make([]string, 0, n)
|
||||
for i := 0; i < n; i++ {
|
||||
parts = append(parts, "?")
|
||||
}
|
||||
return strings.Join(parts, ",")
|
||||
}
|
||||
|
||||
func redirectWithMessage(w http.ResponseWriter, r *http.Request, path, key, val string) {
|
||||
http.Redirect(w, r, path+"?"+key+"="+url.QueryEscape(val), http.StatusSeeOther)
|
||||
}
|
||||
Reference in New Issue
Block a user