core

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init added in v0.4.2

func Init()

func SendResponse

func SendResponse[T any](w http.ResponseWriter, v *Res[T])

func ThrowBadRequest

func ThrowBadRequest(w http.ResponseWriter, err error)

Types

type Context

type Context[TI any, TO any] struct {
	Request   *http.Request
	TraceId   string
	Input     *TI
	Output    *TO
	Exception exception.Exception
	Logger    *logger.Logger

	Timeline ContextTimeline
}

func NewContext

func NewContext[TI any, TO any](req *http.Request) *Context[TI, TO]

func (*Context[TI, TO]) Return added in v0.4.0

func (r *Context[TI, TO]) Return(data ...*TO) *Res[TO]

func (*Context[TI, TO]) Throw added in v0.4.0

func (r *Context[TI, TO]) Throw(err exception.Exception) *Res[TO]

type ContextTimeline

type ContextTimeline struct {
	Started  int64
	Finished int64
}

type Nichirin

type Nichirin struct {
	Engine  *chi.Mux
	Address string
}

func NewApp

func NewApp(addr string) *Nichirin

func (*Nichirin) StartServer

func (s *Nichirin) StartServer()

type Res

type Res[T any] struct {
	Data *T                  `json:"data"`
	Err  exception.Exception `json:"error"`
}

func CreateResponse

func CreateResponse[T any](data *T, err exception.Exception) *Res[T]

type ResPayload

type ResPayload[T any] struct {
	Code    string `json:"code"`
	Data    *T     `json:"data"`
	Message string `json:"message"`
}

type Router

type Router[TI any, TO any] struct {
	Name      string
	Method    HttpMethod
	Url       string
	AuthGuard bool
	Handler   func(*Context[TI, TO]) *Res[TO]
}

func (*Router[T, I]) Attach

func (r *Router[T, I]) Attach(app *Nichirin) *Router[T, I]

func (*Router[T, I]) Auth

func (r *Router[T, I]) Auth() *Router[T, I]

func (*Router[TI, TO]) Register added in v0.4.0

func (r *Router[TI, TO]) Register(app *Nichirin, httpMethod HttpMethod, url string, fn func(*Context[TI, TO]) *Res[TO]) *Router[TI, TO]

Jump to

Keyboard shortcuts

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