-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (50 loc) · 1.33 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-lambda-go/lambdacontext"
)
//recomendaciones type
//input event: Proveedor a guardar
type recomendaciones struct {
Code string `json:"Code"`
ExternalCode string `json:"ExternalCode"`
Rut string `json:"Rut"`
Rubros string `json:"Rubros"`
Relevancia float32 `json:"Relevancia"`
Activo bool `json:"Activo"`
}
//PostRecomendaciones func
//Ingresa nuevas recomendaciones
func PostRecomendaciones(re recomendaciones) (bool, error) {
return postItem(re)
}
//PostResponse type
//output event: Response de la operacion
type PostResponse struct {
Message string `json:"Message"`
}
//HandleEvent func
func HandleEvent(ctx context.Context, event recomendaciones) (PostResponse, error) {
lc, _ := lambdacontext.FromContext(ctx)
log.Print(lc)
log.Print(lc.AwsRequestID)
log.Print(lc.InvokedFunctionArn)
resultado, err := PostRecomendaciones(event)
if err != nil {
fmt.Println("Dynamo call failed:")
fmt.Println((err.Error()))
os.Exit(1)
}
if resultado == true {
return PostResponse{Message: "Ok"}, nil
}
return PostResponse{Message: "No es posible almacenar el registro"}, nil
}
func main() {
// Make the handler available for Remote Procedure Call by AWS Lambda
lambda.Start(HandleEvent)
}