common

package
v0.0.0-...-4e281dc Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2020 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WorkspaceNameLenMin = 1
	WorkspaceNameLenMax = 50
	WorkspaceDescLenMin = 1
	WorkspaceDescLenMax = 1000
)

For validation of workspace fields

View Source
const (
	ChannelNameLenMin = 1
	ChannelNameLenMax = 50
	ChannelDescLenMin = 1
	ChannelDescLenMax = 1000
)

For validation of Channel fields

View Source
const (
	MtextLenMin = 1
	MtextLenMax = 1000
)

For validation of Message fields

View Source
const (
	FirstNameLenMin = 1
	FirstNameLenMax = 100
	LastNameLenMin  = 1
	LastNameLenMax  = 100
	PasswordLenMin  = 6
	PasswordLenMax  = 50
)

For validation of user fields

View Source
const (
	UgroupNameLenMin = 1
	UgroupNameLenMax = 50
	UgroupDescLenMin = 1
	UgroupDescLenMax = 1000
)

For validation of Ugroup fields

View Source
const (
	UbadgeNameLenMin = 1
	UbadgeNameLenMax = 50
	UbadgeDescLenMin = 1
	UbadgeDescLenMax = 1000
)

For validation of Ubadge fields

View Source
const Active = 1

Active - value of status

View Source
const DBMysql string = "mysql"

DBMysql for DbType is mysql

View Source
const DBPgsql string = "pgsql"

DBPgsql for DbType is pgsql

View Source
const Inactive = 0

Inactive - value of status

View Source
const RPCReqTimeout = 10 * time.Second

RPCReqTimeout - value of request timeout

Variables

This section is empty.

Functions

func AddMiddleware

func AddMiddleware(h http.Handler, middleware ...func(http.Handler) http.Handler) http.Handler

AddMiddleware - adds middleware to a Handler

func AuthenticateMiddleware

func AuthenticateMiddleware(next http.Handler) http.Handler

AuthenticateMiddleware - Authenticate Token from request

func CheckRoles

func CheckRoles(AllowedRoles []string, UserRoles []string) error

CheckRoles - used for checking roles

func ConvertToTime

func ConvertToTime(createdAt *timestamp.Timestamp, updatedAt *timestamp.Timestamp) (time.Time, time.Time, error)

ConvertToTime - used to convert timestamp to time.Time

func ConvertToTimestamp

func ConvertToTimestamp(createdAt time.Time, updatedAt time.Time) (*timestamp.Timestamp, *timestamp.Timestamp, error)

ConvertToTimestamp - used to convert time.Time to timestamp

func CorsMiddleware

func CorsMiddleware(next http.Handler) http.Handler

CorsMiddleware - Enable CORS with various options

func CreateCtxJWT

func CreateCtxJWT(ctx context.Context) (context.Context, error)

CreateCtxJWT - used to get context

func DecodeCursor

func DecodeCursor(cursor string) string

DecodeCursor - decode cursor

func EncodeCursor

func EncodeCursor(cursor uint32) string

EncodeCursor - encode cursor

func GenTokenHash

func GenTokenHash(requestID string) (selector, verifier, token string, err error)

GenTokenHash - GenTokenHash generates pieces needed for passwd recovery hash of the first half of a 64 byte value (to be stored in the database and used in SELECT query) verifier: hash of the second half of a 64 byte value (to be stored in database but never used in SELECT query) token: the user-facing base64 encoded selector+verifier

func GetAuthBearerToken

func GetAuthBearerToken(r *http.Request) (string, error)

GetAuthBearerToken - extract the BEARER token from the auth header

func GetClientCred

func GetClientCred(log *zap.Logger, isTest bool, pwd string, grpcServerOpt *GrpcServerOptions) (credentials.TransportCredentials, error)

GetClientCred -- client credentials

func GetConfigOpt

GetConfigOpt -- Get db, redis, mailer, grpc, jwt, oauth, user, tracer, prometheus, elasticsearch options

func GetHTTPRateLimiter

func GetHTTPRateLimiter(store *goredisstore.GoRedisStore, MaxRate int, MaxBurst int) throttled.HTTPRateLimiter

