utils

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: Apache-2.0 Imports: 17 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 EndOfDayInUTC

func EndOfDayInUTC(t time.Time) time.Time

func ExtractDomainFromEmail added in v0.0.23

func ExtractDomainFromEmail(email string) string

func FirstTimeOfMonth

func FirstTimeOfMonth(year, month int) time.Time

func GenerateIMAPHash added in v0.2.4

func GenerateIMAPHash(mailboxID, folder string, uid uint32) string

func GenerateKey added in v0.0.3

func GenerateKey(length int, includeSpecial bool) string

func GenerateLowerAlpha added in v0.0.3

func GenerateLowerAlpha(length int) string

func GenerateMessageID

func GenerateMessageID(domain, metadata string) string

generateMessageID creates a unique message ID for the email

func GenerateNanoID added in v0.0.3

func GenerateNanoID(length int) string

func GenerateNanoIDWithPrefix

func GenerateNanoIDWithPrefix(prefix string, length int) string

func GetCurrentTimeInTimeZone

func GetCurrentTimeInTimeZone(timezone string) time.Time

func GetFileExtensionFromContentType added in v0.1.5

func GetFileExtensionFromContentType(contentType string) string

func GetOrDefault added in v0.1.6

func GetOrDefault[T any](ptr *T, defaultVal T) T

GetOrDefault returns the value if the pointer is not nil, otherwise returns the default value

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 IntPtr added in v0.0.3

func IntPtr(i int) *int

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 added in v0.1.6

func IsInFuture(timestamp time.Time) bool

func IsStringInSlice added in v0.0.3

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

func LastDayOfMonth

func LastDayOfMonth(year, month int) time.Time

func LastTimeOfMonth

func LastTimeOfMonth(year, month int) time.Time

func MiddleTimeOfMonth

func MiddleTimeOfMonth(year, month int) time.Time

func NormalizeMessageID added in v0.0.3

func NormalizeMessageID(messageID string) string

func NormalizeSubject added in v0.0.3

func NormalizeSubject(subject string) string

func Now

func Now() time.Time

func NowIfZero

func NowIfZero(t time.Time) time.Time

func NowPtr

func NowPtr() *time.Time

func SanitizeFilename added in v0.2.5

func SanitizeFilename(filename string) string

sanitizeFilename removes or replaces characters that might be problematic in filenames

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 SliceToString added in v0.0.3

func SliceToString(slice []string) string

func StartOfDayInUTC

func StartOfDayInUTC(t time.Time) time.Time

func StringPtr added in v0.0.3

func StringPtr(s string) *string

func StringToSlice added in v0.0.3

func StringToSlice(str 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 Today

func Today() time.Time

func UniqueEmails added in v0.0.3

func UniqueEmails(emails []string) []string

func UnmarshalDateTime

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

func ValidateTenant

func ValidateTenant(ctx context.Context) error

func ValidateUserId added in v0.1.19

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 WithTenant added in v0.2.1

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

WithTenant adds tenant to context

func WithTenantContext added in v0.0.21

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

WithTenantContext creates a new context with the specified tenant

func WithUserId added in v0.2.1

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 EventCompletedDetails added in v0.1.6

type EventCompletedDetails struct {
	Create bool
	Update bool
	Delete bool
}

func NewEventCompletedDetails added in v0.1.6

func NewEventCompletedDetails() *EventCompletedDetails

func (*EventCompletedDetails) WithCreate added in v0.1.6

func (ecd *EventCompletedDetails) WithCreate() *EventCompletedDetails

func (*EventCompletedDetails) WithDelete added in v0.1.6

func (ecd *EventCompletedDetails) WithDelete() *EventCompletedDetails

func (*EventCompletedDetails) WithUpdate added in v0.1.6

func (ecd *EventCompletedDetails) WithUpdate() *EventCompletedDetails

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