helpers

package
v0.0.0-...-f5fa5b5 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: GPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TimeFormatMap = map[string]string{

	"y": "06",
	"Y": "2006",

	"n": "1",
	"m": "01",

	"j": "2",
	"d": "02",

	"g": "3",

	"h": "03",
	"H": "15",
	"i": "04",
	"s": "05",
	"u": ".000000",
	"v": ".000",

	"e": "MST",
	"O": "-0700",
	"P": "-07:00",

	"U":            "1136239445",
	"c":            "2006-01-02T15:04:05-07:00",
	"r":            "Mon, 02 Jan 2006 15:04:05 -0700",
	"RFC3339":      "2006-01-02T15:04:05Z07:00",
	"RFC3339Micro": "2006-01-02T15:04:05.999Z07:00",
	"RFC3339Milli": "2006-01-02T15:04:05.999999Z07:00",
	"RFC3339Nano":  "2006-01-02T15:04:05.999999999Z07:00",
	"a":            "pm",
	"A":            "PM",
	"M":            "Jan",
	"F":            "January",
	"D":            "Mon",
	"l":            "Monday",
}

conversion from https://www.php.net/manual/en/function.date.php to https://golang.org/src/time/format.go

Functions

func AddDateTime

func AddDateTime(unit string, src string, n int, format string) string

func CheckAcl

func CheckAcl(ctx Context, key string) bool

func Connect

func Connect() *gorm.DB

func DecodeToken

func DecodeToken(token string) map[string]interface{}

func DeletedMessage

func DeletedMessage(object, key, id string) map[string]interface{}

func DotNotationSet

func DotNotationSet(json, path string, value interface{}) string

func DotToInterface

func DotToInterface(data []map[string]interface{}, schema map[string]interface{}) []map[string]interface{}

func EncodeToken

func EncodeToken(id, access_token, refresh_token string) string

func ErrorEmailAlreadyBeenTaken

func ErrorEmailAlreadyBeenTaken(ctx Context) (map[string]interface{}, error)

func ErrorHasAwaitingPaymentInvoice

func ErrorHasAwaitingPaymentInvoice(ctx Context) (map[string]interface{}, error)

func ErrorInvoiceAmountIsZero

func ErrorInvoiceAmountIsZero(ctx Context) (map[string]interface{}, error)

func ErrorPhoneAlreadyBeenTaken

func ErrorPhoneAlreadyBeenTaken(ctx Context) (map[string]interface{}, error)

func Float64ToCurrency

func Float64ToCurrency(n float64) string

func GeneralErrorMessage

func GeneralErrorMessage(code int, message string, detail map[string]interface{}) map[string]interface{}

func GetAclKeyFromRequest

func GetAclKeyFromRequest(ctx Context) string

func GetById

func GetById(ctx Context, object, key, id string, params map[string][]string, schema map[string]interface{}) map[string]interface{}

func GetCurrentTime

func GetCurrentTime(format string) string

func GetDB

func GetDB(ctx Context) *gorm.DB

func GetEndOfMonth

func GetEndOfMonth(date string) (string, error)

func GetHasMayData

func GetHasMayData(ctx Context, data map[string]interface{}, schema map[string]interface{}) map[string]interface{}

func GetPaginated

func GetPaginated(ctx Context, params map[string][]string, schema map[string]interface{}) map[string]interface{}

func GetPeriodFromDate

func GetPeriodFromDate(date string, dateStart string) string

func GetResults

func GetResults(rows *sql.Rows) []map[string]interface{}

func GetStructName

func GetStructName(s interface{}) string

func GetUserLanguage

func GetUserLanguage(ctx Context, UserID string) string

func Hash

func Hash(password string) ([]byte, error)

func HaveArrayDate

func HaveArrayDate(params map[string][]string) bool

func InArray

func InArray(val interface{}, array interface{}) (exists bool, index int)

func InternalErrorMessage

func InternalErrorMessage(message string) map[string]interface{}

func IsEndOfMonth

func IsEndOfMonth(date string) bool

func IsEndOfYearDate

func IsEndOfYearDate(date string) bool

func IsInArray

func IsInArray(val string, array []string) bool

