Documentation ¶
Overview ¶
Common tools and helper functions
Index ¶
- Constants
- Variables
- func Bind(c *gin.Context, obj interface{}) error
- func BintoUint32(b []byte) uint32
- func GenToken(id uint32) string
- func GetDB() *slowpoke.Db
- func GetMasterSlave(master uint32, slave uint32) ([]byte, []byte)
- func Init() *slowpoke.Db
- func RandString(n int) string
- func ResetUsersDBWithMock()
- func TestDBFree() error
- func TestDBInit() *slowpoke.Db
- func Uint32toBin(id uint32) []byte
- type CommonError
- type Database
Constants ¶
View Source
const NBRandomPassword = "A String Very Very Very Niubilty!!@##$!@#4"
View Source
const NBSecretPassword = "A String Very Very Very Strong!!@##$!@#$"
Keep this two config private, it should not expose to open source
Variables ¶
View Source
var DB *slowpoke.Db
Functions ¶
func Bind ¶
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 BintoUint32 ¶
func ResetUsersDBWithMock ¶
func ResetUsersDBWithMock()
Reset test DB and create new one with mock data
func TestDBInit ¶
This function will create a temporarily database for running testing cases
func Uint32toBin ¶
Types ¶
type CommonError ¶
type CommonError struct {
Errors map[string]interface{} `json:"errors"`
}
My own Error type that will help return my customized Error info
{"database": {"hello":"no such table", error: "not_exists"}}
func NewValidatorError ¶
func NewValidatorError(err error) CommonError
To handle the error returned by c.Bind in gin framework https://github.com/go-playground/validator/blob/v9/_examples/translations/main.go
Click to show internal directories.
Click to hide internal directories.