ometria.kit

module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2024 License: MIT

README

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()
    ...
}

Directories

Path Synopsis
Package api provides a minimal framework for APIs.
Package api provides a minimal framework for APIs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL