pyrin

package module
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 13 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

Projects Used

Documentation

Index

Constants

This section is empty.

Variables

Functions

func Body

func Body[T any](c Context) (T, error)

func ServeFile added in v0.8.4

func ServeFile(c Context, filesystem fs.FS, file string) error

Types

type ApiHandler added in v0.8.1

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

type ApiHandlerFunc added in v0.8.1

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

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 BadContentType added in v0.12.0

func BadContentType(expected string) *Error

func EmptyBody added in v0.12.0

func EmptyBody() *Error

func FormValidationError added in v0.12.0

func FormValidationError(extra any) *Error

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"
	ErrTypeFormValidationError ErrorType = "FORM_VALIDATION_ERROR"
	ErrTypeEmptyBody           ErrorType = "EMPTY_BODY_ERROR"
	ErrTypeBadContentType      ErrorType = "BAD_CONTENT_TYPE_ERROR"
)

func (ErrorType) String added in v0.13.0

func (e ErrorType) String() string

type Files added in v0.12.0

type Files []*multipart.FileHeader

func FormFiles added in v0.12.0

func FormFiles(c Context, key string) (Files, error)

type FormApiHandler added in v0.12.0

type FormApiHandler struct {
	Name         string
	Method       string
	Path         string
	ResponseType any
	Spec         FormSpec
	Errors       []ErrorType
	Middlewares  []echo.MiddlewareFunc
	HandlerFunc  ApiHandlerFunc
}

type FormFileSpec added in v0.12.0

type FormFileSpec struct {
	NumExpected int
}

type FormSpec added in v0.12.0

type FormSpec struct {
	BodyType any
	Files    map[string]FormFileSpec
}

type Group

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

type Handler

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

type NoContentError added in v0.13.0

type NoContentError struct {
	Code int `json:"code"`
}

func NoContentNotFound added in v0.13.0

func NoContentNotFound() *NoContentError

func (*NoContentError) Error added in v0.13.0

func (e *NoContentError) Error() string

type NormalHandler added in v0.8.1

type NormalHandler struct {
	Name        string
	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 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

type Transformable added in v0.10.0

type Transformable interface {
	Transform()
}

Directories

Path Synopsis
cmd
tools
ast
gen

Jump to

Keyboard shortcuts

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