pkg

package
v0.0.0-...-79ac43c Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ALREADY_EXISTS_ERROR  = "already_exists"
	INTERNAL_ERROR        = "internal"
	INVALID_ERROR         = "invalid"
	NOT_FOUND_ERROR       = "not_found"
	NOT_IMPLEMENTED_ERROR = "not_implemented"
	AUTHENTICATION_ERROR  = "authentication"
)

Variables

This section is empty.

Functions

func BoolPtr

func BoolPtr(b bool) *bool

BoolPtr returns a pointer to the given bool.

func BytePtr

func BytePtr(b byte) *byte

BytePtr returns a pointer to the given byte.

func CalculateOffset

func CalculateOffset(currentPage, pageSize uint32) int32

func ComparePasswordAndHash

func ComparePasswordAndHash(hashPass string, password string) error

func DurationPtr

func DurationPtr(d time.Duration) *time.Duration

DurationPtr returns a pointer to the given time.Duration.

func ErrorCode

func ErrorCode(err error) string

func ErrorMessage

func ErrorMessage(err error) string

func ErrorToStatusCode

func ErrorToStatusCode(err error) int

func Float32Ptr

func Float32Ptr(f float32) *float32

Float32Ptr returns a pointer to the given float32.

func Float64Ptr

func Float64Ptr(f float64) *float64

Float64Ptr returns a pointer to the given float64.

func GenerateAccessToken

func GenerateAccessToken(consumerKey string, consumerSecret string) (string, error)

func GenerateHashPassword

func GenerateHashPassword(password string, cost int) (string, error)

func Int32Ptr

func Int32Ptr(i int32) *int32

Int32Ptr returns a pointer to the given int32.

func Int64Ptr

func Int64Ptr(i int64) *int64

Int64Ptr returns a pointer to the given int64.

func IntPtr

func IntPtr(i int) *int

IntPtr returns a pointer to the given int.

func InterfaceFloat64

func InterfaceFloat64(i interface{}) float64

transform interface to float64 if error it logs and return 0.00 used to trransform money from db to go type float64

func PtrToStr

func PtrToStr(s *string) string

func RunePtr

func RunePtr(r rune) *rune

RunePtr returns a pointer to the given rune.

func StringPtr

func StringPtr(s string) *string

StringPtr returns a pointer to the given string.

func StringToFloat64

func StringToFloat64(s string) (float64, error)

func StringToUint32

func StringToUint32(s string) (uint32, error)

func TimePtr

func TimePtr(t time.Time) *time.Time

TimePtr returns a pointer to the given time.Time.

func Uint32Ptr

func Uint32Ptr(i uint32) *uint32

Uint32Ptr returns a pointer to the given uint32.

func Uint64Ptr

func Uint64Ptr(i uint64) *uint64

Uint64Ptr returns a pointer to the given uint64.

func UintPtr

func UintPtr(i uint) *uint

UintPtr returns a pointer to the given uint.

Types

type Config

type Config struct {
	CONFIG_PATH             string        `mapstructure:"CONFIG_PATH"`
	ENVIRONMENT             string        `mapstructure:"ENVIRONMENT"`
	HTTP_PORT               string        `mapstructure:"HTTP_PORT"`
	MYSQL_USER              string        `mapstructure:"MYSQL_USER"`
	MYSQL_PASSWORD          string        `mapstructure:"MYSQL_PASSWORD"`
	MYSQL_DB                string        `mapstructure:"MYSQL_DB"`
	DB_DSN                  string        `mapstructure:"DB_DSN"`
	MIGRATION_PATH          string        `mapstructure:"MIGRATION_PATH"`
	TOKEN_DURATION          time.Duration `mapstructure:"TOKEN_DURATION"`
	PASSWORD_RESET_DURATION time.Duration `mapstructure:"PASSWORD_RESET_DURATION"`
	REFRESH_TOKEN_DURATION  time.Duration `mapstructure:"REFRESH_TOKEN_DURATION"`
	TOKEN_SYMMETRY_KEY      string        `mapstructure:"TOKEN_SYMMETRY_KEY"`
	PASSWORD_COST           int           `mapstructure:"PASSWORD_COST"`
	RSA_PRIVATE_KEY         string        `mapstructure:"RSA_PRIVATE_KEY"`
	RSA_PUBLIC_KEY          string        `mapstructure:"RSA_PUBLIC_KEY"`
	EMAIL_SENDER_PASSWORD   string        `mapstructure:"EMAIL_SENDER_PASSWORD"`
	EMAIL_SENDER_NAME       string        `mapstructure:"EMAIL_SENDER_NAME"`
	EMAIL_SENDER_ADDRESS    string        `mapstructure:"EMAIL_SENDER_ADDRESS"`
	REDIS_ADDRESS           string        `mapstructure:"REDIS_ADDRESS"`
	REDIS_PASSWORD          string        `mapstructure:"REDIS_PASSWORD"`
	MPESA_CONSUMER_KEY      string        `mapstructure:"MPESA_CONSUMER_KEY"`
	MPESA_CONSUMER_SECRET   string        `mapstructure:"MPESA_CONSUMER_SECRET"`
	MPESA_SHORT_CODE        string        `mapstructure:"MPESA_SHORT_CODE"`
	MPESA_PASSKEY           string        `mapstructure:"MPESA_PASSKEY"`
}

func LoadConfig

func LoadConfig(path, name, configType string) (Config, error)

Loads app configuration from .env file.

type EmailSender

type EmailSender interface {
	SendMail(subject, content string, mimeType string, to, cc, bcc []string, attachmentNames []string, attachmentData [][]byte) error
}

func NewGmailSender

func NewGmailSender(name, fromEmailAddress, fromEmailPassword string) EmailSender

type Error

type Error struct {
	Code    string
	Message string
}

func Errorf

func Errorf(code string, format string, args ...any) *Error

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface. Not used by the application otherwise.

type GmailSender

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

func (GmailSender) SendMail

func (sender GmailSender) SendMail(subject, content string, mimeType string, to, cc, bcc []string, attachmentNames []string, attachmentData [][]byte) error

type JWTMaker

type JWTMaker struct {
	PublicKey  *rsa.PublicKey
	PrivateKey *rsa.PrivateKey
	// contains filtered or unexported fields
}

func NewJWTMaker

func NewJWTMaker(privateKeyPEM string, publicKeyPEM string, config Config) (*JWTMaker, error)

func (*JWTMaker) CreateToken

func (maker *JWTMaker) CreateToken(email string, userID, branchID uint32, role string, duration time.Duration) (string, error)

func (*JWTMaker) GetPayload

func (maker *JWTMaker) GetPayload(token string) (*Payload, error)

func (*JWTMaker) VerifyToken

func (maker *JWTMaker) VerifyToken(token string) (*Payload, error)

type PaginationMetadata

type PaginationMetadata struct {
	PageSize    uint32     `json:"pageSize"`
	CurrentPage uint32     `json:"currentPage"`
	TotalData   uint32     `json:"totalData"`
	TotalPages  uint32     `json:"totalPages"`
	FromDate    *time.Time `json:"from_date,omitempty"`
	ToDate      *time.Time `json:"to_date,omitempty"`
}

func CreatePaginationMetadata

func CreatePaginationMetadata(totalData, pageSize, currentPage uint32) PaginationMetadata

type Payload

type Payload struct {
	ID       uuid.UUID `json:"id"`
	UserID   uint32    `json:"user_id"`
	Email    string    `json:"email"`
	Role     string    `json:"role"`
	BranchID uint32    `json:"branch_id"`
	jwt.RegisteredClaims
}

Jump to

Keyboard shortcuts

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