-
-
Notifications
You must be signed in to change notification settings - Fork 158
/
client.go
40 lines (32 loc) 路 829 Bytes
/
client.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
package scm
import "fmt"
// Client define the interface a scm client has to have
type Client interface {
NewClient() (Client, error)
GetUserRepos(targetUsername string) ([]Repo, error)
GetOrgRepos(targetOrg string) ([]Repo, error)
GetType() string
}
var (
clients []Client
)
// registerClient registers a client
func registerClient(c Client) {
clients = append(clients, c)
}
func GetClient(cType string) (Client, error) {
for i := range clients {
if clients[i].GetType() == cType {
return clients[i].NewClient()
}
}
return nil, fmt.Errorf("client type '%s' unsupported", cType)
}
// SupportedClients return list of all supported clients
func SupportedClients() []string {
types := make([]string, 0, len(clients))
for i := range clients {
types = append(types, clients[i].GetType())
}
return types
}