utils

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 FirstTimeOfMonth

func FirstTimeOfMonth(year, month int) time.Time

func GenerateMessageID

func GenerateMessageID(domain, metadata string) string

generateMessageID creates a unique message ID for the email

func GenerateNanoIDWithPrefix

func GenerateNanoIDWithPrefix(prefix string, length int) string

func GetAppSourceFromContext

func GetAppSourceFromContext(ctx context.Context) string

func GetAuthUserIdFromContext

func GetAuthUserIdFromContext(ctx context.Context) string

func GetCurrentTimeInTimeZone

func GetCurrentTimeInTimeZone(timezone string) time.Time

func GetRolesFromContext

func GetRolesFromContext(ctx context.Context) []string

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 IsImpersonatedUserInContext

func IsImpersonatedUserInContext(ctx context.Context) 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 Now

func Now() time.Time

func NowIfZero

func NowIfZero(t time.Time) time.Time

func NowPtr

func NowPtr() *time.Time

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 StartOfDayInUTC

func StartOfDayInUTC(t time.Time) time.Time

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 UnmarshalDateTime

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

func ValidateTenant

func ValidateTenant(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, appSource string) context.Context

func ZeroTime

func ZeroTime() time.Time

Types

type CustomContext

type CustomContext struct {
	AppSource  string
	Tenant     string
	AuthUserId string
	UserId     string
	UserEmail  string
	Roles      []string
}

func GetContext

func GetContext(ctx context.Context) *CustomContext

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