-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapes.go
62 lines (52 loc) · 1.18 KB
/
apes.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
62
// Copyright 2020 Clivern. All rights reserved.
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package main
import (
"flag"
"fmt"
"log"
"net/http"
"github.com/clivern/apes/internal/app/controller"
"github.com/gorilla/mux"
)
var (
version = "dev"
commit = "none"
date = "unknown"
)
func main() {
var get string
var port int
var upstream string
var failRate string
var latency string
flag.IntVar(&port, "port", 8080, "port")
flag.StringVar(&upstream, "upstream", "https://httpbin.org", "upstream")
flag.StringVar(&failRate, "failRate", "10%", "failRate")
flag.StringVar(&latency, "latency", "0s", "latency")
flag.StringVar(&get, "get", "", "get")
flag.Parse()
if get == "release" {
fmt.Println(
fmt.Sprintf(
`Apes Version %v Commit %v, Built @%v`,
version,
commit,
date,
),
)
return
}
log.Printf(
"Starting apes chaos reverse proxy port=%d upstream=%s failRate=%s latency=%s",
port,
upstream,
failRate,
latency,
)
r := mux.NewRouter()
r.HandleFunc("/{path:.*}", controller.Proxy(upstream, failRate, latency))
http.Handle("/", r)
http.ListenAndServe(fmt.Sprintf(":%d", port), r)
}