-
Notifications
You must be signed in to change notification settings - Fork 0
/
series.go
61 lines (51 loc) · 935 Bytes
/
series.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
package main
import (
"fmt"
"io/ioutil"
"math/big"
"net/http"
"net/url"
"os"
"os/signal"
"syscall"
"time"
)
func series(c chan *big.Int) {
var i int64
for {
c <- big.NewInt(i)
time.Sleep(250 * time.Millisecond)
i++
}
}
func main() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
var c = make(chan *big.Int)
go series(c)
active := true
go func() {
<-sigs
signal.Stop(sigs)
active = false
}()
for active {
var URL *url.URL
URL, err := url.Parse("http://localhost:12345/")
if err != nil {
panic(err)
}
n := <-c
parameters := url.Values{}
parameters.Add("n", n.String())
URL.RawQuery = parameters.Encode()
resp, err := http.Get(URL.String())
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
fmt.Printf("N: %v, A: %v\n", n.String(), string(body))
}
fmt.Println("See you later")
}