File: is.go

package info (click to toggle)
golang-github-scaleway-scaleway-sdk-go 1.0.0~beta32-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,444 kB
  • sloc: sh: 70; makefile: 3
file content (61 lines) | stat: -rw-r--r-- 1,759 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Package validation provides format validation functions.
package validation

import (
	"net/url"
	"regexp"
)

var (
	isUUIDRegexp  = regexp.MustCompile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
	isRegionRegex = regexp.MustCompile("^[a-z]{2}-[a-z]{3}$")
	isZoneRegex   = regexp.MustCompile("^[a-z]{2}-[a-z]{3}-[1-9]$")
	isAccessKey   = regexp.MustCompile("^SCW[A-Z0-9]{17}$")
	isEmailRegexp = regexp.MustCompile("^.+@.+$")
)

// IsUUID returns true if the given string has a valid UUID format.
func IsUUID(s string) bool {
	return isUUIDRegexp.MatchString(s)
}

// IsAccessKey returns true if the given string has a valid Scaleway access key format.
func IsAccessKey(s string) bool {
	return isAccessKey.MatchString(s)
}

// IsSecretKey returns true if the given string has a valid Scaleway secret key format.
func IsSecretKey(s string) bool {
	return IsUUID(s)
}

// IsOrganizationID returns true if the given string has a valid Scaleway organization ID format.
func IsOrganizationID(s string) bool {
	return IsUUID(s)
}

// IsProjectID returns true if the given string has a valid Scaleway project ID format.
func IsProjectID(s string) bool {
	return IsUUID(s)
}

// IsRegion returns true if the given string has a valid region format.
func IsRegion(s string) bool {
	return isRegionRegex.MatchString(s)
}

// IsZone returns true if the given string has a valid zone format.
func IsZone(s string) bool {
	return isZoneRegex.MatchString(s)
}

// IsURL returns true if the given string has a valid URL format.
func IsURL(s string) bool {
	_, err := url.Parse(s)
	return err == nil
}

// IsEmail returns true if the given string has an email format.
func IsEmail(v string) bool {
	return isEmailRegexp.MatchString(v)
}