File: endpoint.go

package info (click to toggle)
toxiproxy 2.0.0%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 388 kB
  • ctags: 321
  • sloc: sh: 91; makefile: 59
file content (44 lines) | stat: -rw-r--r-- 772 bytes parent folder | download | duplicates (2)
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
package main

import (
	"encoding/hex"
	"fmt"
	"net/http"
)

var stuff []byte
var out []byte
var out2 []byte

func handler1(w http.ResponseWriter, r *http.Request) {
	n, err := w.Write(out)
	if n != len(out) {
		fmt.Println("Short write!")
	}
	if err != nil {
		fmt.Println(err)
	}
}

func handler2(w http.ResponseWriter, r *http.Request) {
	n, err := w.Write(out2)
	if n != len(out2) {
		fmt.Println("Short write!")
	}
	if err != nil {
		fmt.Println(err)
	}
}

func main() {
	stuff = make([]byte, 32*1024)
	out = make([]byte, len(stuff)*2)
	out2 = []byte("hello world")
	for i := 0; i < len(stuff); i++ {
		stuff[i] = byte(i % 256)
	}
	hex.Encode(out, stuff)
	http.HandleFunc("/test1", handler1)
	http.HandleFunc("/test2", handler2)
	http.ListenAndServe(":20002", nil)
}