-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
87 lines (73 loc) · 2.01 KB
/
main.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"flag"
"log"
"github.com/gincorp/gin/datastore"
"github.com/gincorp/gin/workflow"
)
var (
redisURI *string
)
func init() {
redisURI = flag.String("redis", "redis://localhost:6379/0", "URI of redis node")
flag.Parse()
}
func main() {
d, err := datastore.NewDatastore(*redisURI)
if err != nil {
panic(err)
}
log.Print(d.SaveWorkflow(postToEchoServer(), true))
log.Print(d.SaveWorkflow(postToEchoServerAndLog(), true))
}
func postToEchoServer() workflow.Workflow {
// Make a request against https://hub.docker.com/r/jspc/go-echo-http-server/
vars := make(map[string]string)
// hyphens in variable keys messes up text/template, which parses
// context values below
vars["echo_url"] = "http://localhost:8000/some-endpoint"
vars["content_type"] = "application/json"
return workflow.Workflow{
Name: "Post to Echo Server",
Variables: vars,
Steps: []workflow.Step{
workflow.Step{
Name: "Make Request",
Type: "post-to-web",
Context: map[string]string{
"url": "{{.Defaults.echo_url}}",
"content-type": "{{.Defaults.content_type}}",
},
Register: "echo_data"},
},
}
}
func postToEchoServerAndLog() workflow.Workflow {
// Make a request against https://hub.docker.com/r/jspc/go-echo-http-server/
// Log the output
vars := make(map[string]string)
vars["echo_url"] = "http://localhost:8000/some-endpoint"
vars["content_type"] = "application/json"
return workflow.Workflow{
Name: "Post and Log Echo Server",
Variables: vars,
Steps: []workflow.Step{
workflow.Step{
Name: "Make Request",
Type: "post-to-web",
Context: map[string]string{
"url": "{{.Defaults.echo_url}}",
"content-type": "{{.Defaults.content_type}}",
},
Register: "echo_data"},
workflow.Step{
Name: "Log Output",
Type: "log",
Context: map[string]string{
// Note: there are workarounds for hyphenated keys, as below
"message": "user agent set to: {{index .echo_data.Headers \"User-Agent\"}}",
},
},
},
}
}