GetHTTPRateLimiter - Get HTTP Rate Limiter

func GetJWTFromCtx

func GetJWTFromCtx(ctx context.Context, header string) (string, error)

GetJWTFromCtx - used to get jwt from context

func GetPathParts

func GetPathParts(url string) []string

GetPathParts - given a url, returns a slice of the parts of the url

func GetPathQueryString

func GetPathQueryString(s string) (string, url.Values, error)

GetPathQueryString -- given url string, returns the path, and the query string Eg. "/v1/users?limit=5&cursor=s4R0Z6ecFTzTC4j=" will return "/v1/users", ["limit"]="5", ["cursor"]="s4R0Z6ecFTzTC4j="

func GetRequestID

func GetRequestID() string

GetRequestID - used for RequestID generation

func GetSelectorForPasswdRecoveryToken

func GetSelectorForPasswdRecoveryToken(token string, requestID string) ([64]byte, string, error)

GetSelectorForPasswdRecoveryToken - Get Selector For Password Recovery Token

func GetServices

func GetServices(log *zap.Logger, isTest bool, dbOpt *DBOptions, redisOpt *RedisOptions, mailerOpt *MailerOptions) (*DBService, *RedisService, *MailerService)

GetServices - Init Db, Redis, and Mailer services

func GetSrvCred

func GetSrvCred(log *zap.Logger, isTest bool, pwd string, grpcServerOpt *GrpcServerOptions) (credentials.TransportCredentials, error)

GetSrvCred -- server credentials

func GetTimeDetails

func GetTimeDetails() time.Time

GetTimeDetails - used to populate created_by and updated_by fields when inserting/updating records in the database

func GetUUID

func GetUUID() uuid.UUID

GetUUID - used for UUID generation

func GetUUIDBytes

func GetUUIDBytes() ([]byte, error)

GetUUIDBytes - used for UUID generation, to save in the db

func GetViper

func GetViper() (*viper.Viper, error)

GetViper -- init viper

func HashPassword

func HashPassword(password string, requestID string) ([]byte, error)

HashPassword - Generate hash password

func LoadEnforcer

func LoadEnforcer(dbOpt *DBService, roleOpt *RoleOptions) (*casbin.Enforcer, error)

LoadEnforcer - used for checking roles

func ParseTemplate

func ParseTemplate(templateFileName string, data interface{}) (string, error)

ParseTemplate - used for parsing template (for emails)

func ParseURL

func ParseURL(urlString string) ([]string, url.Values, error)

ParseURL - parses a url into a slice (GetPathParts) and the query string (GetPathQueryString)

func RenderErrorJSON

func RenderErrorJSON(w http.ResponseWriter, errorCode string, errorMsg string, httpStatusCode int, requestID string)

RenderErrorJSON - send error JSON response

func RenderJSON

func RenderJSON(w http.ResponseWriter, data interface{})

RenderJSON - send JSON response

func SetJWTOpt

func SetJWTOpt(jwt *JWTOptions)

SetJWTOpt set JWT opt used in auth middleware

func SetUpLogging

func SetUpLogging(logPath string) *zap.Logger

SetUpLogging - SetUpLogging

func TimeToTimestamp

func TimeToTimestamp(dateAt time.Time) (*timestamp.Timestamp, error)

TimeToTimestamp - used to convert time.Time to timestamp

func TimestampToTime

func TimestampToTime(dateAt *timestamp.Timestamp) (time.Time, error)

TimestampToTime - used to convert timestamp to time.Time

func UUIDBytesToStr

func UUIDBytesToStr(b []byte) (string, error)

UUIDBytesToStr - convert a UUID retrieved from the DB as str, to string for sending to the client

func UUIDStrToBytes

func UUIDStrToBytes(s string) ([]byte, error)

UUIDStrToBytes - convert a UUID str into bytes

func UUIDStrToUUID

func UUIDStrToUUID(s string) (uuid.UUID, error)

UUIDStrToUUID - convert a UUID str into UUID

func ValidatePasswdRecoveryToken

func ValidatePasswdRecoveryToken(verifierBytes [64]byte, verifier string, tokenExpiry time.Time, requestID string) error

ValidatePasswdRecoveryToken - Validate Passwd Recovery Token

