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

package main
import (
"context"
"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-gonic/gin"
"github.com/gissleh/stufflog/api"
"github.com/gissleh/stufflog/database"
"github.com/gissleh/stufflog/internal/auth"
"log"
"os"
)
func env(key string, defaultValue string) string {
e := os.Getenv(key)
if e == "" {
return defaultValue
}
return e
}
func main() {
dbDriver := env("DB_DRIVER", "postgres")
dbConnect := env("DB_CONNECT", "")
gin.SetMode(gin.ReleaseMode)
db, err := database.Open(context.Background(), dbDriver, dbConnect)
if err != nil {
log.Println("Failed to open database:", err)
os.Exit(1)
}
server := gin.New()
server.Use(auth.TrustingJwtParserMiddleware())
api.Group(server.Group("/api/group"), db)
api.Item(server.Group("/api/item"), db)
api.Project(server.Group("/api/project"), db)
api.Task(server.Group("/api/task"), db)
api.Log(server.Group("/api/log"), db)
api.Goal(server.Group("/api/goal"), db)
ginLambda := ginadapter.New(server)
lambda.Start(func(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
return ginLambda.ProxyWithContext(ctx, request)
})
}