util

package
v1.1.0-32 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RFC3339Mili is a modification of RFC3339Nano to only include ms (3 decimal places)
	RFC3339Mili = "2006-01-02T15:04:05.999Z07:00"
	// DateFormat used for things such as date of birth (when time does not matter)
	DateFormat = "2006-01-02"
)

https://golang.org/pkg/time/#pkg-constants

Variables

View Source
var (
	// ErrNoMatchFound ...
	ErrNoMatchFound = errors.New("No match found")
)

Functions

func FloatOrNull

func FloatOrNull(n float64) sql.NullFloat64

FloatOrNull returns properly configured sql.NullFloat64

func FormatDate

func FormatDate(timestamp *time.Time) string

FormatDate formats a time object to a date only format, e.g. 2006-01-02

func FormatTime

func FormatTime(timestamp *time.Time) string

FormatTime formats a time object to RFC3339 with ms precision

func GetCurrentURL

func GetCurrentURL(r *http.Request) string

GetCurrentURL returns the current request URL

func IntOrNull

func IntOrNull(n int64) sql.NullInt64

IntOrNull returns properly configured sql.NullInt64

func IsValidUUID added in v1.0.5

func IsValidUUID(u string) bool

func NewSecure

func NewSecure(isDevelopment bool) *secure.Secure

NewSecure returns instance of secure.Secure to redirect http to https

func ParseBearerToken

func ParseBearerToken(r *http.Request) ([]byte, error)

ParseBearerToken parses Bearer token from Authorization header

func ParseDate

func ParseDate(timestamp string) (*time.Time, error)

ParseDate parses a string representation of a date format and returns a time.Time instance

func ParseTimestamp

func ParseTimestamp(timestamp string) (*time.Time, error)

ParseTimestamp parses a string representation of a timestamp in RFC3339 format and returns a time.Time instance

func PositiveFloatOrNull

func PositiveFloatOrNull(n float64) sql.NullFloat64

PositiveFloatOrNull returns properly configured sql.NullFloat64 for a positive number

func PositiveIntOrNull

func PositiveIntOrNull(n int64) sql.NullInt64

PositiveIntOrNull returns properly configured sql.NullInt64 for a positive number

func RegexExtractMatch

func RegexExtractMatch(in, regularExpression, name string) (string, error)

RegexExtractMatch extracts a named match from a string using regex

func RegexExtractMatches

func RegexExtractMatches(in, regExp string, names ...string) (map[string]string, error)

RegexExtractMatches extracts multiple named matches from a string using regex

func SpaceDelimitedStringNotGreater

func SpaceDelimitedStringNotGreater(first, second string) bool

SpaceDelimitedStringNotGreater returns true if the first string is the same as the second string or does not contain any substring not contained in the second string (when split by space)

func StringInSlice

func StringInSlice(a string, list []string) bool

StringInSlice is a function similar to "x in y" Python construct

func StringOrNull

func StringOrNull(str string) sql.NullString

StringOrNull returns properly configured sql.NullString

func TimeOrNull

func TimeOrNull(t *time.Time) pq.NullTime

TimeOrNull returns properly confiigured pq.TimeNull

func ValidateEmail

func ValidateEmail(email string) bool

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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