-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
66 lines (57 loc) · 1.51 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
package main
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
"os"
)
const Version = "mock-1.0.2"
const Build = "nov-6-2017"
//
// Main Method
//
func main() {
//
route := mux.NewRouter()
//
// Admin flows
//
route.HandleFunc("/v1/version", VersionHandler).
Methods("GET")
route.HandleFunc("/admin/exit", ExitHandler).
Methods("GET")
//
// mocks
//
//auth flow
route.HandleFunc("/v1/charges", AuthauthorizeHandler).
Methods("POST").Headers("Content-Type", "application/x-www-form-urlencoded")
//capture flow
route.HandleFunc("/v1/charges/{id}/capture", CaptureHandler).
Methods("POST").Headers("Content-Type", "application/x-www-form-urlencoded")
//refund flow
route.HandleFunc("/v1/charges/{id}/refunds", RefundsHandler).
Methods("POST").Headers("Content-Type", "application/x-www-form-urlencoded")
//start server
log.Fatal(http.ListenAndServe(":8080", route))
}
//
// Handle version request
//
func VersionHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "{\"version\": \"" + Version + "\", \"build_date\":\"" + Build + "\"}")
log.Println("VersionHandler:Init")
//write http status
w.WriteHeader(200)
}
//
// Handle Exit request
//
func ExitHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "{\"version\": \"mock-1.0.1\", \"exit\":\"OK\"}")
log.Println("ExitHandler:Init")
//write http status
w.WriteHeader(200)
os.Exit(3)
}