Skip to content

A collection of building blocks for Go apps 🧱

License

Notifications You must be signed in to change notification settings

dlmiddlecote/kit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kit

Test codecov PkgGoDev

A collection of building blocks for Go apps 🧱.

Packages

package api

This package provides building blocks for HTTP APIs. There is one main interface and one main function that are used to interact with this package.

  • API: This interface defines an API, and concrete implementations of an API should be registered with a server, which is returned by;
  • NewServer: This function takes an API, and returns a http.Server.

These two should be used in conjunction to provide a conformant experience across many HTTP APIs.

Example

...

type MyAPI struct {
    logger *zap.SugaredLogger
}

func (a *MyAPI) Endpoints() []api.Endpoint {
    return []api.Endpoint{
        {"GET", "/:id", a.handleGet(), []api.Middleware{}},
    }
}

func (a *MyAPI) handleGet() http.Handler {
    var h http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
        api.Respond(w, r, http.StatusOK, nil)
    }
    return h
}

func main() {
    ...
    a := MyAPI{logger}
    srv := api.NewServer(":8080", logger, a)
    srv.ListenAndServe()
    ...
}

About

A collection of building blocks for Go apps 🧱

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages