-
Notifications
You must be signed in to change notification settings - Fork 8
/
proxy.go
47 lines (36 loc) · 849 Bytes
/
proxy.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
package transports
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"github.com/fukata/golang-stats-api-handler"
)
type Proxy struct {
Port int
Transport interface{}
}
func (proxy *Proxy) Listen() {
fmt.Println("Proxy listening on", proxy.Port)
err := errors.New("no transport specified")
if proxy.Transport == nil {
panic(err)
}
// transport := proxy.Transport.(FacebookTransport)
transport := proxy.Transport.(WhatsappTransport)
transport.Prepare()
http.HandleFunc("/", transport.Handler)
http.HandleFunc( "/stats", stats_api.Handler )
http.ListenAndServe(":8080", nil)
return
}
func MarshalRequest(request *http.Request) []byte {
r := Request{
Method: request.Method,
URL: request.URL.String(),
Proto: request.Proto,
Headers: request.Header,
}
output, _ := json.Marshal(r)
return output
}