<a href='https://alexisvisco.gitbook.io/kcd'>
<img alt="kcd logo" width="460" height="300" src="https://github.com/alexisvisco/kcd/raw/v0.1.2/github/kcd_logo.svg"></a>
<a href="https://github.com/alexisvisco/kcd/actions">
<img alt="kcd is passing lint and tests" width="93" height="20" src="https://github.com/alexisvisco/kcd/workflows/Go/badge.svg"></a>
<a href="https://goreportcard.com/report/github.com/alexisvisco/kcd">
<img alt="kcd has a a+ report" width="78" height="20" src="https://goreportcard.com/badge/github.com/alexisvisco/kcd"></a>
<a href='https://coveralls.io/github/alexisvisco/kcd?branch=master'>
<img src='https://coveralls.io/repos/github/alexisvisco/kcd/badge.svg?branch=master' alt='Coverage Status' /></a>
<a href='https://alexisvisco.gitbook.io/kcd'>
<img src='https://img.shields.io/badge/gitbook-documentation-blue' alt='documentation' /></a>
<img alt="comparaison between a code with and without kcd" src="https://github.com/alexisvisco/kcd/raw/v0.1.2/github/versus.svg">
KCD is a grandiose REST helper that wrap your shiny handler into a classic http handler. It manages all you want for building REST services.
This library is opinionated by default but customizable 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.
package main
import (
"fmt"
"net/http"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/alexisvisco/kcd"
)
func main() {
r := chi.NewRouter()
r.Use(middleware.RequestID)
// You can configure kcd with kcd.Config
r.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.
type CreateCustomerInput struct {
Name string `path:"name"` // you can extract value from: 'path', 'query', 'header', 'ctx'
Emails []string `query:"emails" exploder:","` // exploder split value with the characters specified
Subject string `json:"body"` // it also works with json body
}
// CreateCustomerOutput is the output type of the http request.
type CreateCustomerOutput struct {
Name string `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.
func YourHttpHandler(in *CreateCustomerInput) (CreateCustomerOutput, error) {
// do some stuff here
fmt.Printf("%+v", in)
return CreateCustomerOutput{Name: in.Name}, nil
}
go get github.com/alexisvisco/kcd@v0.1.0