URL parameters helper for Сhi Router.
go get -u github.com/oceanicdev/chi-param
And then import the package in your code:
import "github.com/oceanicdev/chi-param"
An example described below is one of the use cases.
package main
import (
"github.com/go-chi/chi"
"github.com/oceanicdev/chi-param"
"log"
"net/http"
)
func main() {
r := chi.NewMux()
r.Get("/{id}", func(w http.ResponseWriter, r *http.Request) {
// call http://localhost:8080/1?code=1&code2
id, _ := param.Int(r, "id") // returns value from path
code, _ := param.QueryInt(r, "code") // returns first value
codes, _ := param.QueryIntArray(r, "code") // returns all values
})
log.Fatal(http.ListenAndServe(":8080", r))
}
Copyright (c) 2018-present Andrey Mak
Licensed under MIT License