common

package
v0.0.0-...-00d3902 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

Functions

func Bind

func Bind(c *gin.Context, obj interface{}) error

Changed the c.MustBindWith() -> c.ShouldBindWith(). I don't want to auto return 400 when error happened. origin function is here: https://github.com/gin-gonic/gin/blob/master/context.go

func BindUrl

func BindUrl(c *gin.Context, obj interface{}) error

func Connect

func Connect() *gorm.DB

func GetDB

func GetDB() *gorm.DB

func RandStringBytes

func RandStringBytes(n int) string

func SaveOne

func SaveOne(obj interface{}) error

Types

type CommonError

type CommonError struct {
	Errors map[string]interface{} `json:"errors"`
}

CommonError will help to return customized Error info {"database": {"hello":"no such table", error: "not_exists"}}

func NewError

func NewError(key string, err error) CommonError

NewError warps the error info in a object

func NewValidatorError

func NewValidatorError(err error) CommonError

NewValidatorError handles the error returned by c.Bind in gin framework https://github.com/go-playground/validator/blob/v9/_examples/translations/main.go

Jump to

Keyboard shortcuts

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