/
service_logs.go
57 lines (44 loc) · 1.06 KB
/
service_logs.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
package command
import (
"fmt"
"gopkg.in/mgo.v2/bson"
"github.com/dokkur/swanager/core/entities"
swarm_service "github.com/dokkur/swanager/core/swarm/service"
)
// ServiceLogs returns service logs
type ServiceLogs struct {
CommonCommand
User *entities.User
ServiceID string
responseChan chan<- []string
}
// NewServiceLogsCommand created service start command
func NewServiceLogsCommand(command ServiceLogs) (ServiceLogs, chan []string, chan error) {
response := make(chan []string, 1)
err := make(chan error, 1)
command.responseChan = response
command.errorChan = err
return command, response, err
}
// Process service logs
func (sl ServiceLogs) Process() {
service, err := entities.GetService(bson.M{
"user_id": sl.User.ID,
"_id": sl.ServiceID,
})
if err != nil {
sl.errorChan <- err
return
}
_, err = swarm_service.Inspect(service)
if err != nil {
sl.errorChan <- fmt.Errorf("Service stopped.")
return
}
logs, err := swarm_service.Logs(service, 10)
if err != nil {
sl.errorChan <- err
return
}
sl.responseChan <- logs
}