network

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApiKeyHeader        = "x-api-key"
	AuthorizationHeader = "Authorization"
)

Variables

This section is empty.

Functions

func CustomTagNameFunc

func CustomTagNameFunc() validator.TagNameFunc

func MockSuccessDataHandler

func MockSuccessDataHandler(msg string, data any) gin.HandlerFunc

func MockSuccessMsgHandler

func MockSuccessMsgHandler(msg string) gin.HandlerFunc

func MockTestAuthenticationProvider

func MockTestAuthenticationProvider(
	t *testing.T,
	auth AuthenticationProvider,
	handler gin.HandlerFunc,
	headers ...primitive.E,
) *httptest.ResponseRecorder

func MockTestAuthorizationProvider

func MockTestAuthorizationProvider(
	t *testing.T,
	role string,
	auth AuthenticationProvider,
	authz AuthorizationProvider,
	handler gin.HandlerFunc,
	headers ...primitive.E,
) *httptest.ResponseRecorder

func MockTestController

func MockTestController(
	t *testing.T, httpMethod, url, body string,
	controller Controller,
) *httptest.ResponseRecorder

func MockTestHandler

func MockTestHandler(
	t *testing.T, httpMethod, path, url, body string,
	handler gin.HandlerFunc,
	headers ...primitive.E,
) *httptest.ResponseRecorder

func MockTestRootMiddleware

func MockTestRootMiddleware(
	t *testing.T,
	middleware RootMiddleware,
	handler gin.HandlerFunc,
	headers ...primitive.E,
) *httptest.ResponseRecorder

func MockTestRootMiddlewareWithUrl

func MockTestRootMiddlewareWithUrl(
	t *testing.T, path, url string,
	middleware RootMiddleware,
	handler gin.HandlerFunc,
	headers ...primitive.E,
) *httptest.ResponseRecorder

func ReqBody

func ReqBody[T any](ctx *gin.Context, dto Dto[T]) (*T, error)

ShouldBindJSON in gin internally used go-playground/validator i.e. why we have error with validaiton info

func ReqHeaders

func ReqHeaders[T any](ctx *gin.Context, dto Dto[T]) (*T, error)

func ReqParams

func ReqParams[T any](ctx *gin.Context, dto Dto[T]) (*T, error)

func ReqQuery

func ReqQuery[T any](ctx *gin.Context, dto Dto[T]) (*T, error)

Types

type ApiError

type ApiError interface {
	GetCode() int
	GetMessage() string
	Error() string
	Unwrap() error
}

func NewBadRequestError

func NewBadRequestError(message string, err error) ApiError

func NewForbiddenError

func NewForbiddenError(message string, err error) ApiError

func NewInternalServerError

func NewInternalServerError(message string, err error) ApiError

func NewNotFoundError

func NewNotFoundError(message string, err error) ApiError

func NewUnauthorizedError

func NewUnauthorizedError(message string, err error) ApiError

type AuthenticationProvider

type AuthenticationProvider Param0MiddlewareProvider

type AuthorizationProvider

type AuthorizationProvider ParamNMiddlewareProvider[string]

type BaseController

type BaseController interface {
	ResponseSender
	Path() string
	Authentication() gin.HandlerFunc
	Authorization(role string) gin.HandlerFunc
}

func NewBaseController

func NewBaseController(basePath string, authProvider AuthenticationProvider, authorizeProvider AuthorizationProvider) BaseController

type BaseMiddleware

type BaseMiddleware interface {
	ResponseSender
	Debug() bool
}

func NewBaseMiddleware

func NewBaseMiddleware() BaseMiddleware

type BaseMiddlewareProvider

type BaseMiddlewareProvider interface {
	BaseMiddleware
}

type BaseModule added in v1.1.2

type BaseModule[T any] interface {
	GetInstance() *T
	RootMiddlewares() []RootMiddleware
	AuthenticationProvider() AuthenticationProvider
	AuthorizationProvider() AuthorizationProvider
}

type BaseRouter added in v1.1.0

type BaseRouter interface {
	GetEngine() *gin.Engine
	RegisterValidationParsers(tagNameFunc validator.TagNameFunc)
	LoadRootMiddlewares(middlewares []RootMiddleware)
	Start(ip string, port uint16)
}

