util

package
v0.0.0-...-d64ad05 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPassword

func CheckPassword(password string, hashedPassword string) error

func DateTimeRegExp

func DateTimeRegExp() *regexp.Regexp

func HashPassword

func HashPassword(password string) (string, error)

HashPassword returns the bcrypt hash of the password

func NewLogger

func NewLogger(config Config) *zerolog.Logger

func ParseDateTime

func ParseDateTime(s string) (time.Time, bool)

ParseDateTime extracts a valid mobile number from s.

func ParseMobileNumber

func ParseMobileNumber(s string) (string, bool)

ParseMobileNumber extracts a valid mobile number from s.

func RandomEmail

func RandomEmail() string

RandomEmail generates a random email

func RandomFloat

func RandomFloat[T constraints.Float](min, max T) T

RandomFloat generates a random float between min and max

func RandomInt

func RandomInt[T constraints.Integer](min, max T) T

RandomInt generates a random integer between min and max

func RandomMobileNumber

func RandomMobileNumber() string

func RandomString

func RandomString(n int) string

RandomString generates a random string of length n

func SetDifference

func SetDifference(a, b []string) (diff []string)

Set Difference

func SetIntersection

func SetIntersection(a, b []string) (c []string)

Set Intersection

func ToFloat4

func ToFloat4(f *float32) pgtype.Float4

func ToInt4

func ToInt4(i *int32) pgtype.Int4

func ToPgDate

func ToPgDate(s string) pgtype.Date

func ToPgText

func ToPgText(s string) pgtype.Text

Types

type Config

type Config struct {
	Environment          string        `mapstructure:"ENVIRONMENT"`
	GinMode              string        `mapstructure:"GIN_MODE"`
	DBDriver             string        `mapstructure:"DB_DRIVER"`
	DBSource             string        `mapstructure:"DB_SOURCE"`
	MigrationPath        string        `mapstructure:"MIGRATION_PATH"`
	HTTPServerAddress    string        `mapstructure:"HTTP_SERVER_ADDRESS"`
	CookieDomain         string        `mapstructure:"COOKIE_DOMAIN"`
	CookiePath           string        `mapstructure:"COOKIE_PATH"`
	TokenSymmetricKey    string        `mapstructure:"TOKEN_SYMMETRIC_KEY"`
	AccessTokenDuration  time.Duration `mapstructure:"ACCESS_TOKEN_DURATION"`
	RefreshTokenDuration time.Duration `mapstructure:"REFRESH_TOKEN_DURATION"`
	APIBasePath          string        `mapstructure:"API_BASE_PATH"`
	SwagAPIBasePath      string        `mapstructure:"SWAG_API_BASE_PATH"`
	GlabsAppID           string        `mapstructure:"GLABS_APP_ID"`
	GlabsAppSecret       string        `mapstructure:"GLABS_APP_SECRET"`
	EnableConsoleLogging bool          `mapstructure:"ENABLE_CONSOLE_LOGGING"`
	EnableFileLogging    bool          `mapstructure:"ENABLE_FILE_LOGGING"`
	LogLevel             string        `mapstructure:"LOG_LEVEL"`
	LogDirectory         string        `mapstructure:"LOG_DIRECTORY"`
	LogFilename          string        `mapstructure:"LOG_FILENAME"`
	LogMaxSize           int           `mapstructure:"LOG_MAX_SIZE"`
	LogMaxBackups        int           `mapstructure:"LOG_MAX_BACKUPS"`
	LogMaxAge            int           `mapstructure:"LOG_MAX_AGE"`
	CronJobs             string        `mapstructure:"CRON_JOBS"`
}

Config store all configuration of the application. Values are read by viper from a config file or environment variables.

func LoadConfig

func LoadConfig(path string) (config Config, err error)

LoadConfig read configuration from file or environment variables.

type Date

type Date struct {
	time.Time
}

Date represents a date-only value

func (*Date) Fake

func (c *Date) Fake(f *gofakeit.Faker) (any, error)

Fake implements the gofakeit.Faker interface

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (Date) String

func (d Date) String() string

String implements the Stringer interface for Date

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type DockerPostgres

type DockerPostgres struct {
	Source string
	Conn   *pgxpool.Pool
	// contains filtered or unexported fields
}

func NewDockerPostgres

func NewDockerPostgres() *DockerPostgres

func (*DockerPostgres) Close

func (pg *DockerPostgres) Close()

type Float4

type Float4 struct {
	pgtype.Float4
}

func (Float4) MarshalJSON

func (src Float4) MarshalJSON() ([]byte, error)

MarshalJSON for NullFloat4

func (*Float4) UnmarshalJSON

func (dst *Float4) UnmarshalJSON(b []byte) error

UnmarshalJSON for NullFloat4

type PaginatedList

type PaginatedList[T any] struct {
	Page       int32 `json:"page"`
	PerPage    int32 `json:"per_page"`
	TotalPages int32 `json:"total_pages"`
	NextPage   int32 `json:"next_page"`
	PrevPage   int32 `json:"prev_page"`
	Count      int32 `json:"count"`
	Items      []T   `json:"items"`
}

func NewPaginatedList

func NewPaginatedList[T any](page, limit, count int32, items []T) PaginatedList[T]

type Point

type Point struct {
	*geom.Point
}

func (*Point) Scan

func (p *Point) Scan(src interface{}) error

Scan implements the database/sql Scanner interface.

func (*Point) Value

func (p *Point) Value() (driver.Value, error)

Value implements the database/sql/driver Valuer interface.

type Province

type Province string

func (*Province) Fake

func (c *Province) Fake(f *gofakeit.Faker) (any, error)

type Region

type Region string

func (*Region) Fake

func (c *Region) Fake(f *gofakeit.Faker) (any, error)

type RegionNumerical

type RegionNumerical string

func (*RegionNumerical) Fake

func (c *RegionNumerical) Fake(f *gofakeit.Faker) (any, error)

Jump to

Keyboard shortcuts

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