-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (54 loc) · 1.28 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
ch "ApiGateway/cache"
hd "ApiGateway/handlers"
"fmt"
"github.com/gorilla/mux"
"net/http"
"os"
"strconv"
)
var h hd.Handler
var c ch.RouteCache
func main() {
var cid string
var key string
fmt.Print("args: ")
fmt.Println(len(os.Args))
if len(os.Args) == 3 {
cid = os.Args[1]
key = os.Args[2]
}
//fmt.Print("cid: ")
//fmt.Println(cid)
//fmt.Print("key: ")
//fmt.Println(key)
h.Cache = c
if cid == "" {
cid = getClientID()
}
if key == "" {
key = getAPIKey()
}
h.ClientID, _ = strconv.ParseInt(cid, 10, 0)
h.APIKey = key
//fmt.Print("cid: ")
//fmt.Println(h.ClientID)
//fmt.Print("key: ")
//fmt.Println(h.APIKey)
fmt.Println("Api Gateway running inside network on port 3020!")
router := mux.NewRouter()
//gateway routes
//disgard router.HandleFunc("/np/{route}/{rname}/{fpath:[^.]+}", h.HandleGwRoute)
router.HandleFunc("/np/{route}/{rname}/{fpath:[^ ]+}", h.HandleGwRoute)
router.HandleFunc("/{route}/{fpath:[^ ]+}", h.HandleGwRoute)
//disgard -- router.HandleFunc("/{route}/{fpath:[^.]+}", handleGwRoute)
router.HandleFunc("/{route}", h.HandleGwRoute)
http.ListenAndServe(":3020", router)
}
func getClientID() string {
return os.Getenv("API_GATEWAY_CLIENT_ID")
}
func getAPIKey() string {
return os.Getenv("API_GATEWAY_API_KEY")
}