-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
66 lines (57 loc) · 1.53 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package winservice
import "errors"
// Config holds configuration for a service.
//
// NOTE: This structure is subject to change in future revisions.
type Config struct {
Path string
Args []string
Type Type
Startup Startup
Importance Importance
Account string
Password string // Write Only
DisplayName string
Description string
}
// Apply copies the values from conf to c2. It allows a configuration struct
// to be passed as an option.
func (conf Config) Apply(c2 *Config) {
c2.Path = conf.Path
c2.Args = conf.Args
c2.Account = conf.Account
c2.Password = conf.Password
c2.Type = conf.Type
c2.Startup = conf.Startup
}
// validate returns an error if the config is invalid
func (conf Config) validate() error {
if conf.Path == "" {
return errors.New("windows service configuration is missing a path")
}
return nil
}
// Option is a service configuration option.
type Option interface {
Apply(conf *Config)
}
// OptionFunc is a service configuration function.
type OptionFunc func(conf *Config)
// Apply applies the configuration option to conf.
func (f OptionFunc) Apply(conf *Config) {
f(conf)
}
// Args returns a service configuration option for a set of service arguments.
func Args(args ...string) Option {
return OptionFunc(func(conf *Config) {
conf.Args = args
})
}
// Account returns a service configuration option for the given account
// credentials.
func Account(account, password string) Option {
return OptionFunc(func(conf *Config) {
conf.Account = account
conf.Password = password
})
}