-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (33 loc) · 1001 Bytes
/
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
package main
import (
"flag"
"fmt"
"github.com/Shopify/toxiproxy/client"
"time"
)
var tpHost = flag.String("tp_host", "localhost", "Toxiproxy host")
var tpPort = flag.Int("tp_port", 8474, "Toxiproxy port")
var host = flag.String("host", "localhost", "Host that will be proxied")
var listenPort = flag.Int("listen", 18811, "Listen port for Toxiproxy")
var upstreamPort = flag.Int("upstream", 8811, "Upstream port for Toxiproxy")
func main() {
flag.Parse()
client := toxiproxy.NewClient(fmt.Sprintf("%v:%v", *tpHost, *tpPort))
proxy, err := client.CreateProxy("server", fmt.Sprintf(":%v", *listenPort), fmt.Sprintf("%v:%v", *host, *upstreamPort))
if err != nil {
fmt.Println("Failed to create proxy")
panic(err)
}
defer func() {
_ = proxy.Delete()
}()
_, err = proxy.AddToxic("latency_down", "latency", "", 1.0, toxiproxy.Attributes{
"latency": 1000,
})
if err != nil {
fmt.Println("Error occurred while adding toxic")
panic(err)
}
ch := time.After(time.Hour)
<-ch
}