forked from sensible-contract/satotx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_scf.go
46 lines (39 loc) · 1.23 KB
/
main_scf.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
package main
import (
"context"
"github.com/gin-contrib/cors"
"log"
"satotx/controller"
"time"
"github.com/gin-gonic/gin"
ginadapter "github.com/linthan/scf-go-api-proxy/gin"
"github.com/tencentyun/scf-go-lib/cloudfunction"
"github.com/tencentyun/scf-go-lib/events"
)
var ginLambda *ginadapter.GinLambda
func init() {
log.Println("Gin cold start")
router := gin.Default()
router.Use(cors.New(cors.Config{
AllowOrigins: []string{"*"},
AllowMethods: []string{"GET", "POST", "OPTIONS"},
AllowHeaders: []string{"Content-Type,Origin,Content-Encoding"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
return true
},
MaxAge: 12 * time.Hour,
}))
router.GET("/", controller.Satotx)
router.POST("/utxo/:txid/:index", controller.SignUtxo)
router.POST("/utxo-spend-by/:txid/:index/:byTxid", controller.SignUtxoSpendBy)
router.POST("/utxo-spend-by-utxo/:txid/:index/:byTxid/:byTxindex", controller.SignUtxoSpendByUtxo)
ginLambda = ginadapter.New(router)
}
func Handler(ctx context.Context, req events.APIGatewayRequest) (events.APIGatewayResponse, error) {
return ginLambda.ProxyWithContext(ctx, req)
}
func main() {
cloudfunction.Start(Handler)
}