rapi

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeKindString = "string"
	TypeKindInt    = "int"
	TypeKindFloat  = "float"
	TypeKindBool   = "bool"
	TypeKindArray  = "array"
	TypeKindMap    = "map"
	TypeKindStruct = "struct"
	TypeKindAny    = "any"
)

Variables

This section is empty.

Functions

func FillURLParam

func FillURLParam(r *http.Request, param any)

Types

type HandlerMethod

type HandlerMethod[I any] interface {
	RouterElement
	// 共通のリクエストパラメーター受け取り処理をセット
	SetInputFunc(func(ctx context.Context, r *http.Request, param any) error)
	// 共通のバリデーション処理をセット
	SetValidateFunc(func(ctx context.Context, param any) error)
	// エラーをレンダリングする処理をセット
	SetHandleErrorFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request, err error))
	// レスポンスをレンダリングする処理をセット
	SetRenderFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request, output any))
	// エラーをレンダリングする直前にエラーを書き換える処理をセット
	BeforeHandleError(func(ctx context.Context, w http.ResponseWriter, r *http.Request, err error) error)
	// 共通リクエストパラメーター受け取り処理の後に必要な処理があればセット
	AfterInput(func(ctx context.Context, r *http.Request, param *I) error)
	// 共通のバリデーション処理の後に必要な処理があればセット
	AfterValidate(func(ctx context.Context, param *I) error)
}

func NewHandlerMethod

func NewHandlerMethod[I, O any](f func(ctx context.Context, param *I) (*O, error)) HandlerMethod[I]

type Router

type Router interface {
	http.Handler
	GetChiRouter() chi.Router
	Route(pattern string, fn func(r Router)) Router
	SetAuthMiddleware(middlewares ...func(http.Handler) http.Handler)
	SetOptAuthMiddleware(middlewares ...func(http.Handler) http.Handler)
	Use(middlewares ...func(http.Handler) http.Handler)
	With(middlewares ...func(http.Handler) http.Handler) Router
	Auth() Router
	OptAuth() Router
	Connect(pattern string, re RouterElement)
	Delete(pattern string, re RouterElement)
	Get(pattern string, re RouterElement)
	Head(pattern string, re RouterElement)
	Options(pattern string, re RouterElement)
	Patch(pattern string, re RouterElement)
	Post(pattern string, re RouterElement)
	Put(pattern string, re RouterElement)
	Trace(pattern string, re RouterElement)
	// router のエンドポイントと input, output の型定義を出力する
	GetRouterDefinition() ([]*RouterDefinition, map[string]*TypeStructure)
}

func NewRouter

func NewRouter() Router

type RouterDefinition

type RouterDefinition struct {
	InputTypeStructure  *TypeStructure `json:"input_type_structure"`
	OutputTypeStructure *TypeStructure `json:"output_type_structure"`
	FullPathName        string         `json:"full_path_name"`
	CurrentPathName     string         `json:"current_path_name"`
	Method              string         `json:"method"`
	WithAuth            bool           `json:"with_auth"`
}

type RouterElement

type RouterElement interface {
	GetHandleFunc() http.HandlerFunc
	GetEmptyInput() any
	GetEmptyOutput() any
}

type TypeScanner

type TypeScanner interface {
	// any の型情報を出力する
	Scan(value any) *TypeStructure
	// 今まで scan したすべての型情報を slice で出力する
	Export() map[string]*TypeStructure
	ScanUnion(values []any) *UnionStructure
	ExportUnion() map[string]*UnionStructure
	EnableStructField() TypeScanner
	DisableStructField() TypeScanner
	AddStructTagName(tagName ...string) TypeScanner
}

型情報を読み取り、整理して、 JSON 化可能な形で出力する interface

func NewTypeScanner

func NewTypeScanner() TypeScanner

type TypeStructure

type TypeStructure struct {
	Name       string `json:"name"`
	GoTypeName string `json:"go_type_name"`
	Kind       string `json:"kind"`
	// map の key の型情報。map じゃない場合は nil
	KeyType *TypeStructure `json:"key_type,omitempty"`
	// map, slice, array の要素の型情報。それ以外は nil
	ElemType *TypeStructure `json:"elem_type,omitempty"`
	// struct の field の型情報。それ以外は nil
	Fields    map[string]*TypeStructure `json:"fields,omitempty"`
	OmitEmpty bool                      `json:"omit_empty,omitempty"`
	Validate  string                    `json:"validate,omitempty"`
}

一つの型情報

type UnionStructure

type UnionStructure struct {
	Name       string `json:"name"`
	GoTypeName string `json:"go_type_name"`
	Kind       string `json:"kind"`
	Values     []any  `json:"values"`
}

Jump to

Keyboard shortcuts

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