-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.go
49 lines (40 loc) · 928 Bytes
/
server.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
package exec
import "strings"
type server struct {
Name string
Dsn string
Configs map[string]*config
key *string
roles []string
sshClient *sshClient
}
func (s *server) AddRole(role string) *server {
s.roles = append(s.roles, role)
return s
}
func (s *server) HasRole(role string) bool {
for _, r := range s.roles {
if role == r {
return true
}
}
return false
}
func (s *server) Set(name string, value interface{}) *server {
s.Configs[name] = &config{Name: name, value: value}
return s
}
func (s *server) Key(file string) *server {
s.key = &file
s.sshClient.keys = append(s.sshClient.keys, file)
return s
}
func (s *server) GetUser() string {
return s.Dsn[:strings.Index(s.Dsn, "@")]
}
func (s *server) GetHost() string {
if strings.Index(s.Dsn, ":") > 0 {
return s.Dsn[strings.Index(s.Dsn, "@")+1 : strings.Index(s.Dsn, ":")]
}
return s.Dsn[strings.Index(s.Dsn, "@")+1:]
}