Documentation
¶
Index ¶
- Constants
- func HookExit(ctx context.Context)
- func InitGinServer(cfg *config.BaseConfig) (*gin.Engine, *log.Logger)
- func Run(r *gin.Engine, cfg *config.ServerConfig, gotCtx bool) context.Context
- type DefaultServer
- func (d *DefaultServer) Create() (gin.HandlerFunc, error)
- func (d *DefaultServer) Delete() (gin.HandlerFunc, error)
- func (d *DefaultServer) Get() (gin.HandlerFunc, error)
- func (d *DefaultServer) List() (gin.HandlerFunc, error)
- func (d *DefaultServer) Middlewares() []MiddlewaresObject
- func (d *DefaultServer) Name() string
- func (d *DefaultServer) Patch() (gin.HandlerFunc, error)
- func (d *DefaultServer) Update() (gin.HandlerFunc, error)
- func (d *DefaultServer) Version() string
- type ListData
- type MiddlewaresObject
- type Request
- type Response
- type RestController
- type RestfulAPI
- type State
Constants ¶
const ( // desc sort order Desc = "desc" // asc sort order Asc = "asc" )
const ( CREATE = "create" DELETE = "delete" UPDATE = "update" PATCH = "patch" GET = "get" LIST = "list" )
const (
CORSAllowHeaders = "*"
)
Variables ¶
This section is empty.
Functions ¶
func HookExit ¶
HookExit waits for the parent process to exit It is used to wait for the parent process to exit
func InitGinServer ¶
InitGinServer initializes a new gin server with the given configuration
Types ¶
type DefaultServer ¶
type DefaultServer struct{}
DefaultServer is the default interface for restful api. You can use it to composite your own interface.
func (*DefaultServer) Create ¶
func (d *DefaultServer) Create() (gin.HandlerFunc, error)
Create is the method for router.POST
func (*DefaultServer) Delete ¶
func (d *DefaultServer) Delete() (gin.HandlerFunc, error)
Delete is the method for router.DELETE
func (*DefaultServer) Get ¶
func (d *DefaultServer) Get() (gin.HandlerFunc, error)
Get is the method for router.GET
func (*DefaultServer) List ¶
func (d *DefaultServer) List() (gin.HandlerFunc, error)
List is the method for router.GET with query parameters
func (*DefaultServer) Middlewares ¶
func (d *DefaultServer) Middlewares() []MiddlewaresObject
func (*DefaultServer) Name ¶
func (d *DefaultServer) Name() string
Name return the restful API name, default is empty
func (*DefaultServer) Patch ¶
func (d *DefaultServer) Patch() (gin.HandlerFunc, error)
Patch is the method for router.PATCH
func (*DefaultServer) Update ¶
func (d *DefaultServer) Update() (gin.HandlerFunc, error)
Update is the method for router.PUT
func (*DefaultServer) Version ¶
func (d *DefaultServer) Version() string
Version return the restful API version, default is v1
type ListData ¶
type ListData struct {
// multiple data
Items interface{} `json:"items,omitempty"`
// total count
Total int `json:"total"`
}
ListData multiple data struct
type MiddlewaresObject ¶
type MiddlewaresObject struct {
Methods []string
Middlewares []gin.HandlerFunc
}
type Request ¶
type Request struct {
ID uint64 `param:"id"`
Page int `form:"page"`
Limit int `form:"limit"`
// sort field, default is create time
Sort string `form:"sort"`
// sort order
Order string `form:"order"`
}
Request request object
func (*Request) HandleQueryParam ¶
HandleQueryParam handle query params
type Response ¶
type Response struct {
State State `json:"state"`
// multiple data is a list, single data is a object
Data interface{} `json:"data,omitempty"`
}
Response base response struct
func ExceptResponse ¶
ExceptResponse except response
func ListResponse ¶
ListResponse multiple data response
type RestController ¶
type RestController interface {
// Create is the method for router.POST
Create() (gin.HandlerFunc, error)
// Delete is the method for router.DELETE
Delete() (gin.HandlerFunc, error)
// Update is the method for router.PUT
Update() (gin.HandlerFunc, error)
// Patch is the method for router.PATCH
Patch() (gin.HandlerFunc, error)
// Get is the method for router.GET
Get() (gin.HandlerFunc, error)
// List is the method for router.GET with query parameters
List() (gin.HandlerFunc, error)
// current api verison
Version() string
// curent api path
Name() string
// middlewares for current api group
Middlewares() []MiddlewaresObject
}
RestController restful api controller interface
type RestfulAPI ¶
type RestfulAPI struct {
// prefix for current resource
PreParameter string
// postfix for current resource
PostParameter string
// contains filtered or unexported fields
}
RestfulAPI restful api struct
func (*RestfulAPI) Install ¶
func (r *RestfulAPI) Install(e *gin.Engine, rc RestController)
Install install api
Directories
¶
| Path | Synopsis |
|---|---|
|
Description: This file is used to collect metrics for the service.
|
Description: This file is used to collect metrics for the service. |