forked from hashicorp/otto
/
status.go
65 lines (55 loc) · 1.65 KB
/
status.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
package otto
import (
"fmt"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/otto/directory"
)
// statusInfo holds the complete status information for the Core.Status
// function.
type statusInfo struct {
Err error
Dev *directory.Dev
Build *directory.Build
Deploy *directory.Deploy
Infra *directory.Infra
}
// statusInfo gets the information for the Status call.
//
// This is meant to be called in a goroutine.
func (c *Core) statusInfo(resultCh chan<- *statusInfo) {
infra := c.appfile.ActiveInfrastructure()
if infra == nil {
panic("infra not found")
}
var err error
var result statusInfo
// Dev
result.Dev, err = c.dir.GetDev(&directory.Dev{Lookup: directory.Lookup{
AppID: c.appfile.ID}})
if err != nil {
result.Err = multierror.Append(result.Err, fmt.Errorf(
"Error loading development status: %s", err))
}
// Build
result.Build, err = c.dir.GetBuild(&directory.Build{Lookup: directory.Lookup{
AppID: c.appfile.ID, Infra: infra.Type, InfraFlavor: infra.Flavor}})
if err != nil {
result.Err = multierror.Append(result.Err, fmt.Errorf(
"Error loading build status: %s", err))
}
// Deploy
result.Deploy, err = c.dir.GetDeploy(&directory.Deploy{Lookup: directory.Lookup{
AppID: c.appfile.ID, Infra: infra.Type, InfraFlavor: infra.Flavor}})
if err != nil {
result.Err = multierror.Append(result.Err, fmt.Errorf(
"Error loading deploy status: %s", err))
}
// Infra
result.Infra, err = c.dir.GetInfra(&directory.Infra{Lookup: directory.Lookup{
Infra: infra.Name}})
if err != nil {
result.Err = multierror.Append(result.Err, fmt.Errorf(
"Error loading infra status: %s", err))
}
resultCh <- &result
}