-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoexample.go
58 lines (42 loc) · 1.3 KB
/
goexample.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
package main
import (
"bytes"
"fmt"
"os"
"strings"
"varnish"
)
var storage_data []string
func my_storage(data [][]byte) []byte {
strdata := bytes.Join(data, []byte(" "))
storage_data = append(storage_data, string(strdata))
all := strings.Join(storage_data, "\n")
result := "Yep, it works! Storage:\n" + all
return []byte(result)
}
func main() {
if varnish.IsLinuxMain() {
return
}
varnish.OnBackendGet(func(url string, conf string) {
varnish.HttpSet("X-Go: GET")
res1, err := varnish.StorageCall("my_storage", []byte("Some input byte data"))
if err != nil {
varnish.Deliver(500, "text/plain", []byte("Storage call []byte failed"))
}
res2, err := varnish.StorageCallV("my_storage",
[][]byte{[]byte("Some"), []byte("Data"), []byte("For"), []byte("Storage"), []byte("!")})
if err != nil {
varnish.Deliver(500, "text/plain", []byte("Storage call []string failed"))
}
var b = append(append(res1, []byte("\n")...), res2...)
varnish.Deliver(200, "text/plain", b)
})
varnish.OnBackendPost(func(url string, conf string, content_type string, content []byte) {
varnish.HttpSet("X-Go: POST")
varnish.Deliver(200, content_type, content)
})
varnish.StorageRegister("my_storage", my_storage)
fmt.Println("Go Compute Example ready (", os.Args[2], ")")
varnish.WaitForRequests()
}