mvc

package
v1.9.7 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMvcTemplate = "v1/{controller}/{action}"
)

Variables

View Source
var RequestMppingFuncs map[string]ActionParametersMappingFunc = map[string]ActionParametersMappingFunc{
	"HttpContext": httpContextMappingMapping,
	"Default":     requestBodyMappingMapping,
}

Functions

func EmptyHandler

func EmptyHandler(ctx *context.HttpContext)

Types

type ActionDescriptor

type ActionDescriptor struct {
	ActionName       string
	ActionMethod     string
	MethodInfo       reflectx.MethodInfo
	IsAttributeRoute bool
	Route            *RouteAttribute
}

type ActionExecutorContext

type ActionExecutorContext struct {
	ControllerName   string
	ActionName       string
	Controller       IController
	ActionDescriptor ActionDescriptor
	Context          *context.HttpContext
}

type ActionFilterChain

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

ActionFilter Chain

func NewActionFilterChain

func NewActionFilterChain(pattern string, filter IActionFilter) ActionFilterChain

New ActionFilter Chain

func (ActionFilterChain) GetFilter

func (chain ActionFilterChain) GetFilter() IActionFilter

Get ActionFilter of Chain

func (ActionFilterChain) MatchFilter

func (chain ActionFilterChain) MatchFilter(want string) IActionFilter

// Match path for pattern to ActionFilter

func (ActionFilterChain) MatchPath

func (chain ActionFilterChain) MatchPath(want string) bool

Match path for pattern

func (ActionFilterChain) SetFilter

func (chain ActionFilterChain) SetFilter(filter IActionFilter)

Set ActionFilter to Chain

type ActionFilterContext

type ActionFilterContext struct {
	ActionExecutorContext
	Result interface{}
}

ActionFilter context

type ActionMethodExecutor

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

func NewActionMethodExecutor

func NewActionMethodExecutor() ActionMethodExecutor

func (ActionMethodExecutor) Execute

func (actionExecutor ActionMethodExecutor) Execute(ctx *ActionExecutorContext) interface{}

type ActionParametersMappingFunc

type ActionParametersMappingFunc func(paramName string, paramTypeName string, paramType reflect.Type, sourceContext *context.HttpContext) (reflect.Value, error)

type ApiController

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

func (*ApiController) ApiResult

func (c *ApiController) ApiResult() *ApiResultBuilder

func (*ApiController) Fail

func (c *ApiController) Fail(msg string) ApiResult

func (*ApiController) GetName

func (c *ApiController) GetName() string

func (*ApiController) OK

func (c *ApiController) OK(data interface{}) ApiResult

func (*ApiController) SetViewEngine

func (c *ApiController) SetViewEngine(viewEngine view.IViewEngine)

func (*ApiController) View

func (c *ApiController) View(name string, data interface{}) actionresult.IActionResult

type ApiDocResult

type ApiDocResult[T any] struct {
	Success bool
	Message string
	Data    T
	Status  int
}

type ApiDocResultBuilder

type ApiDocResultBuilder[T any] struct {
	// contains filtered or unexported fields
}

func ApiDocumentResult

func ApiDocumentResult[T any]() *ApiDocResultBuilder[T]

func (*ApiDocResultBuilder[T]) Build

func (arb *ApiDocResultBuilder[T]) Build() ApiDocResult[T]

func (*ApiDocResultBuilder[T]) Data

func (arb *ApiDocResultBuilder[T]) Data(data T) *ApiDocResultBuilder[T]

func (*ApiDocResultBuilder[T]) Fail

func (arb *ApiDocResultBuilder[T]) Fail() *ApiDocResultBuilder[T]

func (*ApiDocResultBuilder[T]) Message

func (arb *ApiDocResultBuilder[T]) Message(msg string) *ApiDocResultBuilder[T]

func (*ApiDocResultBuilder[T]) MessageWithFunc

func (arb *ApiDocResultBuilder[T]) MessageWithFunc(fc func() string) *ApiDocResultBuilder[T]

func (*ApiDocResultBuilder[T]) StatusCode

func (arb *ApiDocResultBuilder[T]) StatusCode(statusCode int) *ApiDocResultBuilder[T]

func (*ApiDocResultBuilder[T]) Success

func (arb *ApiDocResultBuilder[T]) Success() *ApiDocResultBuilder[T]

type ApiResult

type ApiResult struct {
	Success bool
	Message string
	Data    interface{}
	Status  int
}

func Fail

func Fail(data interface{}) ApiResult

func FailVoid

func FailVoid() ApiResult

func FailWithMsg

func FailWithMsg(data interface{}, msg string) ApiResult

