kcd
  • KCD ? What is that
  • Getting started
  • Handler
    • The magic behind kcd.Handler
    • How to use kcd.Handler
  • concepts
    • Handler
    • Input
    • Output
    • Hooks
    • Extractors
  • Input
    • Supported field types
    • Bind from body json
    • Bind path parameter
    • Bind query parameter
    • Bind context values
    • Bind header values
    • Default value
    • Validation
    • Exploder for slices
    • Nested fields and path system
    • Custom unmarshal (json, binary, text)
  • output
    • Returning JSON response
    • Errors
      • Throw special http status code
  • hooks & extractors
    • Override a default hook
    • Error hook
    • Render hook
    • Bind hook
    • Validate hook
    • Log hook
    • String extractor
    • Value extractor
  • Real world use case
    • Pagination
    • Conditionally render your outputs
  • Compatible with
    • Compatible with ?
    • Compatible with chi
    • Compatible with gin
    • Compatible with gorilla/mux
    • Compatible with echo
    • Compatible with the standard library
Powered by GitBook
On this page

Was this helpful?

  1. Input

Bind query parameter

package main

import (
	"fmt"
	"net/http"

	"github.com/go-chi/chi"

	"github.com/alexisvisco/kcd"
)

func main() {
	r := chi.NewRouter()
	r.Post("/", kcd.Handler(YourHttpHandler, http.StatusOK))
	_ = http.ListenAndServe(":3000", r)
}

type CreateCustomerInput struct {
	Number int      `query:"number"`
	Names  []string `query:"name"`
}

func YourHttpHandler(in *CreateCustomerInput) (string, error) {
	fmt.Printf("%+v", in)

	return fmt.Sprintf("%v ; %v", in.Number, in.Names), nil
}

// Test it : curl -XPOST 'localhost:3000/?number=3&name=vincent&name=remi'
PreviousBind path parameterNextBind context values

Last updated 4 years ago

Was this helpful?