Documentation
¶
Index ¶
- Constants
- func DecodeAndValidate[T DbModel](r *http.Request) (T, error)
- func Encode[T any](w http.ResponseWriter, r *http.Request, status int, v T) error
- func IntPathValue(r *http.Request, key string) int
- func IntQueryValue(r *http.Request, key string) int
- func RegisterValidations(db *gorm.DB)
- func Validate(instance any) error
- type ActionForbiddenError
- type AnyMap
- type AppError
- type AppValidationError
- type AuthHeaderMissingError
- type ContextKey
- type DbModel
- type ErrorsResponse
- type HandlerWithError
- type InternalError
- type InvalidAuthHeaderError
- type InvalidJwtClaimsError
- type InvalidUserError
- type JwtTokenExpiredError
- type JwtTokenParsingError
- type LoginError
- type PaginatedResponse
- type PaginationInfo
- type PaginationParams
- type RecordNotFoundError
- type UserNotFoundError
- type ValidationResponseItem
Constants ¶
View Source
const AdminRole = "admin"
View Source
const DbContextKey = ContextKey(1)
View Source
const DefaultOrderBy = "id"
View Source
const DefaultPageNumber = 1
View Source
const DefaultPageSize = 20
View Source
const OnlyCurrentUserContextKey = ContextKey(4)
View Source
const OnlyCurrentUserPath = "/users/me"
View Source
const OrganizerRole = "organizer"
View Source
const RecordIdContextKey = ContextKey(3)
View Source
const UserContextKey = ContextKey(0)
View Source
const UserRole = "user"
View Source
const WorkersContextKey = ContextKey(2)
Variables ¶
This section is empty.
Functions ¶
func RegisterValidations ¶
Types ¶
type ActionForbiddenError ¶
type ActionForbiddenError struct {
AppError
}
type AppValidationError ¶
type AuthHeaderMissingError ¶
type AuthHeaderMissingError struct {
AppError
}
type ContextKey ¶
type ContextKey uint
type DbModel ¶
type DbModel interface { GetID() uint Validate(*http.Request) error BeforeCreateCtx(context.Context, *gorm.DB) error AfterCreateCtx(context.Context, *gorm.DB) error BeforeUpdateCtx(context.Context, *gorm.DB) error AfterUpdateCtx(context.Context, *gorm.DB) error BeforeDeleteCtx(context.Context, *gorm.DB) error AfterDeleteCtx(context.Context, *gorm.DB) error GetAllQuery(*gorm.DB, *http.Request) *gorm.DB GetQuery(*gorm.DB, *http.Request) *gorm.DB UpdateQuery(*gorm.DB, *http.Request) *gorm.DB DeleteQuery(*gorm.DB, *http.Request) *gorm.DB BuildResponse() any }
type ErrorsResponse ¶
type HandlerWithError ¶
type HandlerWithError func(http.ResponseWriter, *http.Request) error
func (HandlerWithError) ServeHTTP ¶
func (f HandlerWithError) ServeHTTP(w http.ResponseWriter, r *http.Request) error
type InternalError ¶
type InternalError struct {
AppError
}
type InvalidAuthHeaderError ¶
type InvalidAuthHeaderError struct {
AppError
}
type InvalidJwtClaimsError ¶
type InvalidJwtClaimsError struct {
AppError
}
type InvalidUserError ¶
type InvalidUserError struct {
AppError
}
type JwtTokenExpiredError ¶
type JwtTokenExpiredError struct {
AppError
}
type JwtTokenParsingError ¶
type JwtTokenParsingError struct {
AppError
}
type LoginError ¶
type LoginError struct {
AppError
}
type PaginatedResponse ¶
type PaginatedResponse struct { Data interface{} `json:"data"` PaginationInfo PaginationInfo `json:"pagination_info"` }
func BuildPaginatedResponse ¶
func BuildPaginatedResponse(responseRecords []any, totalCount int64, paginationParams *PaginationParams) *PaginatedResponse
type PaginationInfo ¶
type PaginationInfo struct { Count int `json:"count"` TotalCount int `json:"total_count"` TotalPages int `json:"total_pages"` CurrentPage int `json:"current_page"` NextPage *int `json:"next_page"` PrevPage *int `json:"prev_page"` IsFirstPage bool `json:"is_first_page"` IsLastPage bool `json:"is_last_page"` IsOutOfRangePage bool `json:"is_out_of_range_page"` }
type PaginationParams ¶
func BuildPaginationParams ¶
func BuildPaginationParams(r *http.Request) *PaginationParams
type RecordNotFoundError ¶
type RecordNotFoundError struct {
AppError
}
type UserNotFoundError ¶
type UserNotFoundError struct {
AppError
}
type ValidationResponseItem ¶
type ValidationResponseItem struct { ErrorsResponse Path []string `json:"path"` }
func AppValidationErrorDetails ¶
func AppValidationErrorDetails(err AppValidationError) []ValidationResponseItem
func ValidationErrorDetails ¶
func ValidationErrorDetails(errors validator.ValidationErrors) []ValidationResponseItem
Click to show internal directories.
Click to hide internal directories.