type BaseService

type BaseService interface {
	Context() context.Context
}

func NewBaseService

func NewBaseService() BaseService

type Controller

type Controller interface {
	BaseController
	MountRoutes(group *gin.RouterGroup)
}

type Dto

type Dto[T any] interface {
	GetValue() *T
	ValidateErrors(errs validator.ValidationErrors) ([]string, error)
}

type MockAuthenticationProvider

type MockAuthenticationProvider struct {
	mock.Mock
}

func (*MockAuthenticationProvider) Debug

func (m *MockAuthenticationProvider) Debug() bool

func (*MockAuthenticationProvider) Middleware

func (m *MockAuthenticationProvider) Middleware() gin.HandlerFunc

func (*MockAuthenticationProvider) Send

type MockAuthorizationProvider

type MockAuthorizationProvider struct {
	mock.Mock
}

func (*MockAuthorizationProvider) Debug

func (m *MockAuthorizationProvider) Debug() bool

func (*MockAuthorizationProvider) Middleware

func (m *MockAuthorizationProvider) Middleware(params ...string) gin.HandlerFunc

func (*MockAuthorizationProvider) Send

type MockDto

type MockDto struct {
	Field string `json:"field" form:"field" uri:"field" binding:"required" validate:"required"`
}

func (*MockDto) GetValue

func (d *MockDto) GetValue() *MockDto

func (*MockDto) ValidateErrors

func (b *MockDto) ValidateErrors(errs validator.ValidationErrors) ([]string, error)

type Module

type Module[T any] interface {
	BaseModule[T]
	Controllers() []Controller
}

type Param0MiddlewareProvider

type Param0MiddlewareProvider interface {
	BaseMiddlewareProvider
	Middleware() gin.HandlerFunc
}

type Param1MiddlewareProvider

type Param1MiddlewareProvider[T any] interface {
	BaseMiddlewareProvider
	Middleware(param1 T) gin.HandlerFunc
}

type Param2MiddlewareProvider

type Param2MiddlewareProvider[T any, V any] interface {
	BaseMiddlewareProvider
	Middleware(param1 T, param2 V) gin.HandlerFunc
}

type Param3MiddlewareProvider

type Param3MiddlewareProvider[T any, V any, W any] interface {
	BaseMiddlewareProvider
	Middleware(param1 T, param2 V, param3 W) gin.HandlerFunc
}

type ParamNMiddlewareProvider

type ParamNMiddlewareProvider[T any] interface {
	BaseMiddlewareProvider
	Middleware(params ...T) gin.HandlerFunc
}

type ResCode

type ResCode string

type Response

type Response interface {
	GetResCode() ResCode
	GetStatus() int
	GetMessage() string
	GetData() any
}

func NewBadRequestResponse

func NewBadRequestResponse(message string) Response

func NewForbiddenResponse

func NewForbiddenResponse(message string) Response

func NewInternalServerErrorResponse

func NewInternalServerErrorResponse(message string) Response

func NewNotFoundResponse

func NewNotFoundResponse(message string) Response

func NewSuccessDataResponse

func NewSuccessDataResponse(message string, data any) Response

func NewSuccessMsgResponse

func NewSuccessMsgResponse(message string) Response

func NewUnauthorizedResponse

func NewUnauthorizedResponse(message string) Response

type ResponseSender

type ResponseSender interface {
	Debug() bool
	Send(ctx *gin.Context) SendResponse
}

func NewResponseSender

func NewResponseSender() ResponseSender

type RootMiddleware

type RootMiddleware interface {
	BaseMiddleware
	Attach(engine *gin.Engine)
	Handler(ctx *gin.Context)
}

type Router

type Router interface {
	BaseRouter
	LoadControllers(controllers []Controller)
}

func NewRouter

func NewRouter(mode string) Router

type SendResponse

type SendResponse interface {
	SuccessMsgResponse(message string)
	SuccessDataResponse(message string, data any)
	BadRequestError(message string, err error)
	ForbiddenError(message string, err error)
	UnauthorizedError(message string, err error)
	NotFoundError(message string, err error)
	InternalServerError(message string, err error)
	MixedError(err error)
}

Jump to

Keyboard shortcuts

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