func FailWithMsgFunc

func FailWithMsgFunc(data interface{}, fc func() string) ApiResult

func Success

func Success(data interface{}) ApiResult

func SuccessVoid

func SuccessVoid() ApiResult

func SuccessWithMsg

func SuccessWithMsg(data interface{}, msg string) ApiResult

func SuccessWithMsgFunc

func SuccessWithMsgFunc(data interface{}, fc func() string) ApiResult

func (ApiResult) StatusCode

func (api ApiResult) StatusCode() int

type ApiResultBuilder

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

func NewApiResultBuilder

func NewApiResultBuilder() *ApiResultBuilder

func (*ApiResultBuilder) Build

func (arb *ApiResultBuilder) Build() ApiResult

func (*ApiResultBuilder) Data

func (arb *ApiResultBuilder) Data(data interface{}) *ApiResultBuilder

func (*ApiResultBuilder) Fail

func (arb *ApiResultBuilder) Fail() *ApiResultBuilder

func (*ApiResultBuilder) Message

func (arb *ApiResultBuilder) Message(msg string) *ApiResultBuilder

func (*ApiResultBuilder) MessageWithFunc

func (arb *ApiResultBuilder) MessageWithFunc(fc func() string) *ApiResultBuilder

func (*ApiResultBuilder) StatusCode

func (arb *ApiResultBuilder) StatusCode(statusCode int) *ApiResultBuilder

func (*ApiResultBuilder) Success

func (arb *ApiResultBuilder) Success() *ApiResultBuilder

type ControllerBuilder

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

ControllerBuilder: controller builder

func NewControllerBuilder

func NewControllerBuilder() *ControllerBuilder

NewControllerBuilder new controller builder

func (*ControllerBuilder) AddController

func (builder *ControllerBuilder) AddController(controllerCtor interface{})

AddController add controller (ctor) to ioc.

func (*ControllerBuilder) AddFilter

func (builder *ControllerBuilder) AddFilter(pattern string, actionFilter IActionFilter)

add filter to mvc

func (*ControllerBuilder) AddViews

func (builder *ControllerBuilder) AddViews(option *view.Option)

AddViews add views to mvc

func (*ControllerBuilder) AddViewsByConfig

func (builder *ControllerBuilder) AddViewsByConfig()

AddViewsByConfig add views by config

func (*ControllerBuilder) EnableRouteAttributes

func (builder *ControllerBuilder) EnableRouteAttributes()

EnableRouteAttributes enable route attributes, such as request parameters fields[0] is RequestBody or RequestGET/POST

func (*ControllerBuilder) GetControllerDescriptorByName

func (builder *ControllerBuilder) GetControllerDescriptorByName(name string) ControllerDescriptor

GetControllerDescriptorByName get controller descriptor by controller name

func (*ControllerBuilder) GetControllerDescriptorList

func (builder *ControllerBuilder) GetControllerDescriptorList() []ControllerDescriptor

GetControllerDescriptorList is get controller descriptor array

func (*ControllerBuilder) GetMvcOptions

func (builder *ControllerBuilder) GetMvcOptions() *Options

GetMvcOptions get mvc options

func (*ControllerBuilder) GetRouterHandler

func (builder *ControllerBuilder) GetRouterHandler() *RouterHandler

GetRouterHandler is get mvc router handler.

func (*ControllerBuilder) SetConfiguration

func (builder *ControllerBuilder) SetConfiguration(configuration abstractions.IConfiguration)

SetConfiguration set configuration

func (*ControllerBuilder) SetRouteProcessor

func (builder *ControllerBuilder) SetRouteProcessor(processor IRouterAttributeBuilder)

func (*ControllerBuilder) SetViewEngine

func (builder *ControllerBuilder) SetViewEngine(viewEngine view.IViewEngine)

SetViewEngine set view engine

func (*ControllerBuilder) SetupOptions

func (builder *ControllerBuilder) SetupOptions(configOption func(options *Options))

SetupOptions , setup mvc builder options

type ControllerDescriptor

type ControllerDescriptor struct {
	ControllerName string
	Descriptor     string
	ControllerType interface{} // ctor func of controller
	// contains filtered or unexported fields
}

ControllerDescriptor

func NewControllerDescriptor

func NewControllerDescriptor(name string, controllerType reflect.Type, controllerCtor interface{}) (ControllerDescriptor, error)

NewControllerDescriptor create new controller descriptor

func (ControllerDescriptor) GetActionDescriptorByName

func (controllerDescriptor ControllerDescriptor) GetActionDescriptorByName(actionName string) (ActionDescriptor, bool)

GetActionDescriptorByName get action descriptor by name

