hateoas

package module
v0.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

README

Bun HATEOAS

This is a HATEOAS package for bunrouter.

Usage

Very similar to how you group routes normally using bun, you can replace them with the WithGroup function from bun-hateoas and it will add the group to the map and running methods of the group handler will work like normal but it will handle adding the routes to the group in the map.

import bunhateoas "github.com/JackalLabs/bun-hateoas"

hateoas := bunhateoas.NewHATEOAS()

hateoas.WithGroup(router.Use(CustomCors(nimbusUrl, true)), "", func(group *bunhateoas.Group) {
	group.GET("/version", routeHandlers.VersionHandler(Version))
	group.GET("/hook", routeHandlers.WebhookHandler())
	group.POST("/register", routeHandlers.UserRegistrationHandler(dbSession, jwtKey))
	group.POST("/login", routeHandlers.LoginHandler(dbSession, jwtKey))
	group.GET("/", hateoas.Handler())
})

hateoas.WithGroup(router.Use(CustomCors("*", false)), "/pubapi", func(group *bunhateoas.Group) {
    group.GET("/download/:id", japicore.DownloadHandler(fileIo))
    group.GET("/d/:id", japicore.DownloadHandler(fileIo))
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FriendlyTimestamp

func FriendlyTimestamp() string

Types

type BunGroupFunc

type BunGroupFunc func(group *Group)

type Group

type Group struct {
	Name     string
	Paths    PathSet
	BunGroup *bunrouter.Group
}

func (*Group) Append

func (g *Group) Append(handlerType string, path string, handlerFunction bunrouter.HandlerFunc)

Append adds a new route to the group. Handler is usually GET or POST.

func (*Group) DELETE

func (g *Group) DELETE(path string, handlerFunction bunrouter.HandlerFunc)

DELETE adds a new DELETE route to the group

func (*Group) GET

func (g *Group) GET(path string, handlerFunction bunrouter.HandlerFunc)

GET adds a new GET route to the group

func (*Group) POST

func (g *Group) POST(path string, handlerFunction bunrouter.HandlerFunc)

POST adds a new POST route to the group

type GroupType

type GroupType interface {
	WithGroup(path string, fn func(group *bunrouter.Group))
}

type HATEOAS

type HATEOAS struct {
	Groups []*Group
}

func NewHATEOAS

func NewHATEOAS() *HATEOAS

func (*HATEOAS) Handler

func (h *HATEOAS) Handler() bunrouter.HandlerFunc

func (*HATEOAS) Print

func (h *HATEOAS) Print() string

func (*HATEOAS) WithGroup

func (h *HATEOAS) WithGroup(g GroupType, path string, groupFunc BunGroupFunc)

type PathSet

type PathSet map[Route]bool

PathSet is a set of routes where no routes can be duplicated

func (PathSet) Add

func (p PathSet) Add(route Route)

Add puts the route into the set

func (PathSet) List

func (p PathSet) List() []Route

List returns a slice of routes from the set

type Route

type Route struct {
	Type string
	Path string
}

Jump to

Keyboard shortcuts

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