Skip to content

Commit ea7eb68

Browse files
committed
feat: Adding status code choose in URL
Signed-off-by: Vincent Boutour <[email protected]>
1 parent 870f9e5 commit ea7eb68

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cmd/goweb/api.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"flag"
66
"net/http"
77
"os"
8+
"strconv"
89
"strings"
910

1011
"github.com/ViBiOh/goweb/pkg/delay"
@@ -65,7 +66,17 @@ func main() {
6566
dumpHandler := http.StripPrefix(dumpPath, dump.Handler())
6667
delayHandler := http.StripPrefix(delayPath, delay.Handler())
6768
rendererHandler := rendererApp.Handler(func(r *http.Request) (string, int, map[string]interface{}, error) {
68-
return "public", http.StatusTeapot, nil, nil
69+
status := http.StatusTeapot
70+
71+
if userStatus := r.URL.Query().Get("status"); len(userStatus) != 0 {
72+
if rawStatus, err := strconv.Atoi(userStatus); err != nil {
73+
logger.Error("unable to parse wanted status: %s", err)
74+
} else {
75+
status = rawStatus
76+
}
77+
}
78+
79+
return "public", status, nil, nil
6980
})
7081

7182
appHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)