-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.go
71 lines (60 loc) · 1.2 KB
/
action.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
67
68
69
70
71
package kcl
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"io"
"os"
)
type message struct {
Action string `json:"action"`
ShardID *string `json:"shardId"`
Records []*Record `json:"records"`
Reason *string `json:"reason"`
Error *string `json:"error"`
}
type status struct {
Action string `json:"action"`
ResponseFor string `json:"responseFor"`
}
// ShutdownType ...
type ShutdownType int
const (
unknownShutdown ShutdownType = iota
// GracefulShutdown ...
GracefulShutdown
// ZombieShutdown ...
ZombieShutdown
)
func readMessage() *message {
bio := bufio.NewReader(os.Stdin)
var buffer bytes.Buffer
for {
line, more, err := bio.ReadLine()
if err == io.EOF {
return nil
}
if err != nil {
panic("Unable to read line from stdin " + err.Error())
}
buffer.Write(line)
if more == false {
break
}
}
var msg message
err := json.Unmarshal(buffer.Bytes(), &msg)
if err != nil {
panic("Failed to unmarshal json message " + err.Error())
}
return &msg
}
func writeStatus(action string) {
s := status{"status", action}
str, err := json.Marshal(s)
if err != nil {
panic("Failed to marshal status as json " + err.Error())
}
fmt.Printf("\n%s\n", str)
}