helper

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2020 License: MIT Imports: 5 Imported by: 0

README

这里将会提供一些 Controller 的 Helper 方法

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentPage

func CurrentPage(ctx *gin.Context) int

CurrentPage returns the current paginate page number, returns 1 as default

func CurrentSize

func CurrentSize(ctx *gin.Context) int

func Page

func Page(db *gorm.DB, pageNum int) *gorm.DB

Page - paginate method for Controller use

func PageWithSize

func PageWithSize(db *gorm.DB, pageNum, pageSize int) *gorm.DB

func Params

func Params(ctx *gin.Context) map[string]string

Params returns the request's all params as map[string]interface{} 1. Query Params (All String) 2. Body Params 3. Form Params 4. URL Params

func QueryToMap

func QueryToMap(query url.Values) map[string]string

QueryToMap makes url query params to map[string]string eg:

url: https://yourdomain?a=a&b=b returns:

map[string]string{
  "a": "a",
  "b": "b",
}

func RequestString

func RequestString(c *gin.Context) string

RequestString provide a method to generate request info.

We can use it with type APIError's Request attribute
eg: GET: /home

Types

type APIError

type APIError struct {
	Code         int    `json:"-"`
	ErrorCode    int    `json:"error_code"`
	ErrorMessage string `json:"error_message"`
	Request      string `json:"request"`
}

func NewAPIError

func NewAPIError(code, errorCode int, errorMessage, request string) *APIError

func (*APIError) Error

func (e *APIError) Error() string

Jump to

Keyboard shortcuts

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