Types

type ContextData

type ContextData struct {
	Email  string
	UserID string
	Roles  []string
}

ContextData - details of a user stored in the Redis cache

type ContextStruct

type ContextStruct struct {
	Email       string
	TokenString string
}

ContextStruct - stored in the request context set in AuthMiddleware

func GetAuthData

func GetAuthData(r *http.Request) ContextStruct

GetAuthData - used to get auth details

type DBIntf

type DBIntf interface {
	DBClose() error
}

DBIntf - Interface to the Database

type DBOptions

type DBOptions struct {
	DB                    string `mapstructure:"db"`
	Host                  string `mapstructure:"hostname"`
	Port                  string `mapstructure:"port"`
	User                  string `mapstructure:"user"`
	Password              string `mapstructure:"password"`
	Schema                string `mapstructure:"db_schema"`
	LimitSQLRows          string `mapstructure:"limit_sql_rows"`
	MySQLTestFilePath     string `mapstructure:"mysql_test_file_path"`
	MySQLSchemaFilePath   string `mapstructure:"mysql_schema_file_path"`
	MySQLTruncateFilePath string `mapstructure:"mysql_truncate_file_path"`
	PgSQLTestFilePath     string `mapstructure:"pgsql_test_file_path"`
	PgSQLSchemaFilePath   string `mapstructure:"pgsql_schema_file_path"`
	PgSQLTruncateFilePath string `mapstructure:"pgsql_truncate_file_path"`
}

DBOptions - for db config

func GetDbConfig

func GetDbConfig(log *zap.Logger, v *viper.Viper, isTest bool, db string, dbHost string, dbPort string, dbUser string, dbPassword string, dbSchema string, dbMysqlTestFilePath string, dbMysqlSchemaFilePath string, dbMysqlTruncateFilePath string, dbPgsqlTestFilePath string, dbPgsqlSchemaFilePath string, dbPgsqlTruncateFilePath string) (*DBOptions, error)

GetDbConfig -- read DB config options

type DBService

type DBService struct {
	DBType                string
	DB                    *sql.DB
	Schema                string
	LimitSQLRows          string
	MySQLTestFilePath     string
	MySQLSchemaFilePath   string
	MySQLTruncateFilePath string
	PgSQLTestFilePath     string
	PgSQLSchemaFilePath   string
	PgSQLTruncateFilePath string
	// contains filtered or unexported fields
}

DBService - Database type and Pointer to access Db

func CreateDBService

func CreateDBService(log *zap.Logger, dbOpt *DBOptions) (*DBService, error)

CreateDBService -- init DB

func NewDBService

func NewDBService(log *zap.Logger, dbOpt *DBOptions) (*DBService, error)

NewDBService - get connection to DB and create a DBService struct

func (*DBService) DBClose

func (dbService *DBService) DBClose() error

DBClose - Close connection to database

func (*DBService) InsUpd

func (dbService *DBService) InsUpd(ctx context.Context, userEmail string, requestID string, ex execFunc) error

InsUpd - Insert, Update to database

func (*DBService) QueryRow

func (dbService *DBService) QueryRow(ctx context.Context, userEmail string, requestID string, query string, args ...interface{}) PartialQuery

QueryRow - Query a single row

func (*DBService) QueryRows

func (dbService *DBService) QueryRows(ctx context.Context, userEmail string, requestID string, query string, args ...interface{}) PartialQuery

QueryRows - query multiple rows

type EachRowFunc

type EachRowFunc func(row ScanFunc) error

EachRowFunc - scan a row

type ElasticOptions

type ElasticOptions struct {
	User       string `mapstructure:"username"`
	Password   string `mapstructure:"password"`
	ServerAddr string `mapstructure:"server_addr"`
	IndexName  string `mapstructure:"index_name"`
}

ElasticOptions - for ElasticSearch config

func GetElasticConfig

func GetElasticConfig(log *zap.Logger, v *viper.Viper, isTest bool, elasticUser string, elasticPass string, elasticServer string, elasticIndexName string) (*ElasticOptions, error)

GetElasticConfig -- read ElasticSearch config options

type Email

