svc

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

README

svc

The svc package based on Gin & Gorm

Documentation

Overview

Package svc

Index

Constants

This section is empty.

Variables

View Source
var (
	EncryptEnable = os.Getenv("ENCRYPT_ENABLE") == "T"
	DecryptEnable = os.Getenv("DECRYPT_ENABLE") == "T"
	AesKey        = os.Getenv("AES_KEY")
)
View Source
var (
	ErrNoReturn = io.ErrNoProgress
)

Functions

func AesDecrypt

func AesDecrypt(cipherBytes []byte) ([]byte, error)

func AesEncrypt

func AesEncrypt(plainText []byte) (string, error)

func Body

func Body(ctx *gin.Context, thenFunc noReqNoRespThenFunc, encrypts ...bool)

func BodyReq

func BodyReq[REQ any](ctx *gin.Context, req REQ, thenFunc reqNoRespThenFunc[REQ], encrypts ...bool)

func BodyReqResp

func BodyReqResp[REQ, RESP any](ctx *gin.Context, req REQ, thenFunc thenFunc[REQ, RESP], encrypts ...bool)

func BodyResp

func BodyResp[RESP any](ctx *gin.Context, thenFunc noReqRespThenFunc[RESP], encrypts ...bool)

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string without a memory allocation.

func Decryption

func Decryption() gin.HandlerFunc

func Form

func Form(ctx *gin.Context, thenFunc noReqNoRespThenFunc, encrypts ...bool)

func FormReq

func FormReq[REQ any](ctx *gin.Context, req REQ, thenFunc reqNoRespThenFunc[REQ], encrypts ...bool)

func FormReqResp

func FormReqResp[REQ, RESP any](ctx *gin.Context, req REQ, thenFunc thenFunc[REQ, RESP], encrypts ...bool)

func FormResp

func FormResp[RESP any](ctx *gin.Context, thenFunc noReqRespThenFunc[RESP], encrypts ...bool)

func GetApp

func GetApp(middlewares ...gin.HandlerFunc) *gin.Engine

func GetAppWithGroup

func GetAppWithGroup(prefix string, middlewares ...gin.HandlerFunc) *gin.RouterGroup

func MapFormWithTag

func MapFormWithTag(ptr any, form map[string][]string, tag string) error

func Pagination

func Pagination(db *gorm.DB, req PageReq, count *int64, list any) (err error)

func Query

func Query(ctx *gin.Context, thenFunc noReqNoRespThenFunc, encrypts ...bool)

func QueryReq

func QueryReq[REQ any](ctx *gin.Context, req REQ, thenFunc reqNoRespThenFunc[REQ], encrypts ...bool)

func QueryReqResp

func QueryReqResp[REQ, RESP any](ctx *gin.Context, req REQ, thenFunc thenFunc[REQ, RESP], encrypts ...bool)

func QueryResp

func QueryResp[RESP any](ctx *gin.Context, thenFunc noReqRespThenFunc[RESP], encrypts ...bool)

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice without a memory allocation.

func WriteBindError

func WriteBindError(ctx *gin.Context, err error, encrypts ...bool)

func WriteJSON

func WriteJSON(ctx *gin.Context, code, httpCode int, msg string, err error, data any, encrypts ...bool)

func WriteMessageJSON

func WriteMessageJSON(ctx *gin.Context, httpCode int, str string, encrypts ...bool)

func WriteServerErrorJSON

func WriteServerErrorJSON(ctx *gin.Context, err error, encrypts ...bool)

func WriteSuccessJSON

func WriteSuccessJSON(ctx *gin.Context, data any, encrypts ...bool)

func WriteSuccessOrErrorJSON

func WriteSuccessOrErrorJSON(ctx *gin.Context, err error, encrypts ...bool)

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

func NewError

func NewError(error string) *Error

func NewErrorWithCode

func NewErrorWithCode(error string, code int) *Error

func NewErrorWithCodes

func NewErrorWithCodes(error string, httpCode int, code int) *Error

func NewErrorWithHttpCode

func NewErrorWithHttpCode(error string, httpCode int) *Error

func (*Error) Error

func (e *Error) Error() string

type PageReq

type PageReq struct {
	Limit int `form:"limit"`
	Page  int `form:"page"`
}

type PageResp

type PageResp[T any] struct {
	Total int64 `json:"total"`
	List  []T   `json:"list"`
}

Jump to

Keyboard shortcuts

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