forked from krystal/guvnor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault_service.go
More file actions
47 lines (37 loc) · 824 Bytes
/
default_service.go
File metadata and controls
47 lines (37 loc) · 824 Bytes
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
package guvnor
import (
"errors"
"os"
"strings"
)
type GetDefaultServiceResult struct {
Name string
}
var (
ErrMultipleServices = errors.New("multiple services found, no default")
ErrNoService = errors.New("no service found")
)
func (e *Engine) GetDefaultService() (*GetDefaultServiceResult, error) {
entries, err := os.ReadDir(e.config.Paths.Config)
if err != nil {
return nil, err
}
serviceName := ""
for _, entry := range entries {
if entry.IsDir() {
continue
}
isYaml := strings.HasSuffix(entry.Name(), ".yaml")
if !isYaml {
continue
}
if serviceName != "" {
return nil, ErrMultipleServices
}
serviceName = strings.TrimSuffix(entry.Name(), ".yaml")
}
if serviceName == "" {
return nil, ErrNoService
}
return &GetDefaultServiceResult{Name: serviceName}, nil
}