Help us shape the future of Go! Take the 2026 Go Developer Survey

utils

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound          = errors.New("data ga ditemukan")
	ErrAlreadyExists     = errors.New("data sudah ada")
	ErrInvalidCredential = errors.New("username atau password salah")
	ErrInvalidOTP        = errors.New("kode OTP salah atau sudah kedaluwarsa")
	ErrUnauthorized      = errors.New("kamu ga memiliki akses")
	ErrForbiddenModule   = errors.New("role kamu tidak memiliki izin mengakses modul ini")
	ErrTokenExpired      = errors.New("token sudah kadaluarsa, coba login kembali")
	ErrAccountInactive   = errors.New("akun kamu ga aktif, hubungi admin")
)

Functions

func ComparePassword

func ComparePassword(hashValue, plain string) bool

func Created

func Created(c *fiber.Ctx, message string, data interface{}) error

func Fail

func Fail(c *fiber.Ctx, status int, message string, errs interface{}) error

func GenerateTOTPSecret

func GenerateTOTPSecret(issuer, accountEmail string) (secret string, qrBase64 string, err error)

func HashPassword

func HashPassword(plain string) (string, error)

func NoContent

func NoContent(c *fiber.Ctx) error

func NotFound

func NotFound(c *fiber.Ctx) error

func OK

func OK(c *fiber.Ctx, message string, data interface{}) error

func OKWithMeta

func OKWithMeta(c *fiber.Ctx, message string, data interface{}, meta interface{}) error

func ParseAndValidate

func ParseAndValidate(c *fiber.Ctx, out interface{}) bool

func ParseUintSubject

func ParseUintSubject(subject string) uint

func UintToString added in v0.1.2

func UintToString(u uint) string

func VerifyTOTP

func VerifyTOTP(code, secret string) bool

Types

type DeviceInfo

type DeviceInfo struct {
	Browser        string     `json:"browser"`
	BrowserVersion string     `json:"browser_version"`
	OS             string     `json:"os"`
	OSVersion      string     `json:"os_version"`
	DeviceType     DeviceType `json:"device_type"`
}

func ParseUserAgent

func ParseUserAgent(userAgent string) DeviceInfo

func (DeviceInfo) String

func (d DeviceInfo) String() string

type DeviceType

type DeviceType string
const (
	DeviceDesktop DeviceType = "desktop"
	DeviceMobile  DeviceType = "mobile"
	DeviceTablet  DeviceType = "tablet"
	DeviceUnknown DeviceType = "unknown"
)

type Envelope

type Envelope struct {
	Success bool        `json:"success"`
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
	Meta    interface{} `json:"meta,omitempty"`
	Errors  interface{} `json:"errors,omitempty"`
}

type FieldError

type FieldError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

func Validate

func Validate(payload interface{}) []FieldError

type JWTClaims

type JWTClaims struct {
	UserID   uint   `json:"user_id"`
	RoleID   uint   `json:"role_id"`
	RoleName string `json:"role_name"`

	SessionID uint `json:"session_id"`
	jwt.RegisteredClaims
}

type JWTService

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

func NewJWTService

func NewJWTService(cfg *config.JWTConfig) *JWTService

func (*JWTService) GenerateAccessToken

func (s *JWTService) GenerateAccessToken(userID, roleID, sessionID uint, roleName string) (string, error)

func (*JWTService) GenerateRefreshToken

func (s *JWTService) GenerateRefreshToken(userID uint) (string, time.Time, error)

func (*JWTService) ParseAccessToken

func (s *JWTService) ParseAccessToken(tokenStr string) (*JWTClaims, error)

func (*JWTService) ParseRefreshToken

func (s *JWTService) ParseRefreshToken(tokenStr string) (*jwt.RegisteredClaims, error)

type PaginationMeta

type PaginationMeta struct {
	Page       int   `json:"page"`
	Limit      int   `json:"limit"`
	TotalItems int64 `json:"total_items"`
	TotalPages int   `json:"total_pages"`
}

func BuildPaginationMeta

func BuildPaginationMeta(p PaginationParams, total int64) PaginationMeta

type PaginationParams

type PaginationParams struct {
	Page   int
	Limit  int
	Search string
	Sort   string
}

func PaginationFromContext

func PaginationFromContext(c *fiber.Ctx) PaginationParams

func (PaginationParams) Apply

func (p PaginationParams) Apply(db *gorm.DB) *gorm.DB

Jump to

Keyboard shortcuts

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