validation

package module
v0.0.0-...-fe5219f Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2020 License: MIT Imports: 4 Imported by: 0

README

Chinese

beego-validation

This is a BaseController and Validation for Beego framework.

It uses govalidator to support the request param validaton. It also provides baseController that other handler struct can combine this BaseController.

Usage

Download and install using go module:

export GO111MODULE=on
go get -u github.com/shuxnhs/beego-validation

Import it in your code:

import (
    validation "github.com/shuxnhs/beego-validation"
)

Example

Please see the example Controller and you can use Declarative parameter validation to validator the request data.

package main

import (
	validation "github.com/shuxnhs/beego-validation"
	"github.com/shuxnhs/beego-validation/formatter"
)

type ExampleController struct {
	validation.BaseController
}

func (e *ExampleController) Ping() {
	ruleMap := map[string]formatter.Rule{
		"objectId": {"name": "object_id", "type": formatter.ValidTypeInt, "required": true, "rule": "", "default": 123},
		"objectName": {"name": "object_name", "type": formatter.ValidTypeString, "required": true,
			"rule": "length(1|10),in(string1|string2|...|stringN)"},
	}
	paramMap := e.Rules(ruleMap)
	e.ApiSuccessData("success", paramMap["objectId"])
}

explain

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseController

type BaseController struct {
	beego.Controller
	// contains filtered or unexported fields
}

func (*BaseController) ApiError

func (b *BaseController) ApiError(ret int, msg string)

*

  • 异常返回

func (*BaseController) ApiErrorData

func (b *BaseController) ApiErrorData(ret int, msg string, data interface{})

*

  • 异常返回,带数据

func (*BaseController) ApiFail

func (b *BaseController) ApiFail(code int, msg string)

*

  • 业务失败返回

func (*BaseController) ApiFailData

func (b *BaseController) ApiFailData(code int, msg string, data interface{})

*

  • 业务失败返回,带数据

func (*BaseController) ApiSuccess

func (b *BaseController) ApiSuccess(msg string)

*

  • 业务成功返回

func (*BaseController) ApiSuccessData

func (b *BaseController) ApiSuccessData(msg string, data interface{})

*

  • 业务成功返回,带数据

func (*BaseController) GetMap

func (b *BaseController) GetMap(key string) map[string]string

func (*BaseController) Rules

func (b *BaseController) Rules(ruleMap map[string]formatter.Rule) map[string]interface{}

func (*BaseController) ServeJSON

func (b *BaseController) ServeJSON(encoding ...bool)

重写ServeJSON,兼容jsonp

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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