-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.go
86 lines (69 loc) · 2.86 KB
/
handlers.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package client
import (
"fmt"
"net/http"
)
/*
Example Mo & Dr handlers
*/
const (
DEFAULT_MO_PATH = "/mock/mosms"
DEFAULT_DR_PATH = "/mock/drs"
)
// IFVERSION=201001&MONUMBER=447111222333&OPERATOR=o2-uk&DESTINATION=84988&BODY=This%20is%20a%20mobile%20originated%20test%20message&RECEIVETIME=20130202102030&GUID=7CDEB38F-4370-18FD-D7CE-329F21B99209&PRICE=15
func MoHandler(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
fmt.Fprintf(w, "ParseForm() err: %v", err)
w.WriteHeader(http.StatusBadRequest)
}
fmt.Println("MO REQUEST")
fmt.Println("Params: ", r.Form.Encode())
ifversion := r.FormValue("IFVERSION")
monumber := r.FormValue("MONUMBER")
operator := r.FormValue("OPERATOR")
destination := r.FormValue("DESTINATION")
body := r.FormValue("BODY")
receiveTime := r.FormValue("RECEIVETIME")
guid := r.FormValue("GUID")
price := r.FormValue("PRICE")
requestID := r.FormValue("REQUESTID")
fmt.Printf("IFVERSION: %s\nMONUMBER: %s\nOPERATOR: %s\nDESTINATION: %s\nBODY: %s\nRECEIVETIME: %s\nGUID: %s\nPRICE: %s\nREQUESTID: %s\n\n", ifversion, monumber, operator, destination, body, receiveTime, guid, price, requestID)
w.WriteHeader(http.StatusOK)
}
// IFVERSION=201001&OPERATOR=o2-uk&MONUMBER=447111222333&DESTINATION=84988
// &STATUSCODE=DELIVERED&STATUSTEXT=Delivered&STATUSTIME=20130202102030
// &PRICE=50&GUID=7CDEB38F-4370-18FD-D7CE-329F21B99209
func DrHandler(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
fmt.Fprintf(w, "ParseForm() err: %v", err)
w.WriteHeader(http.StatusBadRequest)
}
fmt.Println("DR REQUEST")
fmt.Println("Params: ", r.Form.Encode())
ifversion := r.FormValue("IFVERSION")
monumber := r.FormValue("MONUMBER")
operator := r.FormValue("OPERATOR")
destination := r.FormValue("DESTINATION")
body := r.FormValue("BODY")
receiveTime := r.FormValue("RECEIVETIME")
guid := r.FormValue("GUID")
price := r.FormValue("PRICE")
requestID := r.FormValue("REQUESTID")
duration := r.FormValue("DURATION")
retryCount := r.FormValue("RETRYCOUNT")
statusCode := r.FormValue("STATUSCODE")
statusTime := r.FormValue("STATUSTIME")
statusText := r.FormValue("STATUSTEXT")
fmt.Printf("IFVERSION: %s\nMONUMBER: %s\nOPERATOR: %s\nDESTINATION: %s\nBODY: %s\nRECEIVETIME: %s\nGUID: %s\nPRICE: %s\nREQUESTID: %s\nDURATION: %s\nRETRYCOUNT: %s\nSTATUSCODE: %s\nSTATUSTIME: %s\nSTATUSTEXT: %s\n\n", ifversion, monumber, operator, destination, body, receiveTime, guid, price, requestID, duration, retryCount, statusCode, statusTime, statusText)
w.WriteHeader(http.StatusOK)
}
func StartMockDrMoHandler(port int) {
portString := ":8090"
http.HandleFunc(DEFAULT_MO_PATH, MoHandler)
http.HandleFunc(DEFAULT_DR_PATH, DrHandler)
if port > 1024 && port < 65535 {
portString = fmt.Sprintf(":%d", port)
}
fmt.Printf("Starting mo/dr mock on port: %s\n", portString)
http.ListenAndServe(portString, nil)
}