6b5f8a6b1d
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
34 lines
715 B
Go
34 lines
715 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
func handleFractionOpt(name string, setter func(int)) http.HandlerFunc {
|
|
return func(rw http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodPost {
|
|
http.Error(rw, "only POST allowed", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
if err := r.ParseForm(); err != nil {
|
|
http.Error(rw, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
asfr := r.Form.Get("x")
|
|
if len(asfr) == 0 {
|
|
http.Error(rw, "parameter 'x' must be set", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
fr, err := strconv.Atoi(asfr)
|
|
if err != nil {
|
|
http.Error(rw, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
log.Infof("setting %s to %d", name, fr)
|
|
setter(fr)
|
|
}
|
|
}
|