-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
services.go
35 lines (31 loc) · 931 Bytes
/
services.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
package narcissus
// Services maps a /etc/services file
type Services struct {
augeasPath string `default:"/files/etc/services"`
Comments []struct {
Comment string `narcissus:"."`
} `narcissus:"#comment"`
Services []Service `narcissus:"service-name"`
}
// Service maps a Services entry
type Service struct {
augeasPath string
Name string `narcissus:"."`
Port int `narcissus:"port"`
Protocol string `narcissus:"protocol"`
Comment string `narcissus:"#comment"`
}
// NewServices returns a new Services structure
func (n *Narcissus) NewServices() (s *Services, err error) {
s = &Services{}
err = n.Parse(s)
return
}
// NewService returns a new Service structure
func (n *Narcissus) NewService(name string, protocol string) (s *Service, err error) {
s = &Service{
augeasPath: "/files/etc/services/service-name[.='" + name + "' and protocol='" + protocol + "']",
}
err = n.Parse(s)
return
}