daily pastebin goal
26%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "encoding/json"
  5.     "log"
  6.  
  7.     "github.com/aws/aws-lambda-go/events"
  8.     "github.com/aws/aws-lambda-go/lambda"
  9. )
  10.  
  11. type repositories struct {
  12.     repo    infra.Repository
  13. }
  14.  
  15. func (repo *repositories) handleRequest(event *events.SNSEvent) {
  16.     for _, r := range event.Records {
  17.         var s3event events.S3Event
  18.         if err := json.Unmarshal([]byte(r.SNS.Message), &s3event); err != nil {
  19.             log.Printf("failed to parse S3 event. err: %v", err)
  20.         }
  21.         repo.handleS3Event(&s3event)
  22.     }
  23. }
  24.  
  25. func (repo *repositories) handleS3Event(s3event *events.S3Event) {
  26.     for _, r := range s3event.Records {
  27.         filePath := r.S3.Object.Key
  28.         repo.Insert(filePath)
  29.     }
  30. }
  31.  
  32. func main() {
  33.   // 初期のenvの読み込み
  34.     s, err := getSpec()
  35.     if err != nil {
  36.         log.Fatalf("[ERROR] failed to load env: %s", err)
  37.     }
  38.   // DBのConnection生成
  39.     db, err := openDB(s)
  40.     if err != nil {
  41.         log.Fatalf("[ERROR] Failed to connect database: %s", err)
  42.     }
  43.     repo := infra.NewRepository(db)
  44.  
  45.     reops := repositories{repo: repo}
  46.     lambda.Start(repos.handleRequest)
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top