Skip to content

URL parameters helper for Сhi Router

License

Notifications You must be signed in to change notification settings

zak905/chi-param

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chi-param

URL parameters helper for Сhi Router.

Go Report Card License MIT Go Doc Release

Install

go get -u github.com/oceanicdev/chi-param

And then import the package in your code:

import "github.com/oceanicdev/chi-param"

Example

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 https://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))
}

License

Copyright (c) 2018-present Andrey Mak

Licensed under MIT License

About

URL parameters helper for Сhi Router

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%