svc

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: Apache-2.0 Imports: 21 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"
)
View Source
var (
	ErrNoReturn = io.ErrNoProgress
)

Functions

func AesDecrypt

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

func AesEncrypt

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

func AesKey

func AesKey() string

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 Callback

func Callback(err0 error, fns ...func()) (err error)

func Callback1

func Callback1[T any](err0 error, t T, fns ...func(t T)) (err error)

func Callback1Err

func Callback1Err[T any](err0 error, t T, fns ...func(t T) (err error)) (err error)

func Callback2

func Callback2[T1, T2 any](err0 error, t1 T1, t2 T2, fns ...func(t1 T1, t2 T2)) (err error)

func Callback2Err

func Callback2Err[T1, T2 any](err0 error, t1 T1, t2 T2, fns ...func(t1 T1, t2 T2) (err error)) (err error)

func Callback3

func Callback3[T1, T2, T3 any](err0 error, t1 T1, t2 T2, t3 T3, fns ...func(t1 T1, t2 T2, t3 T3)) (err error)

func Callback3Err

func Callback3Err[T1, T2, T3 any](err0 error, t1 T1, t2 T2, t3 T3, fns ...func(t1 T1, t2 T2, t3 T3) (err error)) (err error)

func CallbackErr

func CallbackErr(err0 error, fns ...func() (err error)) (err error)

func Cors

func Cors(configure ...func(opt *CorsOption)) gin.HandlerFunc

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) *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 Return

func Return[T any](t T, err0 error) (T, error)

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice without a memory allocation.

func Uri

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

func UriReq

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

func UriReqResp

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

func UriResp

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

func ValidatorLangFunc

func ValidatorLangFunc(fn func(ctx *gin.Context) (lang string))

func ValidatorLangSupport

func ValidatorLangSupport(lang ...string)

func WebTry

func WebTry(fs embed.FS, configure ...func(opt *WebTryOption)) func(ctx *gin.Context)

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 CorsOption

type CorsOption struct {
	AccessControlAllowOrigin      string
	AccessControlAllowHeaders     string
	AccessControlAllowMethods     string
	AccessControlExposeHeaders    string
	AccessControlAllowCredentials string
	PreflightCond                 func(req *http.Request) (ok bool)
	PreflightFunc                 func(ctx *gin.Context)
}

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 HttpResponse

type HttpResponse[T any] struct {
	Code uint   `json:"code"`
	Msg  string `json:"msg"`
	Data T      `json:"data"`
	// contains filtered or unexported fields
}

func HttpDo

func HttpDo[REQ, RESP any](method, url string, header map[string]string, req REQ, options ...func(client *http.Client)) (resp0 HttpResponse[RESP], resp RESP, err error)

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"`
}

type WebTryOption

type WebTryOption struct {
	FsName             string
	ApiRoutePrefix     string
	IndexHtmlName      string
	StatusNotFoundFunc func(err error, ctx *gin.Context)
}

Jump to

Keyboard shortcuts

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