-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcandidate.go
50 lines (41 loc) · 1.38 KB
/
candidate.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
46
47
48
49
50
package candidate
import (
"github.com/barolab/candidate/fetch"
)
var providers []NameProvider
// NameProvider represents a service providing names, it then should be able to checks for existence of a given name
type NameProvider interface {
String() string
WithFetcher
IsAvailabler
Validator
}
// Validator interface for remote system that have special rules about user names
type Validator interface {
// Validate if the given string respect the SocialNetwork restrictions
Validate(name string) Violations
}
// IsAvailabler interface for remote system that can check for a username availability
type IsAvailabler interface {
// IsAvailable check if the given name exists in the provider
IsAvailable(name string) (bool, error)
}
// WithFetcher is an interface to set the behavior of all the name provider
type WithFetcher interface {
// WithFetcher can bind a new HTTP Fetcher to a name provider to use different mechanism
WithFetcher(f fetch.Fetcher)
}
// SocialNetworks returns a full list of NameProvider supported by this package
func SocialNetworks() []NameProvider {
return providers
}
// UseFetcher will return all the supported providers but initialized with a custom http client
func UseFetcher(f fetch.Fetcher) {
for _, p := range providers {
p.WithFetcher(f)
}
}
// Register a NameProvider in this package
func Register(np NameProvider) {
providers = append(providers, np)
}