common

package
v0.5.0-beta Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApiErrorResponse

func ApiErrorResponse(gCtx *gin.Context, status int, code ApiErrorCode, err error)

func BasicAuthHandler

func BasicAuthHandler(h http.Handler, users []config.OverwriteUser) http.Handler

func ErrorResponse

func ErrorResponse(gCtx *gin.Context, err error)

func HttpStatusResponse

func HttpStatusResponse(gCtx *gin.Context, status int, err error)

func JsonResponse

func JsonResponse(gCtx *gin.Context, status int, data interface{})

func MetricMiddleware

func MetricMiddleware(handlerID string, handler http.Handler) http.Handler

Types

type ApiErrorCode

type ApiErrorCode string
const (
	ApiArgsError     ApiErrorCode = "ArgsError"
	ApiNoAccess      ApiErrorCode = "NoAccess"
	ApiNoPermits     ApiErrorCode = "NoPermits"
	ApiNotFoundError ApiErrorCode = "NotFound"
	ApiNotGroupError ApiErrorCode = "NotGroup"
	ApiIsGroupError  ApiErrorCode = "IsGroup"
	ApiNotEmptyError ApiErrorCode = "NotEmpty"
	ApiEntryExisted  ApiErrorCode = "EntryExisted"
	ApiInternalError ApiErrorCode = "InternalError"
)

func Error2ApiErrorCode

func Error2ApiErrorCode(err error) (int, ApiErrorCode)

type Error

type Error struct {
	Code    ApiErrorCode `json:"code"`
	Message string       `json:"message"`
}

type Response

type Response struct {
	Status int         `json:"status"`
	Error  *Error      `json:"error,omitempty"`
	Data   interface{} `json:"data,omitempty"`
}

type UserInfo

type UserInfo struct {
	UID, GID int64
}

func GetUserInfo

func GetUserInfo(ctx context.Context) *UserInfo

Jump to

Keyboard shortcuts

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