func (ControllerDescriptor) GetActionDescriptors

func (controllerDescriptor ControllerDescriptor) GetActionDescriptors() []ActionDescriptor

GetActionDescriptors get action descriptor list

type IActionFilter

type IActionFilter interface {
	OnActionExecuting(context ActionFilterContext) bool
	OnActionExecuted(context ActionFilterContext)
}

type IController

type IController interface {
	GetName() string
	SetViewEngine(viewEngine view.IViewEngine)
}

func ActivateController

func ActivateController(serviceProvider dependencyinjection.IServiceProvider, controllerName string) (IController, error)

type IRouterAttributeBuilder

type IRouterAttributeBuilder interface {
	Match(ctx *context.HttpContext, pathComponents []string) (string, bool)
	Insert(method, path string, handler func(ctx *context.HttpContext))
}

type MatchMvcInfo

type MatchMvcInfo struct {
	ControllerName string
	ActionName     string
}

type Options

type Options struct {
	Template   *RouteTemplate
	ViewOption *view.Option
}

func NewMvcOptions

func NewMvcOptions() *Options

NewMvcOptions new mvc options.

func (*Options) MapRoute

func (options *Options) MapRoute(template string)

MapRoute map url route to mvc url template.

type RequestBody

type RequestBody struct {
}

type RequestDelete

type RequestDelete struct {
}

type RequestGET

type RequestGET struct {
}

type RequestHead

type RequestHead struct {
}

type RequestOptions

type RequestOptions struct {
}

type RequestPOST

type RequestPOST struct {
}

type RequestPatch

type RequestPatch struct{}

type RequestPut

type RequestPut struct{}

type RouteAttribute

type RouteAttribute struct {
	Template   string `json:"routeTemplate"`
	Controller string `json:"controller"`
	Action     string `json:"action"`
	Method     string `json:"method"`
}

func NewRouteAttribute

func NewRouteAttribute(template string) RouteAttribute

type RouteAttributeCollection

type RouteAttributeCollection struct {
	Collection map[string]RouteAttribute
	// contains filtered or unexported fields
}

func NewRouteAttributeCollection

func NewRouteAttributeCollection() *RouteAttributeCollection

func (*RouteAttributeCollection) Add

func (collection *RouteAttributeCollection) Add(routeAttribute RouteAttribute)

func (*RouteAttributeCollection) Disable

func (collection *RouteAttributeCollection) Disable()

func (*RouteAttributeCollection) Enable

func (collection *RouteAttributeCollection) Enable()

func (*RouteAttributeCollection) HasElement

func (collection *RouteAttributeCollection) HasElement() bool

func (*RouteAttributeCollection) IsEnable

func (collection *RouteAttributeCollection) IsEnable() bool

func (*RouteAttributeCollection) Match

func (collection *RouteAttributeCollection) Match(ctx *context.HttpContext, pathComponents []string, match *MatchMvcInfo) bool

func (*RouteAttributeCollection) SetProcessor

func (collection *RouteAttributeCollection) SetProcessor(processor IRouterAttributeBuilder)

type RouteTemplate

type RouteTemplate struct {
	Template       string
	TemplateSplits []string
	// contains filtered or unexported fields
}

func NewRouteTemplate

func NewRouteTemplate(temp string) *RouteTemplate

func (*RouteTemplate) GetActionIndex

func (template *RouteTemplate) GetActionIndex() int

func (*RouteTemplate) GetControllerIndex

func (template *RouteTemplate) GetControllerIndex() int

func (*RouteTemplate) Match

func (template *RouteTemplate) Match(pathComponents []string, matchinfo *MatchMvcInfo) bool

type RouterHandler

type RouterHandler struct {
	ControllerFilters      []ActionFilterChain
	ControllerDescriptors  map[string]ControllerDescriptor
	ActionRoutesAttributes *RouteAttributeCollection
	Options                *Options
	ViewEngine             view.IViewEngine
}

func NewMvcRouterHandler

func NewMvcRouterHandler() *RouterHandler

func (*RouterHandler) Invoke

func (handler *RouterHandler) Invoke(ctx *context.HttpContext, pathComponents []string) func(ctx *context.HttpContext)

func (RouterHandler) MatchFilters

func (handler RouterHandler) MatchFilters(ctx *context.HttpContext) []IActionFilter

type RouterHandlerResponse

type RouterHandlerResponse struct {
	Result interface{}
}

func (*RouterHandlerResponse) Callback

func (response *RouterHandlerResponse) Callback(ctx *context.HttpContext)

type StatusCoder

type StatusCoder interface {
	StatusCode() int
}

Jump to

Keyboard shortcuts

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