-
Notifications
You must be signed in to change notification settings - Fork 12
/
common.go
45 lines (37 loc) · 821 Bytes
/
common.go
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
package main
import (
"flag"
"fmt"
)
var (
certFile string
keyFile string
)
func init() {
flag.StringVar(&certFile, "cert", "test.crt", "TLS Cert File")
flag.StringVar(&keyFile, "key", "test.key", "TLS Key File")
flag.Parse()
}
func main() {
var block = make(chan struct{})
go mainGRPC("localhost:4443")
go mainREST("localhost:4444")
<-block
}
// Validatable interface to describe what is validatable
type Validatable interface {
Validate() error
}
// validationErrors - custom error type that can take many errors
type validationErrors []error
// Error - implementation of error interface
func (ve validationErrors) Error() string {
var errStr string
for _, v := range ve {
errStr += fmt.Sprintf("%s\n", v.Error())
}
return errStr
}
func validate(v Validatable) error {
return v.Validate()
}