forked from sensible-contract/satotx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_aws.go
47 lines (39 loc) · 1.23 KB
/
main_aws.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 main
import (
"context"
"log"
"satotx/controller"
"time"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
ginadapter "github.com/awslabs/aws-lambda-go-api-proxy/gin"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
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.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
return ginLambda.ProxyWithContext(ctx, req)
}
func main() {
lambda.Start(Handler)
}