apiright

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2025 License: GPL-3.0 Imports: 2 Imported by: 0

README

Apiright

Apiright (Name is WIP), is yet another go Webframework, mainly for APIs. Why another one, aren't there enough? Probably yes... But I usually write my APIs with the stdlib and use often the same boilerplate. So this Framework will be a wrapper for the stdlib net/http server, with some quality of life additions.

Therefore I will try to add the best features I have seen in other Frameworks into it.

Features:

- [ ] "ExpressJS" like Router, with a global Error Handler and panic recovery
- [ ] Catch-all/default Route
- [ ] Multi domain support
- [ ] Routergroups
- [ ] Middlewares
- [ ] "Fastapi" like, streamlined simple CRUD Operations
- [ ] Automatic OpenAPI Documention
- [ ] Embedded SQLc and Goose implementation (like in Flask and SQLAlchemy)
- [ ] Embedded HTMX Support
- [ ] Static File serving
- [ ] Metrics
- [ ] Simple ReverseProxy (not recommended for production, but for hobby projects maybe nice to have)
- [ ] Embedded "cron-jobs", like included Microservices (run once, run every hour etc.)
- [ ] Multiworker scaling
- [ ] CLI-Mode
- [ ] Extensive Testsuite

Limitation

As long I haven't tagged or released a Version 1.X.X, you shouldn't use this in production!

Usage

Install via go pkg and hope for the best :)

How to use

As it is more or less a stdlib wrapper, most of the syntax is the same.

Adding Routes

A difference to the stdlib pkg is, that the "/" path isn't a Catch-all route. I think this choice by go is rather strange, so in Apiright "/" is a valid route that only serves "/". You can implement a Catch-all route, if you want. It should mainly be used for a 404 or some redirecting logic.

app := apiright.NewApp()

app.SetDefaultRoute(func(c *Ctx) error {
	c.Writer.Write([]byte("Custom not found!"))
	return nil
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Config *AppConfig
	// contains filtered or unexported fields
}

func NewApp

func NewApp() App

func (*App) GET

func (a *App) GET(path string, handler func(*Ctx) error)

func (*App) NewRouter

func (a *App) NewRouter(path string) *Router

func (App) Run

func (a App) Run() error

func (*App) SetDefaultRoute

func (a *App) SetDefaultRoute(handler Handler)

type AppConfig

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

func NewAppConfig

func NewAppConfig() AppConfig

func (AppConfig) GetListenAddress

func (c AppConfig) GetListenAddress() string

type Ctx

type Ctx struct {
	Writer  http.ResponseWriter
	Request *http.Request
}

func NewCtx

func NewCtx(w http.ResponseWriter, r *http.Request) *Ctx

type Endpoint

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

type Handler

type Handler func(*Ctx) error

type Middleware

type Middleware func(Handler) Handler

type RequestMethod

type RequestMethod int
const (
	METHOD_GET RequestMethod = iota
	METHOD_POST
	METHOD_PUT
	METHOD_PATCH
	METHOD_DELETE
	METHOD_HEAD
	METHOD_OPTIONS
	METHOD_TRACE
	METHOD_CONNECT
)

type Response

type Response struct{}

type Route

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

type Router

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

func (*Router) GET

func (r *Router) GET(path string, handler Handler)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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