-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
40 lines (33 loc) · 913 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
31
32
33
34
35
36
37
38
39
40
package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/go-chi/chi/v5"
chiadapter "github.com/serverless-plus/tencent-serverless-go/chi"
"github.com/serverless-plus/tencent-serverless-go/events"
"github.com/serverless-plus/tencent-serverless-go/faas"
)
var chiFaas *chiadapter.ChiFaas
func init() {
fmt.Printf("Chi start")
r := chi.NewRouter()
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
buf, _ := json.Marshal(map[string]interface{}{
"message": "Hello Serverless Chi",
"query": r.URL.Query().Get("q"),
})
w.Write(buf)
})
chiFaas = chiadapter.New(r)
}
// Handler serverless faas handler
func Handler(ctx context.Context, req events.APIGatewayRequest) (events.APIGatewayResponse, error) {
return chiFaas.ProxyWithContext(ctx, req)
}
func main() {
faas.Start(Handler)
}