type Email struct {
	From    string
	To      string
	Subject string
	Body    string
	Cc      string
}

Email - for sending email notifications

type Error

type Error struct {
	ErrorCode      string `json:"error_code"`
	ErrorMsg       string `json:"error_msg"`
	HTTPStatusCode int    `json:"status"`
	RequestID      string `json:"request_id"`
}

Error - used for

type GrpcServerOptions

type GrpcServerOptions struct {
	GrpcWorkspaceServerPort string `mapstructure:"grpc_workspace_server_port"`
	GrpcChannelServerPort   string `mapstructure:"grpc_channel_server_port"`
	GrpcMessageServerPort   string `mapstructure:"grpc_message_server_port"`
	GrpcUserServerPort      string `mapstructure:"grpc_user_server_port"`
	GrpcUbadgeServerPort    string `mapstructure:"grpc_ubadge_server_port"`
	GrpcUgroupServerPort    string `mapstructure:"grpc_ugroup_server_port"`
	GrpcSearchServerPort    string `mapstructure:"grpc_search_server_port"`
	GrpcCaCertPath          string `mapstructure:"grpc_ca_cert_path"`
	GrpcCertPath            string `mapstructure:"grpc_cert_path"`
	GrpcKeyPath             string `mapstructure:"grpc_key_path"`
}

GrpcServerOptions - for grpc server config

func GetGrpcServerConfig

func GetGrpcServerConfig(log *zap.Logger, v *viper.Viper) (*GrpcServerOptions, error)

GetGrpcServerConfig -- read grpc server config options

type JWTOptions

type JWTOptions struct {
	JWTKey      []byte
	JWTDuration int
}

JWTOptions - for JWT config

func GetJWTConfig

func GetJWTConfig(log *zap.Logger, v *viper.Viper, isTest bool, jwtKey string, jwtDuration string) (*JWTOptions, error)

GetJWTConfig -- read JWT config options

func GetJWTOpt

func GetJWTOpt() *JWTOptions

GetJWTOpt get JWT opt used in auth middleware

type JaegerTracerOptions

type JaegerTracerOptions struct {
	WorkspaceServiceName string `mapstructure:"workspace_service_name"`
	ChannelServiceName   string `mapstructure:"channel_service_name"`
	MessageServiceName   string `mapstructure:"message_service_name"`
	UbadgeServiceName    string `mapstructure:"ubadge_service_name"`
	UgroupServiceName    string `mapstructure:"ugroup_service_name"`
	UserServiceName      string `mapstructure:"user_service_name"`
	SearchServiceName    string `mapstructure:"search_service_name"`
	UserAgent            string `mapstructure:"user_agent"`
}

JaegerTracerOptions - for Jaeger Tracer config

func GetJaegerTracerConfig

func GetJaegerTracerConfig(log *zap.Logger, v *viper.Viper) (*JaegerTracerOptions, error)

GetJaegerTracerConfig -- read JaegerTracer config options

type Key

type Key string

Key - type of the key used in the request context

const KeyEmailToken Key = "emailtoken"

KeyEmailToken - used for the request context key

type LogOptions

type LogOptions struct {
	Path          string `mapstructure:"log_file_path"`
	WorkspacePath string `mapstructure:"log_workspace_file_path"`
	ChannelPath   string `mapstructure:"log_channel_file_path"`
	MessagePath   string `mapstructure:"log_message_file_path"`
	UbadgePath    string `mapstructure:"log_ubadge_file_path"`
	UgroupPath    string `mapstructure:"log_ugroup_file_path"`
	UserPath      string `mapstructure:"log_user_file_path"`
	SearchPath    string `mapstructure:"log_search_file_path"`
	Level         string `mapstructure:"log_level"`
}

LogOptions - for logging

func GetLogConfig

func GetLogConfig(v *viper.Viper) (*LogOptions, error)

GetLogConfig -- read log config options

type MailerIntf

type MailerIntf interface {
	SendConfirmationMail(hostURL string, userEmail string, emailConfirmationToken string, requestID string) error
	SendResetPasswordMail(hostURL string, userEmail string, resetToken string, requestID string) error
	SendChangeMail(hostURL string, userEmail string, newEmail string, resetToken string, requestID string) error
	SendMail(msg Email) error
}