func IsRecordNotFoundError

func IsRecordNotFoundError(err error) bool

func IsStartOfYearDate

func IsStartOfYearDate(date string) bool

func NewToken

func NewToken() string

func NewUUID

func NewUUID() string

func NotFoundMessage

func NotFoundMessage(object, key, id string) map[string]interface{}

func ParsingDate

func ParsingDate(src string, formatFrom string, formatTo string) string

func RandomString

func RandomString(n int) string

func Response

func Response(c echo.Context, code int, res map[string]interface{}) error

func ResponseInternalError

func ResponseInternalError(c echo.Context, e error) error

func SetAuthContext

func SetAuthContext(ctx Context, ti *Oauth2Token)

func SetFilterDate

func SetFilterDate(params map[string][]string, tipe string)

func SetPage

func SetPage(db *gorm.DB, params map[string][]string, count int64) (*gorm.DB, map[string]int64)

page=1&per_page=10

func StructToMap

func StructToMap(s interface{}) map[string]interface{}

func SuccessResponse

func SuccessResponse(c echo.Context, statusCode int, res interface{})

func TimeFormatPhpToGo

func TimeFormatPhpToGo(format string) string

func ToCamelCase

func ToCamelCase(str string) string

func ToSnakeCase

func ToSnakeCase(str string) string

func Validate

func Validate(ctx Context, i interface{}) (bool, map[string]interface{})

func VerifyHash

func VerifyHash(hashed, value string) error

Types

type Context

type Context echo.Context

func SetContext

func SetContext(c echo.Context) Context

type Ctx

type Ctx struct {
	C echo.Context
}

func GetCtx

func GetCtx(ctx Context) *Ctx

func NewCtx

func NewCtx(ctx echo.Context) *Ctx

func (*Ctx) AccessToken

func (ctx *Ctx) AccessToken() string

func (*Ctx) ClientID

func (ctx *Ctx) ClientID() string

func (*Ctx) DB

func (ctx *Ctx) DB() *gorm.DB

func (*Ctx) ErrorMessage

func (ctx *Ctx) ErrorMessage() map[string]interface{}

func (*Ctx) SetErrorMessage

func (ctx *Ctx) SetErrorMessage(ErrorMessage map[string]interface{})

func (*Ctx) Tx

func (ctx *Ctx) Tx() *gorm.DB

func (*Ctx) UserID

func (ctx *Ctx) UserID() string

func (*Ctx) UserLang

func (ctx *Ctx) UserLang() string

type Iconvert

type Iconvert struct {
	Val interface{}
}

func Convert

func Convert(val interface{}) Iconvert

func (Iconvert) Int

func (v Iconvert) Int() int

func (Iconvert) String

func (v Iconvert) String() string

type Oauth2Client

