forked from AfterShip/email-verifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
62 lines (55 loc) · 1.38 KB
/
util.go
File metadata and controls
62 lines (55 loc) · 1.38 KB
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
62
package emailverifier
import (
"crypto/md5" //nolint:gosec
"encoding/hex"
"reflect"
"strings"
"golang.org/x/net/idna"
)
// splitDomain splits domain and returns sld and tld
func splitDomain(domain string) (string, string) {
parts := strings.Split(domain, ".")
n := len(parts)
if len(parts) >= 2 {
return parts[n-2], parts[n-1]
}
return "", parts[0]
}
// domainToASCII converts any internationalized domain names to ASCII
// reference: https://en.wikipedia.org/wiki/Punycode
func domainToASCII(domain string) string {
asciiDomain, err := idna.ToASCII(domain)
if err != nil {
return domain
}
return asciiDomain
}
// callJobFuncWithParams convert jobFunc and prams to a specific function and call it
func callJobFuncWithParams(jobFunc interface{}, params []interface{}) []reflect.Value {
typ := reflect.TypeOf(jobFunc)
if typ.Kind() != reflect.Func {
return nil
}
f := reflect.ValueOf(jobFunc)
if len(params) != f.Type().NumIn() {
return nil
}
in := make([]reflect.Value, len(params))
for k, param := range params {
in[k] = reflect.ValueOf(param)
}
return f.Call(in)
}
// getMD5Hash use md5 to encode string
// #nosec
func getMD5Hash(str string) (string, error) {
h := md5.New()
_, err := h.Write([]byte(str))
if err != nil {
return "", err
}
return hex.EncodeToString(h.Sum(nil)), nil
}
func trimLower(s string) string {
return strings.ToLower(strings.TrimSpace(s))
}