forked from testcontainers/testcontainers-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
echoserver.go
48 lines (36 loc) · 946 Bytes
/
echoserver.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
package main
import (
"fmt"
"log"
"net"
"net/http"
"os"
)
func envHandler() http.HandlerFunc {
return func(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte(os.Getenv("FOO")))
rw.WriteHeader(http.StatusAccepted)
}
}
func echoHandler(destination *os.File) http.HandlerFunc {
return func(rw http.ResponseWriter, req *http.Request) {
echo := req.URL.Query()["echo"][0]
l := log.New(destination, "echo ", 0)
l.Println(echo)
rw.WriteHeader(http.StatusAccepted)
}
}
// a simple server that will echo whatever is in the "echo" parameter to stdout
// in the /stdout endpoint or to stderr in the /stderr endpoint
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/stdout", echoHandler(os.Stdout))
mux.HandleFunc("/stderr", echoHandler(os.Stderr))
mux.HandleFunc("/env", envHandler())
ln, err := net.Listen("tcp", ":8080")
if err != nil {
panic(err)
}
fmt.Println("ready")
http.Serve(ln, mux)
}