-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5.go
More file actions
59 lines (53 loc) · 1.42 KB
/
5.go
File metadata and controls
59 lines (53 loc) · 1.42 KB
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 (
"fmt"
"net/http"
"github.com/hydrogen18/stalecucumber"
)
func main() {
resp, err := http.Get("http://www.pythonchallenge.com/pc/def/banner.p")
if err != nil {
fmt.Println("resp/err", err)
}
defer resp.Body.Close()
// some stalecucumber magic
unpickled, err := stalecucumber.Unpickle(resp.Body)
if err != nil {
fmt.Println("stale/err", err)
}
data, ok := unpickled.([]interface{})
if !ok {
fmt.Println("assert/data", "not []interface{}")
}
// loop through line by line
for _, d := range data {
sub, ok := d.([]interface{})
if !ok {
fmt.Println("assert/sub", "not []interface{}")
}
line := ""
for _, pair := range sub {
kv, ok := pair.([]interface{})
if !ok {
fmt.Println("assert/pair", "not []interface{}")
}
if len(kv) != 2 {
fmt.Println("assert/err", "not key-value pair")
}
k, ok := kv[0].(string)
if !ok {
fmt.Println("assert/not string")
}
v, ok := kv[1].(int64)
if !ok {
fmt.Println("assert/not int64 - has to be int64")
}
i := 0
for i < int(v) {
line += k
i++
}
}
fmt.Println("line/ ", line)
}
}