MailerIntf interface to the Mailer

type MailerOptions

type MailerOptions struct {
	User     string `mapstructure:"username"`
	Password string `mapstructure:"password"`
	Port     int    `mapstructure:"port"`
	Server   string `mapstructure:"server"`
}

MailerOptions - for mailer config

func GetMailerConfig

func GetMailerConfig(log *zap.Logger, v *viper.Viper) (*MailerOptions, error)

GetMailerConfig -- read mailer config options

type MailerService

type MailerService struct {
	Mailer *gomail.Dialer
	// contains filtered or unexported fields
}

MailerService Pointer to mailer

func CreateMailerService

func CreateMailerService(log *zap.Logger, mailerOpt *MailerOptions) (*MailerService, error)

CreateMailerService -- init mailer

func NewMailerService

func NewMailerService(log *zap.Logger, mailerOpt *MailerOptions) (*MailerService, error)

NewMailerService get connection to mailer and create a MailerService struct

func (*MailerService) SendChangeMail

func (mailerService *MailerService) SendChangeMail(hostURL string, userEmail string, newEmail string, resetToken string, requestID string) error

SendChangeMail - used for sending change email

func (*MailerService) SendConfirmationMail

func (mailerService *MailerService) SendConfirmationMail(hostURL string, userEmail string, emailConfirmationToken string, requestID string) error

SendConfirmationMail - used for sending confirmation email

func (*MailerService) SendMail

func (mailerService *MailerService) SendMail(msg Email) error

SendMail - used for sending email

func (*MailerService) SendResetPasswordMail

func (mailerService *MailerService) SendResetPasswordMail(hostURL string, userEmail string, resetToken string, requestID string) error

SendResetPasswordMail - used for sending reset password email

type OauthOptions

type OauthOptions struct {
	ClientID     string `mapstructure:"client_id"`
	ClientSecret string `mapstructure:"client_secret"`
}

OauthOptions - for oauth config

func GetOauthConfig

func GetOauthConfig(log *zap.Logger, v *viper.Viper) (*OauthOptions, error)

GetOauthConfig -- read oauth config options

type PartialQuery

type PartialQuery func(row EachRowFunc) error

PartialQuery - function to drive the loop

type PromOptions

type PromOptions struct {
	PromHTTPWorkspaceServerPort string `mapstructure:"prom_http_workspace_server_port"`
	PromHTTPChannelServerPort   string `mapstructure:"prom_http_channel_server_port"`
	PromHTTPMessageServerPort   string `mapstructure:"prom_http_message_server_port"`
	PromHTTPUserServerPort      string `mapstructure:"prom_http_user_server_port"`
	PromHTTPUbadgeServerPort    string `mapstructure:"prom_http_ubadge_server_port"`
	PromHTTPUgroupServerPort    string `mapstructure:"prom_http_ugroup_server_port"`
	PromHTTPSearchServerPort    string `mapstructure:"prom_http_search_server_port"`
}

PromOptions - for Prometheus config

func GetPromConfig

func GetPromConfig(log *zap.Logger, v *viper.Viper) (*PromOptions, error)

GetPromConfig -- read Prometheus config options

type RateOptions

type RateOptions struct {
	UserMaxRate       int `mapstructure:"user_max_rate"`
	UserMaxBurst      int `mapstructure:"user_max_burst"`
	UgroupMaxRate     int `mapstructure:"ugroup_max_rate"`
	UgroupMaxBurst    int `mapstructure:"ugroup_max_burst"`
	WorkspaceMaxRate  int `mapstructure:"workspace_max_rate"`
	WorkspaceMaxBurst int `mapstructure:"workspace_max_burst"`
	ChannelMaxRate    int `mapstructure:"channel_max_rate"`
	ChannelMaxBurst   int `mapstructure:"channel_max_burst"`
	MsgMaxRate        int `mapstructure:"msg_max_rate"`
	MsgMaxBurst       int `mapstructure:"msg_max_burst"`
	UbadgeMaxRate     int `mapstructure:"ubadge_max_rate"`
	UbadgeMaxBurst    int `mapstructure:"ubadge_max_burst"`
	SearchMaxRate     int `mapstructure:"search_max_rate"`
	SearchMaxBurst    int `mapstructure:"search_max_burst"`
	UMaxRate          int `mapstructure:"u_max_rate"`
	UMaxBurst         int `mapstructure:"u_max_burst"`
}

