-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
30 lines (26 loc) · 745 Bytes
/
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
package main
import (
"bytes"
"fmt"
"net/http"
"github.com/nerney/serverless-rest-golang/api"
"github.com/nerney/serverless-rest-golang/models"
)
// run the endpoint locally
func main() {
fmt.Println("Server up @ :8080")
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
b := new(bytes.Buffer)
b.ReadFrom(r.Body)
res := api.Rest(models.Request{
HTTPMethod: r.Method,
PathParameters: map[string]string{"id": r.URL.Path[1:]},
Body: b.String(),
})
fmt.Printf("[%v] %v --> %v\n", r.Method, r.URL.RequestURI(), res.StatusCode)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(res.StatusCode)
w.Write([]byte(res.Body))
})
panic(http.ListenAndServe(":8080", nil))
}