You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.2 KiB

4 years ago
  1. package main
  2. import (
  3. "context"
  4. "github.com/aws/aws-lambda-go/events"
  5. "github.com/aws/aws-lambda-go/lambda"
  6. ginadapter "github.com/awslabs/aws-lambda-go-api-proxy/gin"
  7. "github.com/gin-gonic/gin"
  8. "github.com/gissleh/stufflog/api"
  9. "github.com/gissleh/stufflog/database"
  10. "github.com/gissleh/stufflog/internal/auth"
  11. "log"
  12. "os"
  13. )
  14. func env(key string, defaultValue string) string {
  15. e := os.Getenv(key)
  16. if e == "" {
  17. return defaultValue
  18. }
  19. return e
  20. }
  21. func main() {
  22. dbDriver := env("DB_DRIVER", "postgres")
  23. dbConnect := env("DB_CONNECT", "")
  24. gin.SetMode(gin.ReleaseMode)
  25. db, err := database.Open(context.Background(), dbDriver, dbConnect)
  26. if err != nil {
  27. log.Println("Failed to open database:", err)
  28. os.Exit(1)
  29. }
  30. server := gin.New()
  31. server.Use(auth.TrustingJwtParserMiddleware())
  32. api.Group(server.Group("/api/group"), db)
  33. api.Item(server.Group("/api/item"), db)
  34. api.Project(server.Group("/api/project"), db)
  35. api.Task(server.Group("/api/task"), db)
  36. api.Log(server.Group("/api/log"), db)
  37. api.Goal(server.Group("/api/goal"), db)
  38. ginLambda := ginadapter.New(server)
  39. lambda.Start(func(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
  40. return ginLambda.ProxyWithContext(ctx, request)
  41. })
  42. }