RateOptions - for rate limiting requests

func GetRateConfig

func GetRateConfig(log *zap.Logger, v *viper.Viper) (*RateOptions, error)

GetRateConfig -- read rate config options

type RedisIntf

type RedisIntf interface {
	Get(key string) (string, error)
	Set(key string, value interface{}, expiration time.Duration) error
}

RedisIntf Interface to Redis commands All redis command to be called using this interface

type RedisOptions

type RedisOptions struct {
	Addr string `mapstructure:"addr"`
}

RedisOptions - for redis config

func GetRedisConfig

func GetRedisConfig(log *zap.Logger, v *viper.Viper) (*RedisOptions, error)

GetRedisConfig -- read redis config options

type RedisService

type RedisService struct {
	RedisClient *redis.Client
	// contains filtered or unexported fields
}

RedisService - Redis Pointer to redis

func CreateRedisService

func CreateRedisService(log *zap.Logger, redisOpt *RedisOptions) (*RedisService, error)

CreateRedisService -- init redis

func NewRedisService

func NewRedisService(log *zap.Logger, redisOpt *RedisOptions) (*RedisService, error)

NewRedisService get connection to redis and create a RedisService struct

func (*RedisService) Get

func (rds *RedisService) Get(key string) (string, error)

Get - call the Get method on the RedisClient

func (*RedisService) Set

func (rds *RedisService) Set(key string, value interface{}, expiration time.Duration) error

Set - Call the Set method on the Redis client

type Role

type Role struct {
	PType string `mapstructure:"ptype"`
	V0    string `mapstructure:"v0"`
	V1    string `mapstructure:"v1"`
	V2    string `mapstructure:"v2"`
	V3    string `mapstructure:"v3"`
	V4    string `mapstructure:"v4"`
	V5    string `mapstructure:"v5"`
}

Role - for user roles

type RoleOptions

type RoleOptions struct {
	Roles                 []Role `mapstructure:"roles"`
	RolesPolicyConfigPath string
	RolesTableName        string `mapstructure:"roles_table"`
}

RoleOptions - for Role

func GetRoleConfig

func GetRoleConfig(log *zap.Logger, v *viper.Viper) (*RoleOptions, error)

GetRoleConfig -- read Roles config options

type ScanFunc

type ScanFunc func(dest ...interface{}) error

ScanFunc - process row

type ServerOptions

type ServerOptions struct {
	ServerAddr string `mapstructure:"server_addr"`
	ServerTLS  string `mapstructure:"server_tls"`
	CaCertPath string `mapstructure:"ca_cert_path"`
	CertPath   string `mapstructure:"cert_path"`
	KeyPath    string `mapstructure:"key_path"`
}

ServerOptions - for server config

func GetServerConfig

func GetServerConfig(log *zap.Logger, v *viper.Viper) (*ServerOptions, error)

GetServerConfig -- read server config options

type User

type User struct {
	ID    uint
	UUID4 []byte
	IDS   string
	Email string
	Role  string
}

User - details of the user from the database

type UserOptions

type UserOptions struct {
	ConfirmTokenDuration string `mapstructure:"confirm_token_duration"`
	ResetTokenDuration   string `mapstructure:"reset_token_duration"`
}

UserOptions - for user login

func GetUserConfig

func GetUserConfig(log *zap.Logger, v *viper.Viper) (*UserOptions, error)

GetUserConfig -- read user config options

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator used for validation

func NewValidator

func NewValidator() *Validator

NewValidator create a Validator struct

func (*Validator) Error

func (v *Validator) Error() string

Error error

func (*Validator) IsAlpha

func (v *Validator) IsAlpha(fieldName string, fieldValue string) bool

IsAlpha validate Alpha characters

func (*Validator) IsAlphaNumeric

func (v *Validator) IsAlphaNumeric(fieldName string, fieldValue string) bool

IsAlphaNumeric validate alpha numeric characters

