Spaces:
Runtime error
Runtime error
Download utils/utils.go from lifedebugger/quzuu-api-dev-v2: direct link, hf CLI and curl.
- Browser
- Download file 990 Bytes
-
https://huggingface.co/spaces/lifedebugger/quzuu-api-dev-v2/resolve/main/utils/utils.go
- Command line
-
hf download hf://spaces/lifedebugger/quzuu-api-dev-v2/utils/utils.go
-
curl -L -o utils.go https://huggingface.co/spaces/lifedebugger/quzuu-api-dev-v2/resolve/main/utils/utils.go
990 Bytes
| package utils | |
| import ( | |
| "time" | |
| models "abdanhafidz.com/go-boilerplate/models/entity" | |
| http_error "abdanhafidz.com/go-boilerplate/models/error" | |
| "github.com/google/uuid" | |
| ) | |
| func ToUUID(s any) (uuid.UUID, error) { | |
| sStr, ok := s.(string) | |
| if !ok { | |
| return uuid.UUID{}, http_error.INTERNAL_SERVER_ERROR | |
| } | |
| res, err := uuid.Parse(sStr) | |
| if err != nil { | |
| return uuid.UUID{}, http_error.INTERNAL_SERVER_ERROR | |
| } | |
| return res, nil | |
| } | |
| func CalculateRemainingTime(startTime, dueTime time.Time) int { | |
| now := time.Now() | |
| if startTime.After(now) { | |
| return int(dueTime.Sub(startTime).Seconds()) | |
| } | |
| remaining := int(dueTime.Sub(now).Seconds()) | |
| if remaining < 0 { | |
| return 0 | |
| } | |
| return remaining / 60 | |
| } | |
| func Ptr[T any](v T) *T { | |
| return &v | |
| } | |
| func TimePtrToString(t *time.Time) *string { | |
| if t == nil { | |
| return nil | |
| } | |
| s := t.Format(time.RFC3339) | |
| return &s | |
| } | |
| func ValidateCode(code string) error { | |
| if !models.CodeRegex.MatchString(code) { | |
| return http_error.INVALID_CODE | |
| } | |
| return nil | |
| } | |