pyrin

package module
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2024 License: MIT Imports: 14 Imported by: 3

README

pyrin

REST API Framework

Goals

  • API Server (Using Echo)
  • Schema Validation
  • Generate Spec File
  • API Client Generation
    • Golang
    • Typescript
  • API Docs Generation

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateSpec added in v0.8.4

func GenerateSpec(routes []Route) (*spec.Server, error)

func ServeFile added in v0.8.4

func ServeFile(w http.ResponseWriter, r *http.Request, filesystem fs.FS, file string) error

Types

type ApiHandler added in v0.8.1

type ApiHandler struct {
	Name        string
	Method      string
	Path        string
	DataType    any
	BodyType    Body
	RequireForm bool
	Errors      []ErrorType
	Middlewares []echo.MiddlewareFunc
	HandlerFunc ApiHandlerFunc
}

type ApiHandlerFunc added in v0.8.1

type ApiHandlerFunc func(c Context) (any, error)

type Body

type Body interface {
	validate.Validatable
}

type Context

type Context interface {
	Request() *http.Request
	Response() http.ResponseWriter
	Param(name string) string
}

type Error added in v0.8.3

type Error struct {
	Code    int       `json:"code"`
	Type    ErrorType `json:"type"`
	Message string    `json:"message"`
	Extra   any       `json:"extra,omitempty"`
}

func RouteNotFound added in v0.8.3

func RouteNotFound() *Error

func ValidationError added in v0.8.3

func ValidationError(extra any) *Error

func (*Error) Error added in v0.8.3

func (e *Error) Error() string

type ErrorType added in v0.8.3

type ErrorType string
const (
	ErrTypeUnknownError    ErrorType = "UNKNOWN_ERROR"
	ErrTypeRouteNotFound   ErrorType = "ROUTE_NOT_FOUND"
	ErrTypeValidationError ErrorType = "VALIDATION_ERROR"
)

type Group

type Group interface {
	Register(handlers ...Handler)
}

type Handler

type Handler interface {
	// contains filtered or unexported methods
}

type NormalHandler added in v0.8.1

type NormalHandler struct {
	Method      string
	Path        string
	Middlewares []echo.MiddlewareFunc
	HandlerFunc NormalHandlerFunc
}

type NormalHandlerFunc added in v0.8.1

type NormalHandlerFunc func(c Context) error

type Response added in v0.8.3

type Response struct {
	Success bool   `json:"success"`
	Data    any    `json:"data,omitempty"`
	Error   *Error `json:"error,omitempty"`
}

func ErrorResponse added in v0.8.3

func ErrorResponse(err Error) Response

func SuccessResponse added in v0.8.3

func SuccessResponse(data any) Response

type Route

type Route struct {
	Name        string
	Path        string
	Method      string
	ErrorTypes  []ErrorType
	Data        any
	Body        any
	RequireForm bool
}

type RouteGroup

type RouteGroup struct {
	Prefix string
	Routes []Route
}

func NewRouteGroup

func NewRouteGroup(prefix string) *RouteGroup

func (*RouteGroup) Register

func (r *RouteGroup) Register(handlers ...Handler)

type Router

type Router interface {
	Group(prefix string) Group
}

type Server

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

func NewServer

func NewServer(config *ServerConfig) *Server

func (*Server) Group

func (s *Server) Group(prefix string, m ...echo.MiddlewareFunc) *ServerGroup

func (*Server) Start

func (s *Server) Start(addr string) error

type ServerConfig

type ServerConfig struct {
	RegisterHandlers func(router Router)
	LogName          string
}

type ServerGroup

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

func (*ServerGroup) Register

func (g *ServerGroup) Register(handlers ...Handler)

type ServerRouter

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

func (*ServerRouter) Group

func (r *ServerRouter) Group(prefix string) Group

Directories

Path Synopsis
client
gen
cmd
tools
ast

Jump to

Keyboard shortcuts

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