restfulrouter

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ControllerSuffix defin the suffix of controller struct
	ControllerSuffix = "Controller"

	// ErrorControllerName is a message of controller wrong name
	ErrorControllerName = "Controller name must be suffix with 'Controller'"
)
View Source
const (
	// KeySeperator seperator for keys
	KeySeperator = ":"
)

Variables

This section is empty.

Functions

func ComposeCustomMappingKey

func ComposeCustomMappingKey(method string, path string) string

ComposeCustomMappingKey which used in custom mapping logic, join the http method and the path into a string. method is http.MethodXXX which defined in http package

func RegisterAPIRoute

func RegisterAPIRoute(ginEngine *gin.Engine, controllers []IBaseController)

RegisterAPIRoute is the main function.use this func can auto register the method to the certain request url

func RegisterGroupAPIRoute

func RegisterGroupAPIRoute(basePath string, ginEngine *gin.Engine, controllers []IBaseController)

RegisterGroupAPIRoute as RegisterAPIRout, the only difference between them is group method can has pre base url

func SetLogger added in v1.0.2

func SetLogger(log ILogger)

SetLogger is set for logger instance

Types

type BaseController

type BaseController struct {
}

BaseController implement IBaseController, cover the base functions with 404 response

func (*BaseController) Delete

func (t *BaseController) Delete(c *gin.Context)

Delete default method

func (*BaseController) Get

func (t *BaseController) Get(c *gin.Context)

Get default method

func (*BaseController) Head

func (t *BaseController) Head(c *gin.Context)

Head default method

func (*BaseController) Mapping

func (t *BaseController) Mapping() map[string]GinHandler

Mapping default method

func (*BaseController) Options

func (t *BaseController) Options(c *gin.Context)

Options default method

func (*BaseController) Patch

func (t *BaseController) Patch(c *gin.Context)

Patch default method

func (*BaseController) Post

func (t *BaseController) Post(c *gin.Context)

Post default method

func (*BaseController) Put

func (t *BaseController) Put(c *gin.Context)

Put default method

type GinHandler

type GinHandler func(c *gin.Context)

GinHandler define a func for gin

type IBaseController

type IBaseController interface {
	//Get is for the HttpGet route for the certain request
	Get(c *gin.Context)
	//Post is for the HttpPost route for the certain request
	Post(c *gin.Context)
	//Put is for the HttpPut route for the certain request
	Put(c *gin.Context)
	//Delete is for the HttpDelete route for the certain request
	Delete(c *gin.Context)
	//Patch is for the HttpPatch route for the certain request
	Patch(c *gin.Context)
	//Head is for the HttpHead route for the certain request
	Head(c *gin.Context)
	//Options is for the HttpOptions route for the certain request
	Options(c *gin.Context)

	//Mapping is the method that mapping custom request to certain method
	Mapping() map[string]GinHandler
}

IBaseController that satisfies restfulrouter.IBaseController can be auto mapping request to the certain method

type ILogger added in v1.0.2

type ILogger interface {
	// WriteError is for error record
	WriteError(err interface{}, trace string, param interface{})

	// WriteInfo is for temp debug info
	WriteInfo(param interface{})
}

ILogger define the log actions

Jump to

Keyboard shortcuts

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