- Notifications
You must be signed in to change notification settings - Fork2
KCD lets you focus on what matters: coding.
License
NotificationsYou must be signed in to change notification settings
alexisvisco/kcd
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
KCD is a grandiose REST helper that wrap your shiny handler into a classic http handler. It manages all you want forbuilding REST services.
This library isopinionated by default butcustomizable which mean it uses some other libraries like Chi,Logrus... KCD is modular so each pieces of the code that rely on a specific library can be changed.
- Demo simple
- Demo standard http handler
- Bind query parameters
- Bind path parameters
- Bind json body
- Bind context value
- Set default value
- Split string with exploder tag
- Nested struct
- Validation
- Errors
- Real world example: pagination
package mainimport ("fmt""net/http""github.com/go-chi/chi""github.com/go-chi/chi/middleware""github.com/alexisvisco/kcd")funcmain() {r:=chi.NewRouter()r.Use(middleware.RequestID)// You can configure kcd with kcd.Configr.Get("/{name}",kcd.Handler(YourHttpHandler,http.StatusOK))// ^ Here the magic happen this is the only thing you need// to do. Adding kcd.Handler(your handler)_=http.ListenAndServe(":3000",r)}// CreateCustomerInput is an example of input for an http request.typeCreateCustomerInputstruct {Namestring`path:"name"`// you can extract value from: 'path', 'query', 'header', 'ctx'Emails []string`query:"emails" exploder:","`// exploder split value with the characters specifiedSubjectstring`json:"body"`// it also works with json body}// CreateCustomerOutput is the output type of the http request.typeCreateCustomerOutputstruct {Namestring`json:"name"`}// YourHttpHandler is your http handler but in a shiny version.// You can add *http.ResponseWriter or http.Request in params if you want.funcYourHttpHandler(in*CreateCustomerInput) (CreateCustomerOutput,error) {// do some stuff herefmt.Printf("%+v",in)returnCreateCustomerOutput{Name:in.Name},nil}
go get github.com/alexisvisco/kcd@v0.1.0
- chi (by default)
- gorilla/mux
- gin
- echo
- More readable code
- Focus on what it matters: business code
- No more code duplication with unmarshalling, verifying, validating, marshalling ...
- You could have one interface for the client and server implementation
About
KCD lets you focus on what matters: coding.
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published