-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
44 lines (34 loc) · 787 Bytes
/
config.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
package ssh
import (
"context"
"time"
"golang.org/x/crypto/ssh"
)
type Option interface {
Apply(*Config) *Config
}
type Heartbeat struct {
Interval time.Duration
MaxCount int
}
type Config struct {
ssh.ClientConfig `json:"-" yaml:"-"`
Network string
Address string
KeepAlive bool
ServerAlive Heartbeat
}
func (cfg *Config) With(opts ...Option) *Config {
for _, opt := range opts {
cfg = opt.Apply(cfg)
}
return cfg
}
func (cfg *Config) WithAuth(methods ...ssh.AuthMethod) *Config {
cfg.ClientConfig.Auth = append(cfg.ClientConfig.Auth, methods...)
return cfg
}
var _ = &Client{ConfigCallback: new(Config).Callback()}
func (cfg *Config) Callback() ConfigCallback {
return func(context.Context, string, string) (*Config, error) { return cfg, nil }
}