quickapi

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: MIT Imports: 13 Imported by: 2

README

quickapi (WIP)

not fast implementation, but quick web API development

Warning 🚧 This package is under construction, so all examples may not work correctly.

We need the type just like this.

type Action[I any, O any] func(ctx context.Context, input I) (output O, err error)

and lift it.

func ListTodo(context.Context, quickapi.Empty) ([]Todo, error) {
    return []Todo{{Title: "foo"}}, nil
}

r.Get("/todos", quickapi.Lift(ListTodo))

experimental openapi support

⚠ this is experimental feature, using quickapi/experimental/define package can be able to define openapi doc with define router.

how to use

see examples

Documentation

Index

Constants

This section is empty.

Variables

A good base middleware stack https://github.com/go-chi/chi

View Source
var GetRequest = shared.GetRequest
View Source
var NewAPIError = shared.NewAPIError
View Source
var NoContent = shared.NoContent
View Source
var Redirect = shared.Redirect

Functions

func DefaultRouter

func DefaultRouter() chi.Router

func Lift

func Lift[I any, O any](action Action[I, O]) http.HandlerFunc

Lift transforms Action to http.Handler

Types

type Action

type Action[I any, O any] func(ctx context.Context, input I) (output O, err error)

type Empty

type Empty = shared.Empty

Empty is zero Input

type ErrorResponse

type ErrorResponse = shared.ErrorResponse

ErrorResponse represents a normal error response type

type Server

type Server struct {
	http.Server

	GracefulShutdownTimeout time.Duration
}

func NewServer

func NewServer(
	addr string, handler http.Handler,
	gracefulShutdownTimeout time.Duration,
) *Server

func (*Server) ListenAndServe

func (server *Server) ListenAndServe(ctx context.Context) error

Directories

Path Synopsis
_examples
experimental

Jump to

Keyboard shortcuts

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