utils

package
v0.0.81 Latest Latest
Warning

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

Go to latest
Published: May 19, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TenantHeaders = []string{
	"X-TENANT",
	"x-tenant",
	"X-Tenant",
	"tenant",
	"Tenant",
	"TENANT",
	"tenantname",
	"TenantName",
	"tenantName",
	"TENANTNAME",
}

TenantHeaders is a list of possible header names for tenant identification

View Source
var UserIdHeaders = []string{
	"X-USER-ID",
	"X-USERID",
	"X-User-Id",
	"X-UserId",
	"X-User-ID",
	"X-Userid",
	"x-user-id",
	"User-ID",
	"UserId",
	"Userid",
	"USERID",
}

Functions

func AddOneMonthFallbackToLastDayOfMonth

func AddOneMonthFallbackToLastDayOfMonth(date time.Time) time.Time

func CloseToNow

func CloseToNow(t time.Time) bool

func ConvertTimeToTimestampPtr

func ConvertTimeToTimestampPtr(input *time.Time) *timestamppb.Timestamp

func ConvertToUTC

func ConvertToUTC(datetimeStr string) (time.Time, error)

func Decode

func Decode(input map[string]any, result any) error

func EndOfDayInUTC

func EndOfDayInUTC(t time.Time) time.Time

func ExtractDomain added in v0.0.35

func ExtractDomain(input string) string

func FirstTimeOfMonth

func FirstTimeOfMonth(year, month int) time.Time

func GenerateEventID

func GenerateEventID() string

func GenerateNanoID

func GenerateNanoID(length int) string

func GenerateNanoIDWithPrefix

func GenerateNanoIDWithPrefix(prefix string, length int) string

func GetCurrentTimeInTimeZone

func GetCurrentTimeInTimeZone(timezone string) time.Time

func GetDomainWithoutTLD added in v0.0.36

func GetDomainWithoutTLD(domain string) string

GetDomainWithoutTLD returns everything before the last dot in the domain

func GetTenantFromContext

func GetTenantFromContext(ctx context.Context) string

func GetUserEmailFromContext

func GetUserEmailFromContext(ctx context.Context) string

func GetUserIdFromContext

func GetUserIdFromContext(ctx context.Context) string

func IsAfter

func IsAfter(t1, t2 *time.Time) bool

IsAfter compares two *time.Time, considering nil as far in the future. if both are nil return false

func IsEndOfMonth

func IsEndOfMonth(t time.Time) bool

func IsEqualTimePtr

func IsEqualTimePtr(t1, t2 *time.Time) bool

IsEqualTimePtr compares two *time.Time values and returns true if both are nil or if both point to the same time.

func IsInFuture

func IsInFuture(timestamp time.Time) bool

func IsLowerAlphanumeric

func IsLowerAlphanumeric(s string) bool

func IsStringInSlice added in v0.0.35

func IsStringInSlice(s string, slice []string) bool

func IsSuspiciousURL

func IsSuspiciousURL(url string) bool

func IsValidDomain added in v0.0.36

func IsValidDomain(input string) bool

func IsValidTLD added in v0.0.35

func IsValidTLD(input string) bool

func LastDayOfMonth

func LastDayOfMonth(year, month int) time.Time

func LastTimeOfMonth

func LastTimeOfMonth(year, month int) time.Time

func MatchPattern added in v0.0.80

func MatchPattern(s, pattern string) bool

MatchPattern checks if a string matches a given regex pattern

func MiddleTimeOfMonth

func MiddleTimeOfMonth(year, month int) time.Time

func NormalizeUrlPath

func NormalizeUrlPath(s string) string

func Now

func Now() time.Time

func NowIfZero

func NowIfZero(t time.Time) time.Time

func NowPtr

func NowPtr() *time.Time

func SanitizeUTF8

func SanitizeUTF8(input string) string

func SetAppSourceInContext

func SetAppSourceInContext(ctx context.Context, appSource string) context.Context

func SetTenantInContext

func SetTenantInContext(ctx context.Context, tenant string) context.Context

func SetUserIdInContext

func SetUserIdInContext(ctx context.Context, userId string) context.Context

func SortUrlsByLength

func SortUrlsByLength(urls []string) []string

func StartOfDayInUTC

func StartOfDayInUTC(t time.Time) time.Time

func StripUrlToBasePath

func StripUrlToBasePath(s string) string

func TimeOrNowFromPtr

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

func TimePtr

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

func TimestampProtoToTime

func TimestampProtoToTime(pbTime *timestamppb.Timestamp) time.Time

func TimestampProtoToTimePtr

func TimestampProtoToTimePtr(pbTime *timestamppb.Timestamp) *time.Time

func ToDate

func ToDate(t time.Time) time.Time

func ToDateAsAny

func ToDateAsAny(t *time.Time) interface{}

func ToDatePtr

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

func ToHookFunc

func ToHookFunc() mapstructure.DecodeHookFunc

func Today

func Today() time.Time

func URLContainsRandomString

func URLContainsRandomString(s string) bool

func UnmarshalDateTime

func UnmarshalDateTime(input string) (*time.Time, error)

func ValidateTenant

func ValidateTenant(ctx context.Context) error

func ValidateUserId

func ValidateUserId(ctx context.Context) error

func WithContext

func WithContext(customContext *CustomContext, next http.Handler) http.Handler

func WithCustomContext

func WithCustomContext(ctx context.Context, customContext *CustomContext) context.Context

func WithCustomContextFromGinRequest

func WithCustomContextFromGinRequest(c *gin.Context) context.Context

func WithCustomContextFromNats

func WithCustomContextFromNats(ctx context.Context, msg *nats.Msg) context.Context

func WithTenant

func WithTenant(ctx context.Context, tenant string) context.Context

WithTenant adds tenant to context

func WithTenantContext

func WithTenantContext(ctx context.Context, tenant string) context.Context

WithTenantContext creates a new context with the specified tenant

func WithUserId

func WithUserId(ctx context.Context, userID string) context.Context

WithUserId adds user ID to context

func ZeroTime

func ZeroTime() time.Time

Types

type CustomContext

type CustomContext struct {
	Tenant    string
	UserId    string
	UserEmail string
	RequestID string
}

func GetContext

func GetContext(ctx context.Context) *CustomContext

type URLComponents

type URLComponents struct {
	URL          string
	Protocol     string
	Host         string
	Path         string
	PathSegments []string
	QueryRaw     string
	QueryParams  map[string][]string
	Anchor       string
}

func ParseURL

func ParseURL(rawURL string) (*URLComponents, error)

type UserAgent

type UserAgent struct {
	Raw            string
	Browser        string
	BrowserVersion string
	Engine         string
	EngineVersion  string
	OS             string
	OSVersion      string
	Device         string
	DeviceModel    string
	IsMobile       bool
	IsTablet       bool
	IsBot          bool
	IsWebView      bool
	SocialPlatform string
}

func ParseUserAgent

func ParseUserAgent(userAgentString string) UserAgent

ParseUserAgent parses a user agent string into structured information

type YearMonth

type YearMonth struct {
	Year  int
	Month time.Month
}

func GenerateYearMonths

func GenerateYearMonths(start, end time.Time) []YearMonth

Jump to

Keyboard shortcuts

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