validation

package
v0.0.0-...-0279da3 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: Apache-2.0 Imports: 9 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"`
	Index int                    `json:"-"` // used for request of array types to determine the correct field
	Codes []ErrorDetails         `json:"codes"`
	Data  map[string]interface{} `json:"data,omitempty"`
}

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 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"`
	Meta    map[string]interface{} `json:"meta,omitempty"`

	// used by limit ms to receive events
	Events event.Payload `json:"events,omitempty"`
}

Result is a data structure expected by FE for each 4xx responses 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 CodeErrorWithEvents

func CodeErrorWithEvents(code string, err error, events event.Payload) *Result

CodeErrorWithEvents is a generic error with code value events

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) AddFieldErrorWithData

func (r *Result) AddFieldErrorWithData(field string, ed ErrorDetails, data map[string]interface{}, index int) *Result

AddFieldErrorWithData used for handling errors regarding array request index used to determine which request object is having error , eg, request

{
    "addresses":
    [
        {
            "asset":"BTC",
            "network:"Tron"
        },
        {
            "asset":"ETH",
            "network":"Erc20"
        }
    ]
}

usage :

out := new(validation.Result)
for i := range newAddresses {
    if newAddresses[i].Asset==""{
        out.AddFieldErrorWithData(messages.FieldAddress, errorx.ErrorDetails(errorx.ErrEmptyAsset), map[string]interface{}{
            messages.FieldAsset: newAddresses[i].Asset,
            messages.FieldNetwork: newAddresses[i].Network,
        }, i)
    }
}

func (*Result) AddMetaInfo

func (r *Result) AddMetaInfo(key string, value interface{}) *Result

AddMetaInfo will add key:value to validation result Meta field

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