MCPcopy Index your code
hub / github.com/alexisvisco/kcd

github.com/alexisvisco/kcd @v0.1.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.2 ↗ · + Follow
199 symbols 498 edges 48 files 70 documented · 35% updated 3y agov0.1.2 · 2022-09-15★ 43
What it actually does AI analysis from the code graph — generated when you open this
loading…
README
<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">

:stars: KCD

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.

:muscle: Example

:rocket: QuickStart

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
}

Install

go get github.com/alexisvisco/kcd@v0.1.0

Compatibility with framework

:coffee: Benefits

  • 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

📖 Read more...

Extension points exported contracts — how you extend this code

Strings (Interface)
Strings extract multiples strings values from request/response. [4 implementers]
pkg/extractor/extractors.go
ErrorHook (FuncType)
ErrorHook hook lets you interpret errors returned by your handlers. After analysis, the hook should return a suitable ht
pkg/hook/hooks.go
Value (Interface)
Value extract one value (a type) from http request/response. [4 implementers]
pkg/extractor/extractors.go
RenderHook (FuncType)
RenderHook is the last hook called by the wrapped handler before returning. It takes the response, request, the success
pkg/hook/hooks.go
BindHook (FuncType)
BindHook is the hook called by the wrapped http handler when binding an incoming request to the kcd handler's input obje
pkg/hook/hooks.go
ValidateHook (FuncType)
ValidateHook is the hook called to validate the input. The default expected return (handled by the error hook) is a map[
pkg/hook/hooks.go
LogHook (FuncType)
LogHook is the logger triggered after the error hook. It can show detailed error about a problem that you can't explain
pkg/hook/hooks.go

Core symbols most depended-on inside this repo

Handler
called by 29
handler.go
WithFields
called by 16
pkg/errors/errors.go
Wrap
called by 12
pkg/errors/errors.go
WithKind
called by 12
pkg/errors/errors.go
NewWithKind
called by 11
pkg/errors/errors.go
WithField
called by 8
pkg/errors/errors.go
Tag
called by 6
pkg/extractor/extractors.go
retrieveLocation
called by 5
pkg/errors/errors.go

Shape

Function 74
Struct 59
Method 55
FuncType 5
TypeAlias 4
Interface 2

Languages

Go100%

Modules by API surface

handler_test.go23 symbols
pkg/errors/errors.go17 symbols
internal/cache/cache.go12 symbols
internal/decoder/field_setter.go9 symbols
examples/demo-ordered-pagination/main.go8 symbols
pkg/hook/validate_test.go7 symbols
internal/decoder/decoder.go7 symbols
pkg/extractor/extractors_test.go6 symbols
pkg/extractor/extractors.go6 symbols
internal/cache/cache_test.go6 symbols
pkg/hook/render_test.go5 symbols
pkg/hook/hooks.go5 symbols

For agents

$ claude mcp add kcd \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page