func (*Validator) IsCreditCard

func (v *Validator) IsCreditCard(fieldName string, fieldValue string) bool

IsCreditCard validate credit card

func (*Validator) IsDateFormat

func (v *Validator) IsDateFormat(fieldName string, fieldValue string) bool

IsDateFormat validate date format

func (*Validator) IsDigits

func (v *Validator) IsDigits(fieldName string, fieldValue string) bool

IsDigits validate Digits

func (*Validator) IsEmail

func (v *Validator) IsEmail(fieldName string, fieldValue string) bool

IsEmail validate email address

func (*Validator) IsGreaterThan

func (v *Validator) IsGreaterThan(fieldName string, fieldValue, high int) bool

IsGreaterThan int comparison

func (*Validator) IsInt64Negative

func (v *Validator) IsInt64Negative(fieldName string, fieldValue int64) bool

IsInt64Negative returns true if value < 0

func (*Validator) IsInt64NonNegative

func (v *Validator) IsInt64NonNegative(fieldName string, fieldValue int64) bool

IsInt64NonNegative returns true if value >= 0

func (*Validator) IsInt64NonPositive

func (v *Validator) IsInt64NonPositive(fieldName string, fieldValue int64) bool

IsInt64NonPositive returns true if value <= 0

func (*Validator) IsInt64Positive

func (v *Validator) IsInt64Positive(fieldName string, fieldValue int64) bool

IsInt64Positive returns true if value > 0

func (*Validator) IsPhoneNumber

func (v *Validator) IsPhoneNumber(fieldName string, fieldValue string) bool

IsPhoneNumber validate phone number

func (*Validator) IsStrLenBetMinMax

func (v *Validator) IsStrLenBetMinMax(fieldName string, fieldValue string, min int, max int) bool

IsStrLenBetMinMax string length between min max

func (*Validator) IsStrLenGtMin

func (v *Validator) IsStrLenGtMin(fieldName string, fieldValue string, min int) bool

IsStrLenGtMin string length greater than min

func (*Validator) IsStrLenLtMax

func (v *Validator) IsStrLenLtMax(fieldName string, fieldValue string, max int) bool

IsStrLenLtMax string length less than max

func (*Validator) IsStrNotEmpty

func (v *Validator) IsStrNotEmpty(fieldName string, fieldValue string) bool

IsStrNotEmpty string not empty

func (*Validator) IsTimeBefore

func (v *Validator) IsTimeBefore(fieldName string, fieldValue, max time.Time) bool

IsTimeBefore time comparison

func (*Validator) IsUUID4

func (v *Validator) IsUUID4(fieldName string, fieldValue string) bool

IsUUID4 validate UUID4

func (*Validator) IsValid

func (v *Validator) IsValid() bool

IsValid bool check

type ValidatorIntf

type ValidatorIntf interface {
	IsGreaterThan(fieldName string, fieldValue, high int) bool
	IsTimeBefore(fieldName string, fieldValue, max time.Time) bool
	IsStrNotEmpty(fieldName string, fieldValue string) bool
	IsInt64Negative(fieldName string, fieldValue int64) bool
	IsInt64NonNegative(fieldName string, fieldValue int64) bool
	IsInt64Positive(fieldName string, fieldValue int64) bool
	IsInt64NonPositive(fieldName string, fieldValue int64) bool
	IsEmail(fieldName string, fieldValue string) bool
	IsDateFormat(fieldName string, fieldValue string) bool
	IsPhoneNumber(fieldName string, fieldValue string) bool
	IsUUID4(fieldName string, fieldValue string) bool
	IsAlpha(fieldName string, fieldValue string) bool
	IsAlphaNumeric(fieldName string, fieldValue string) bool
	IsDigits(fieldName string, fieldValue string) bool
	IsCreditCard(fieldName string, fieldValue string) bool
	IsStrLenGtMin(fieldName string, fieldValue string, min int) bool
	IsStrLenLtMax(fieldName string, fieldValue string, max int) bool
	IsStrLenBetMinMax(fieldName string, fieldValue string, min int, max int) bool
	IsValid() bool
	Error() string
}

ValidatorIntf interface for Validator

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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