type Oauth2Client struct {
	ID        string `gorm:"type:varchar(32)"`
	Name      string `gorm:"type:varchar(255)"`
	Secret    string `gorm:"type:varchar(255)"`
	UserID    string `gorm:"type:char(36);index:oauth2_client_user_id"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

type Oauth2Manager

type Oauth2Manager struct {
	Tx *gorm.DB

	// request auth code
	ClientID    string `json:"client_id" form:"client_id" query:"client_id"`
	RedirectUri string `query:"redirect_uri"`
	Scope       string `query:"scope"`
	State       string `query:"state"`

	// request access token
	// ClientID     string
	ClientSecret string `json:"client_secret" form:"client_secret" query:"client_secret"`
	GrantType    string `json:"grant_type" form:"grant_type" query:"grant_type"`
	Code         string `json:"code" form:"code" query:"code"`
	Username     string `json:"username" form:"username" query:"username"`
	Password     string `json:"password" form:"password" query:"password"`
	RefreshToken string `json:"refresh_token" form:"refresh_token" query:"refresh_token"`
}

func (*Oauth2Manager) CheckRefreshToken

func (o *Oauth2Manager) CheckRefreshToken(t *Oauth2Token) (*Oauth2Token, error)

func (*Oauth2Manager) ClientLogin

func (o *Oauth2Manager) ClientLogin() (*Oauth2Token, error)

func (*Oauth2Manager) GenerateAccessToken

func (o *Oauth2Manager) GenerateAccessToken(ctx Context) (*Oauth2Token, error)

func (*Oauth2Manager) GenerateAuthToken

func (o *Oauth2Manager) GenerateAuthToken(ctx Context) (string, error)

todo

func (*Oauth2Manager) Oauth2AuthorizationCode

func (o *Oauth2Manager) Oauth2AuthorizationCode() (*Oauth2Token, error)

todo

func (*Oauth2Manager) Oauth2ClientCredentials

func (o *Oauth2Manager) Oauth2ClientCredentials() (*Oauth2Token, error)

func (*Oauth2Manager) Oauth2Implicit

func (o *Oauth2Manager) Oauth2Implicit() (*Oauth2Token, error)

todo

func (*Oauth2Manager) Oauth2PasswordCredentials

func (o *Oauth2Manager) Oauth2PasswordCredentials() (*Oauth2Token, error)

func (*Oauth2Manager) Oauth2Refreshing

func (o *Oauth2Manager) Oauth2Refreshing() (*Oauth2Token, error)

func (*Oauth2Manager) SaveToken

func (o *Oauth2Manager) SaveToken(t *Oauth2Token) (*Oauth2Token, error)

func (*Oauth2Manager) UserLogin

func (o *Oauth2Manager) UserLogin(t *Oauth2Token) (*Oauth2Token, error)

type Oauth2RedirectUrl

type Oauth2RedirectUrl struct {
	ID        string `gorm:"type:char(36)"`
	Url       string `gorm:"type:varchar(255)"`
	ClientID  string `gorm:"type:varchar(32);index:oauth2_redirect_url_client_id"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

type Oauth2Token

type Oauth2Token struct {
	ID              string    `json:"-" gorm:"type:char(36)"`
	Code            string    `json:"-" gorm:"type:varchar(32);index:oauth2_token_code"`
	UserID          string    `json:"-" gorm:"type:char(36);index:oauth2_token_user_id"`
	ClientID        string    `json:"-" gorm:"type:varchar(32);index:oauth2_token_client_id"`
	AccessToken     string    `json:"access_token" gorm:"type:varchar(32);index:oauth2_token_access_token"`
	TokenType       string    `json:"token_type" gorm:"-"`
	ExpireIn        int       `json:"expire_in" gorm:"-"`
	RefreshToken    string    `json:"refresh_token" gorm:"type:varchar(32);index:oauth2_token_refresh_token"`
	AccessExpiredAt time.Time `json:"-"`
	ExpiredAt       time.Time `json:"-"`
	CreatedAt       time.Time `json:"-"`
	UpdatedAt       time.Time `json:"-"`
}

func ValidateToken

func ValidateToken(ctx Context) (*Oauth2Token, error)

type User

type User struct {
	ID           string
	Email        string
	Phone        string
	Password     string
	LanguageCode string
}

type Validation

type Validation struct {
	Lang string
	I    interface{}
}

func (*Validation) BahasaIndonesiaTranslator

func (v *Validation) BahasaIndonesiaTranslator() ut.Translator

func (*Validation) Contains

func (v *Validation) Contains(val, param string) bool

Contains is the validation function for validating that the field's value contains the text specified within the param.

func (*Validation) ContainsAny

func (v *Validation) ContainsAny(val, param string) bool

ContainsAny is the validation function for validating that the field's value contains any of the characters specified within the param.

func (*Validation) ContainsRune

func (v *Validation) ContainsRune(val, param string) bool

ContainsRune is the validation function for validating that the field's value contains the rune specified within the param.

func (*Validation) EndsWith

func (v *Validation) EndsWith(val, param string) bool

EndsWith is the validation function for validating that the field's value ends with the text specified within the param.

func (*Validation) EnglishTranslator

func (v *Validation) EnglishTranslator() ut.Translator

func (*Validation) GetJsonTag

func (v *Validation) GetJsonTag(fld reflect.StructField) string

func (*Validation) HasMultiByteCharacter

func (v *Validation) HasMultiByteCharacter(val string) bool

HasMultiByteCharacter is the validation function for validating if the field's value has a multi byte character.

func (*Validation) IsASCII

func (v *Validation) IsASCII(val string) bool

IsASCII is the validation function for validating if the field's value is a valid ASCII character.

func (*Validation) IsAlpha

func (v *Validation) IsAlpha(val string) bool

IsAlpha is the validation function for validating if the current field's value is a valid alpha value.

func (*Validation) IsAlphaUnicode

func (v *Validation) IsAlphaUnicode(val string) bool

IsAlphaUnicode is the validation function for validating if the current field's value is a valid alpha unicode value.

func (*Validation) IsAlphanum

func (v *Validation) IsAlphanum(val string) bool

IsAlphanum is the validation function for validating if the current field's value is a valid alphanumeric value.

func (*Validation) IsAlphanumUnicode

func (v *Validation) IsAlphanumUnicode(val string) bool

IsAlphanumUnicode is the validation function for validating if the current field's value is a valid alphanumeric unicode value.

func (*Validation) IsBase64

func (v *Validation) IsBase64(val string) bool

IsBase64 is the validation function for validating if the current field's value is a valid base 64.

func (*Validation) IsBase64URL

func (v *Validation) IsBase64URL(val string) bool

IsBase64URL is the validation function for validating if the current field's value is a valid base64 URL safe string.

func (*Validation) IsCIDR

func (v *Validation) IsCIDR(val string) bool

IsCIDR is the validation function for validating if the field's value is a valid v4 or v6 CIDR address.

func (*Validation) IsCIDRv4

func (v *Validation) IsCIDRv4(val string) bool

IsCIDRv4 is the validation function for validating if the field's value is a valid v4 CIDR address.

func (*Validation) IsCIDRv6

func (v *Validation) IsCIDRv6(val string) bool

IsCIDRv6 is the validation function for validating if the field's value is a valid v6 CIDR address.

func (*Validation) IsDataURI

func (v *Validation) IsDataURI(val string) bool

IsDataURI is the validation function for validating if the field's value is a valid data URI.

func (*Validation) IsDate

func (v *Validation) IsDate(val string) bool

IsDate is the validation function for validating if the current field's value is a valid date string.

func (*Validation) IsDateTime

func (v *Validation) IsDateTime(val string) bool

IsDateTime is the validation function for validating if the current field's value is a valid datetime string.

func (*Validation) IsDir

func (v *Validation) IsDir(val string) bool

IsDir is the validation function for validating if the current field's value is a valid directory.

func (*Validation) IsE164

func (v *Validation) IsE164(val string) bool

IsE164 is the validation function for validating if the current field's value is a valid e.164 formatted phone number.

func (*Validation) IsEmail

func (v *Validation) IsEmail(val string) bool

IsEmail is the validation function for validating if the current field's value is a valid email address.

func (*Validation) IsFQDN

func (v *Validation) IsFQDN(val string) bool

func (*Validation) IsFile

func (v *Validation) IsFile(val string) bool

IsFile is the validation function for validating if the current field's value is a valid file path.

func (*Validation) IsHEXColor

func (v *Validation) IsHEXColor(val string) bool

IsHEXColor is the validation function for validating if the current field's value is a valid HEX color.

func (*Validation) IsHSL

func (v *Validation) IsHSL(val string) bool

IsHSL is the validation function for validating if the current field's value is a valid HSL color.

func (*Validation) IsHSLA

func (v *Validation) IsHSLA(val string) bool

IsHSLA is the validation function for validating if the current field's value is a valid HSLA color.

func (*Validation) IsHTML

func (v *Validation) IsHTML(val string) bool

func (*Validation) IsHTMLEncoded

func (v *Validation) IsHTMLEncoded(val string) bool

func (*Validation) IsHexadecimal

func (v *Validation) IsHexadecimal(val string) bool

IsHexadecimal is the validation function for validating if the current field's value is a valid hexadecimal.

func (*Validation) IsHostnamePort

func (v *Validation) IsHostnamePort(val string) bool

IsHostnamePort validates a <dns>:<port> combination for fields typically used for socket address.

func (*Validation) IsHostnameRFC1123

func (v *Validation) IsHostnameRFC1123(val string) bool

func (*Validation) IsHostnameRFC952

func (v *Validation) IsHostnameRFC952(val string) bool

func (*Validation) IsIP

func (v *Validation) IsIP(val string) bool

IsIP is the validation function for validating if the field's value is a valid v4 or v6 IP address.

func (*Validation) IsIP4Addr

func (v *Validation) IsIP4Addr(val string) bool

func (*Validation) IsIP4AddrResolvable

func (v *Validation) IsIP4AddrResolvable(val string) bool

IsIP4AddrResolvable is the validation function for validating if the field's value is a resolvable ip4 address.

func (*Validation) IsIP6Addr

func (v *Validation) IsIP6Addr(val string) bool

func (*Validation) IsIP6AddrResolvable

func (v *Validation) IsIP6AddrResolvable(val string) bool

IsIP6AddrResolvable is the validation function for validating if the field's value is a resolvable ip6 address.

func (*Validation) IsIPAddrResolvable

func (v *Validation) IsIPAddrResolvable(val string) bool

IsIPAddrResolvable is the validation function for validating if the field's value is a resolvable ip address.

func (*Validation) IsIPv4

func (v *Validation) IsIPv4(val string) bool

IsIPv4 is the validation function for validating if a value is a valid v4 IP address.

func (*Validation) IsIPv6

func (v *Validation) IsIPv6(val string) bool

IsIPv6 is the validation function for validating if the field's value is a valid v6 IP address.

func (*Validation) IsISBN

func (v *Validation) IsISBN(val string) bool

IsISBN is the validation function for validating if the field's value is a valid v10 or v13 ISBN.

func (*Validation) IsISBN10

func (v *Validation) IsISBN10(val string) bool

IsISBN10 is the validation function for validating if the field's value is a valid v10 ISBN.

func (*Validation) IsISBN13

func (v *Validation) IsISBN13(val string) bool

IsISBN13 is the validation function for validating if the field's value is a valid v13 ISBN.

func (*Validation) IsJSON

func (v *Validation) IsJSON(val string) bool

IsJSON is the validation function for validating if the current field's value is a valid json string.

func (*Validation) IsLatitude

func (v *Validation) IsLatitude(val string) bool

IsLatitude is the validation function for validating if the field's value is a valid latitude coordinate.

func (*Validation) IsLongitude

func (v *Validation) IsLongitude(val string) bool

IsLongitude is the validation function for validating if the field's value is a valid longitude coordinate.

func (*Validation) IsLowercase

func (v *Validation) IsLowercase(val string) bool

IsLowercase is the validation function for validating if the current field's value is a lowercase string.

func (*Validation) IsMAC

func (v *Validation) IsMAC(val string) bool

IsMAC is the validation function for validating if the field's value is a valid MAC address.

func (*Validation) IsNumber

func (v *Validation) IsNumber(val string) bool

IsNumber is the validation function for validating if the current field's value is a valid number.

func (*Validation) IsNumeric

func (v *Validation) IsNumeric(val string) bool

IsNumeric is the validation function for validating if the current field's value is a valid numeric value.

func (*Validation) IsPrintableASCII

func (v *Validation) IsPrintableASCII(val string) bool

IsPrintableASCII is the validation function for validating if the field's value is a valid printable ASCII character.

func (*Validation) IsRGB

func (v *Validation) IsRGB(val string) bool

IsRGB is the validation function for validating if the current field's value is a valid RGB color.

func (*Validation) IsRGBA

func (v *Validation) IsRGBA(val string) bool

IsRGBA is the validation function for validating if the current field's value is a valid RGBA color.

func (*Validation) IsSSN

func (v *Validation) IsSSN(val string) bool

IsSSN is the validation function for validating if the field's value is a valid SSN.

func (*Validation) IsTCP4AddrResolvable

func (v *Validation) IsTCP4AddrResolvable(val string) bool

IsTCP4AddrResolvable is the validation function for validating if the field's value is a resolvable tcp4 address.

func (*Validation) IsTCP6AddrResolvable

func (v *Validation) IsTCP6AddrResolvable(val string) bool

IsTCP6AddrResolvable is the validation function for validating if the field's value is a resolvable tcp6 address.

func (*Validation) IsTCPAddrResolvable

func (v *Validation) IsTCPAddrResolvable(val string) bool

IsTCPAddrResolvable is the validation function for validating if the field's value is a resolvable tcp address.

func (*Validation) IsTime

func (v *Validation) IsTime(val string) bool

IsTime is the validation function for validating if the current field's value is a valid time string.

func (*Validation) IsUDP4AddrResolvable

func (v *Validation) IsUDP4AddrResolvable(val string) bool

IsUDP4AddrResolvable is the validation function for validating if the field's value is a resolvable udp4 address.

func (*Validation) IsUDP6AddrResolvable

func (v *Validation) IsUDP6AddrResolvable(val string) bool

IsUDP6AddrResolvable is the validation function for validating if the field's value is a resolvable udp6 address.

func (*Validation) IsUDPAddrResolvable

func (v *Validation) IsUDPAddrResolvable(val string) bool

IsUDPAddrResolvable is the validation function for validating if the field's value is a resolvable udp address.

func (*Validation) IsURI

func (v *Validation) IsURI(s string) bool

IsURI is the validation function for validating if the current field's value is a valid URI.

func (*Validation) IsURL

func (v *Validation) IsURL(s string) bool

IsURL is the validation function for validating if the current field's value is a valid URL.

func (*Validation) IsURLEncoded

func (v *Validation) IsURLEncoded(val string) bool

func (*Validation) IsUUID

func (v *Validation) IsUUID(val string) bool

IsUUID is the validation function for validating if the field's value is a valid UUID of any version.

func (*Validation) IsUUID3

func (v *Validation) IsUUID3(val string) bool

IsUUID3 is the validation function for validating if the field's value is a valid v3 UUID.

func (*Validation) IsUUID3RFC4122

func (v *Validation) IsUUID3RFC4122(val string) bool

IsUUID3RFC4122 is the validation function for validating if the field's value is a valid RFC4122 v3 UUID.

func (*Validation) IsUUID4

func (v *Validation) IsUUID4(val string) bool

IsUUID4 is the validation function for validating if the field's value is a valid v4 UUID.

func (*Validation) IsUUID4RFC4122

func (v *Validation) IsUUID4RFC4122(val string) bool

IsUUID4RFC4122 is the validation function for validating if the field's value is a valid RFC4122 v4 UUID.

func (*Validation) IsUUID5

func (v *Validation) IsUUID5(val string) bool

IsUUID5 is the validation function for validating if the field's value is a valid v5 UUID.

func (*Validation) IsUUID5RFC4122

func (v *Validation) IsUUID5RFC4122(val string) bool

IsUUID5RFC4122 is the validation function for validating if the field's value is a valid RFC4122 v5 UUID.

func (*Validation) IsUUIDRFC4122

func (v *Validation) IsUUIDRFC4122(val string) bool

IsUUIDRFC4122 is the validation function for validating if the field's value is a valid RFC4122 UUID of any version.

func (*Validation) IsUnixAddrResolvable

func (v *Validation) IsUnixAddrResolvable(val string) bool

IsUnixAddrResolvable is the validation function for validating if the field's value is a resolvable unix address.

func (*Validation) IsUppercase

func (v *Validation) IsUppercase(val string) bool

IsUppercase is the validation function for validating if the current field's value is an uppercase string.

func (*Validation) IsUrnRFC2141

func (v *Validation) IsUrnRFC2141(val string) bool

IsUrnRFC2141 is the validation function for validating if the current field's value is a valid URN as per RFC 2141.

func (*Validation) IsValidUUID

func (v *Validation) IsValidUUID(u string) bool

func (*Validation) Response

func (v *Validation) Response(trans ut.Translator) (bool, map[string]interface{})

func (*Validation) SetTranslator

func (v *Validation) SetTranslator() ut.Translator

func (*Validation) StartsWith

func (v *Validation) StartsWith(val, param string) bool

StartsWith is the validation function for validating that the field's value starts with the text specified within the param.

Jump to

Keyboard shortcuts

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