validation

package
v0.0.0-...-1762b78 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EmailField = "email"
	PhoneField = "phone"
)

Variables

This section is empty.

Functions

func HasOnlyDigits

func HasOnlyDigits(s *string) bool

func IsAlpha

func IsAlpha(s string) bool

IsAlpha returns true if s contains only letters

func IsAntiPhishingCodeValid

func IsAntiPhishingCodeValid(in string) bool

func IsCountryCallingCodeValid

func IsCountryCallingCodeValid(country, callingCode string) bool

func IsEmailValid

func IsEmailValid(email string) bool

func IsIpv4Valid

func IsIpv4Valid(ip string) bool

func IsIpv6Valid

func IsIpv6Valid(ip string) bool

func IsNameValid

func IsNameValid(name string) bool

IsNameValid allows names with no less than 2 characters

func IsOlderThan

func IsOlderThan(birthdate time.Time, years int) bool

func IsPasswordValid

func IsPasswordValid(s string) bool

Types

type Error

type Error struct {
	Name  string         `json:"name"`
	Codes []ErrorDetails `json:"codes"`
}

type ErrorDetails

type ErrorDetails struct {
	Message string `json:"message"`
	Code    string `json:"code"`
}

func EitherPhoneOrEmail

func EitherPhoneOrEmail() ErrorDetails

func EmptyBirthDate

func EmptyBirthDate() ErrorDetails

func EmptyDevice

func EmptyDevice() ErrorDetails

func EmptyPassword

func EmptyPassword() ErrorDetails

func EmptyRefreshToken

func EmptyRefreshToken() ErrorDetails

func Invalid2FAMethod

func Invalid2FAMethod() ErrorDetails

func InvalidAction

func InvalidAction() ErrorDetails

func InvalidAntiPhishingCode

func InvalidAntiPhishingCode() ErrorDetails

func InvalidCode

func InvalidCode() ErrorDetails

func InvalidConfirmPassword

func InvalidConfirmPassword() ErrorDetails

func InvalidCountryCallingCodeFormat

func InvalidCountryCallingCodeFormat() ErrorDetails

func InvalidEmail

func InvalidEmail() ErrorDetails

func InvalidIPAddress

func InvalidIPAddress(ip string) ErrorDetails

func InvalidKey

func InvalidKey() ErrorDetails

func InvalidKeys

func InvalidKeys() ErrorDetails

func InvalidOrderColumn

func InvalidOrderColumn() ErrorDetails

func InvalidOtpCode

func InvalidOtpCode() ErrorDetails

func InvalidPageLimit

func InvalidPageLimit() ErrorDetails

func InvalidPassword

func InvalidPassword() ErrorDetails

func InvalidPhone

func InvalidPhone() ErrorDetails

func InvalidResetToken

func InvalidResetToken() ErrorDetails

func NameIsTooShort

func NameIsTooShort() ErrorDetails

func NotOnlyLetters

func NotOnlyLetters() ErrorDetails

func RulesNotAccepted

func RulesNotAccepted() ErrorDetails

func TooYoungAge

func TooYoungAge() ErrorDetails

func Unauthorized

func Unauthorized() ErrorDetails

func UnknownCountry

func UnknownCountry() ErrorDetails

func UserAlreadyExists

func UserAlreadyExists() ErrorDetails

func UserNotFound

func UserNotFound() ErrorDetails

func WrongCountryCallingCode

func WrongCountryCallingCode() ErrorDetails

func WrongPhoneFormat

func WrongPhoneFormat() ErrorDetails

type Result

type Result struct {
	Details string   `json:"details"`
	Code    string   `json:"code"`
	Errors  []*Error `json:"errors"`
}

structure of backend errors https://oua.atlassian.net/wiki/spaces/ORIENTCODE/pages/1535770629/Unified+server+error+reporting

func BothEmailAndPhoneProvided

func BothEmailAndPhoneProvided() *Result

func CaptchaError

func CaptchaError(err error) *Result

func CodeError

func CodeError(code string, err error) *Result

CodeError is a generic error with code value

func DBOperationError

func DBOperationError(err error) *Result

func NewResult

func NewResult() *Result

func NoCodeError

func NoCodeError(err error) *Result

NoCodeError is a generic error, on request from FE will refactor responses that uses this if they need a code

func UnmarshalDetailedError

func UnmarshalDetailedError(err error) *Result

func UnmarshalError

func UnmarshalError(err error) *Result

func Validate

func Validate(v Validatable) *Result

Validate clean data (strips spaces from strings) and validates Make sure to provide a pointer to the struct or else it will fail

func ValidateAntiPhishingCode

func ValidateAntiPhishingCode(in string) *Result

func ValidateIPAddress

func ValidateIPAddress(in string) *Result

func ValidateIPAddressAndDevice

func ValidateIPAddressAndDevice(ipAddress, device string) *Result

func (*Result) AddCode

func (r *Result) AddCode(code string) *Result

func (*Result) AddDetails

func (r *Result) AddDetails(details string, formatArgs ...interface{}) *Result

func (*Result) AddFieldError

func (r *Result) AddFieldError(field string, ed ErrorDetails) *Result

func (*Result) AddResult

func (r *Result) AddResult(result *Result)

func (*Result) IsValid

func (r *Result) IsValid() bool

type Validatable

type Validatable interface {
	Validate() *Result // Validate must ALWAYS be declared on a pointer to a struct
}

Jump to

Keyboard shortcuts

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