fast

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: MIT Imports: 9 Imported by: 0

README

Fast

Fast is conviniet wrapper for the Fiber framework. It provides a set of tools to simplify the development of web applications.

Example
func main() {
  app, _ := fast.New()

  app.MustRegister("/", GreetingHandler{})

  log.Fatal(app.Run(":3000"))
}

type GreetingHandler struct{}

func (h GreetingHandler) HandleGet() fast.Handler {
  return fast.
    Endpoint[fast.In, fast.Out]().
    Method(http.MethodGet).
    Path("/").
    Handle(func(*fast.Context, fast.In) (fast.Out, error) {
      return "Hello, World!", nil
    })
}

The In and Out types are used to define the input and output of the endpoint. Fast will perform validations under the hood and will automatically serialize the output to JSON.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Endpoint

func Endpoint[In, Out any]() *endpoint[In, Out]

func UnauthorizedError

func UnauthorizedError(message string) httpError

func ValidationError

func ValidationError(message string) httpError

func WithFiberApp added in v0.0.2

func WithFiberApp(app *fiber.App) func(*App)

WithFiberApp sets the fiber app to use. This is useful to pre-configure the fiber app

Types

type App

type App struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...func(*App)) (App, error)

func (App) Group

func (a App) Group(prefix string) Group

Group creates a new group of routes

func (App) Listen

func (a App) Listen(addr string) error

Listen serves HTTP requests from the given addr.

app.Listen(":8080")
app.Listen("127.0.0.1:8080")

func (App) MustRegister

func (a App) MustRegister(prefix string, handler any)

MustRegister registers a handler to the app The handler must be a struct with Hanlder methods.

type Context

type Context struct {
	*fiber.Ctx
}

type Group

type Group struct {
	// contains filtered or unexported fields
}

Group is a group of routes

func (Group) MustRegister

func (g Group) MustRegister(prefix string, handler any) Group

MustRegister registers a handler to the app The handler must be a struct with methods that return a Handler

type Handler

type Handler interface {
	// Register registers the endpoint to the given router
	Register(router fiber.Router, validator validator.Validator)
}

Handler is the interface that links the endpoint to the router

type In

type In struct{}

In is the default input type for an endpoint

type Middleware

type Middleware = func(ctx *Context) error

type Out

type Out string

Out is the default output type for an endpoint

Directories

Path Synopsis
examples
internal
validator
Package validator
Package validator

Jump to

Keyboard shortcuts

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