Documentation ¶
Overview ¶
Package uniuri generates random strings good for use in URIs to identify unique objects.
Example usage:
s := util.UniUriNew() // s is now "apHCJBl7L1OmC57n"
A standard string created by New() is 16 bytes in length and consists of Latin upper and lowercase letters, and numbers (from the set of 62 allowed characters), which means that it has ~95 bits of entropy. To get more entropy, you can use NewLen(UUIDLen), which returns 20-byte string, giving ~119 bits of entropy, or any other desired length.
Functions read from crypto/rand random source, and panic if they fail to read from it.
Index ¶
- Constants
- Variables
- func AuthFailed(c *gin.Context)
- func CipherDecrypt(cryptoText string) string
- func CipherEncrypt(text string) string
- func CredentialStructLevelValidation(sl validator.StructLevel)
- func FindTensor() string
- func GenerateCookieSecrets()
- func GetAPIInfo(c *gin.Context)
- func GetAPIVersion(c *gin.Context)
- func GetIdParam(name string, c *gin.Context) (string, error)
- func GetIntParam(name string, c *gin.Context) (int, error)
- func GetPing(c *gin.Context)
- func GetU64IntParam(name string, c *gin.Context) (uint64, error)
- func GetValidationErrors(err error) []string
- func IsCredentialKind(fl validator.FieldLevel) bool
- func IsDNSName(fl validator.FieldLevel) bool
- func IsHost(fl validator.FieldLevel) bool
- func IsIP(fl validator.FieldLevel) bool
- func IsJobType(fl validator.FieldLevel) bool
- func IsScmType(fl validator.FieldLevel) bool
- func NaProperty(fl validator.FieldLevel) bool
- func ProjectStructLevelValidation(sl validator.StructLevel)
- func UniqueNew() string
- func UniqueNewLen(length int) string
- func UniqueNewLenChars(length int, chars []byte) string
- func ValidateEmail(email string) bool
- type MongoDBConfig
- type Pagination
- type QueryParser
- func (p *QueryParser) Contains(fields []string, query bson.M) bson.M
- func (p *QueryParser) Endswith(fields []string, query bson.M) bson.M
- func (p *QueryParser) Eq(fields []string, query bson.M) bson.M
- func (p *QueryParser) Exact(fields []string, query bson.M) bson.M
- func (p *QueryParser) Gt(fields []string, query bson.M) bson.M
- func (p *QueryParser) Gte(fields []string, query bson.M) bson.M
- func (p *QueryParser) IContains(s []string, query bson.M) bson.M
- func (p *QueryParser) IEndswith(s []string, query bson.M) bson.M
- func (p *QueryParser) IExact(s []string, query bson.M) bson.M
- func (p *QueryParser) IStartswith(s []string, query bson.M) bson.M
- func (p *QueryParser) In(fields []string, query bson.M) bson.M
- func (p *QueryParser) IsNull(fields []string, query bson.M) bson.M
- func (p *QueryParser) Lookups(fields []string, query bson.M) bson.M
- func (p *QueryParser) Lt(fields []string, query bson.M) bson.M
- func (p *QueryParser) Lte(fields []string, query bson.M) bson.M
- func (p *QueryParser) Match(s []string, query bson.M) bson.M
- func (p *QueryParser) Ne(fields []string, query bson.M) bson.M
- func (p *QueryParser) OrderBy() string
- func (p *QueryParser) Startswith(fields []string, query bson.M) bson.M
- type SpaceValidator
Constants ¶
const ( // StdLen is a standard length of uniuri string to achive ~95 bits of entropy. StdLen = 16 // UUIDLen is a length of uniuri string to achive ~119 bits of entropy, closest // to what can be losslessly converted to UUIDv4 (122 bits). UUIDLen = 20 )
const ( Become string = "^(sudo|su|pbrun|pfexec|runas|doas|dzdo)$" CredentialKind string = "^(windows|ssh|net|scm|aws|rax|vmware|satellite6|cloudforms|gce|azure|openstack)$" ScmType string = "^(manual|git|hg|svn)$" JobType string = "^(run|check|scan)$" DNSName string = `^([a-zA-Z0-9]{1}[a-zA-Z0-9_-]{1,62}){1}(\.[a-zA-Z0-9]{1}[a-zA-Z0-9_-]{1,62})*$` IP string = `` /* 659-byte string literal not displayed */ URLSchema string = `((ftp|tcp|udp|wss?|https?):\/\/)` URLUsername string = `(\S+(:\S*)?@)` URLPath string = `((\/|\?|#)[^\s]*)` URLPort string = `(:(\d{1,5}))` URLIP string = `([1-9]\d?|1\d\d|2[01]\d|22[0-3])(\.(1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.([0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))` URLSubdomain string = `((www\.)|([a-zA-Z0-9]([-\.][a-zA-Z0-9]+)*))` URL string = `^` + URLSchema + `?` + URLUsername + `?` + `((` + URLIP + `|(\[` + IP + `\])|(([a-zA-Z0-9]([a-zA-Z0-9-]+)?[a-zA-Z0-9]([-\.][a-zA-Z0-9]+)*)|(` + URLSubdomain + `?))?(([a-zA-Z\x{00a1}-\x{ffff}0-9]+-?-?)*[a-zA-Z\x{00a1}-\x{ffff}0-9]+)(?:\.([a-zA-Z\x{00a1}-\x{ffff}]{1,}))?))` + URLPort + `?` + URLPath + `?$` )
Variables ¶
var ( DefaultLimit = int(10) MinLimit = int(1) MaxLimit = int(500) LimitParam = "page_size" DefaultPage = int(1) PageParam = "page" )
var Config *configType
var InteractiveSetup bool
var (
OrderParam = "order_by"
)
var Secrets bool
var StdChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
StdChars is a set of standard characters allowed in uniuri string.
var Uni *ut.UniversalTranslator
use a single instance , it caches struct info
var Version = "0.0.8"
Version is for hold the system version globally
Functions ¶
func AuthFailed ¶
func CipherDecrypt ¶ added in v0.0.5
Decrypt from base64 to decrypted string
func CipherEncrypt ¶ added in v0.0.5
Encrypt string to base64 crypto using AES
func CredentialStructLevelValidation ¶ added in v0.0.2
func CredentialStructLevelValidation(sl validator.StructLevel)
TODO: openstack,azure,gce,
func FindTensor ¶
func FindTensor() string
func GenerateCookieSecrets ¶
func GenerateCookieSecrets()
func GetAPIInfo ¶
func GetAPIVersion ¶
func GetIdParam ¶
GetIdParam is to Get ObjectID url parameter If the parameter is not an ObjectId it will terminate the request
func GetValidationErrors ¶ added in v0.0.2
func IsCredentialKind ¶ added in v0.0.2
func IsCredentialKind(fl validator.FieldLevel) bool
func IsDNSName ¶ added in v0.0.2
func IsDNSName(fl validator.FieldLevel) bool
IsDNSName will validate the given string as a DNS name
func IsHost ¶ added in v0.0.2
func IsHost(fl validator.FieldLevel) bool
IsHost checks if the string is a valid IP (both v4 and v6) or a valid DNS name
func IsIP ¶ added in v0.0.2
func IsIP(fl validator.FieldLevel) bool
IsIP checks if a string is either IP version 4 or 6.
func ProjectStructLevelValidation ¶ added in v0.0.2
func ProjectStructLevelValidation(sl validator.StructLevel)
func UniqueNew ¶ added in v0.0.5
func UniqueNew() string
New returns a new random string of the standard length, consisting of standard characters.
func UniqueNewLen ¶ added in v0.0.5
NewLen returns a new random string of the provided length, consisting of standard characters.
func UniqueNewLenChars ¶ added in v0.0.5
NewLenChars returns a new random string of the provided length, consisting of the provided byte slice of allowed characters (maximum 256).
func ValidateEmail ¶
Types ¶
type MongoDBConfig ¶
type Pagination ¶
type Pagination struct {
// contains filtered or unexported fields
}
func NewPagination ¶
func NewPagination(c *gin.Context, n int) *Pagination
func (*Pagination) HasPage ¶
func (p *Pagination) HasPage() bool
func (*Pagination) Limit ¶
func (p *Pagination) Limit() int
func (*Pagination) NextPage ¶
func (p *Pagination) NextPage() interface{}
func (*Pagination) Offset ¶
func (p *Pagination) Offset() int
func (*Pagination) Page ¶
func (p *Pagination) Page() int
func (*Pagination) PreviousPage ¶
func (p *Pagination) PreviousPage() interface{}
type QueryParser ¶
func NewQueryParser ¶
func NewQueryParser(c *gin.Context) QueryParser
func (*QueryParser) Contains ¶ added in v0.0.4
Contains adds regex to mgo query to check a field contain a value accepting fields must pass to fields parameter
func (*QueryParser) Endswith ¶ added in v0.0.4
Endswith adds regex to mgo query to check a field endswith a value accepting fields must pass to fields parameter
func (*QueryParser) Eq ¶ added in v0.0.4
Eq check the given field or related object is equel to given value
func (*QueryParser) Exact ¶ added in v0.0.4
Exact adds regex to mgo query to check a field is an exact match accepting fields must pass to fields parameter
func (*QueryParser) Gt ¶ added in v0.0.4
Gt adds $gt to mgo query to check a field greater than the comparison value accepting fields must pass to fields parameter
func (*QueryParser) Gte ¶ added in v0.0.4
Gte adds $gte to mgo query to check a field greater or equal to the comparison value accepting fields must pass to fields parameter
func (*QueryParser) IContains ¶
IContains adds regex to mgo query to check a field contain a value this is the case insensitive version of contains accepting fields must pass to fields parameter
func (*QueryParser) IEndswith ¶ added in v0.0.4
IEndswith adds regex to mgo query to check a field endswith a value this is the case insensitive version of endswith accepting fields must pass to fields parameter
func (*QueryParser) IExact ¶ added in v0.0.4
Exact adds regex to mgo query to check a field is an exact match this is the case insensitive version of Exact accepting fields must pass to fields parameter
func (*QueryParser) IStartswith ¶ added in v0.0.4
IStartswith adds regex to mgo query to check a field startswith a value this is the case insensitive version of startswith accepting fields must pass to fields parameter
func (*QueryParser) In ¶ added in v0.0.4
In Check the given field's value is present in the list provide accepting fields must pass to fields parameter
func (*QueryParser) Lt ¶ added in v0.0.4
Lt adds $lt to mgo query to check a field less than the comparison value accepting fields must pass to fields parameter
func (*QueryParser) Lte ¶ added in v0.0.4
Gt adds $lte to mgo query to check a field less than or equal to the comparison value accepting fields must pass to fields parameter
func (*QueryParser) Ne ¶ added in v0.0.4
Eq check the given field or related object is not equal to given value
func (*QueryParser) OrderBy ¶
func (p *QueryParser) OrderBy() string
func (*QueryParser) Startswith ¶ added in v0.0.4
Startswith adds regex to mgo query to check a field startswith a value accepting fields must pass to fields parameter
type SpaceValidator ¶
type SpaceValidator struct {
// contains filtered or unexported fields
}
func (*SpaceValidator) ValidateStruct ¶
func (v *SpaceValidator) ValidateStruct(obj interface{}) error