Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Start ¶
Start is analogous to lambda.Start() but takes a *gin.Engine argument instead of a handler function. The engine should have any desired routes initialized but should not be run.
Example ¶
package main
import (
"net/http"
"github.com/dgravesa/ginlambda"
"github.com/gin-gonic/gin"
)
var r *gin.Engine
func init() {
r = gin.Default()
r.GET("/greeting", func(c *gin.Context) {
c.String(http.StatusOK, "Hello, World!")
})
}
func main() {
ginlambda.Start(r)
}
Types ¶
type HandlerFunc ¶
type HandlerFunc func(context.Context, events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)
HandlerFunc is the signature for the Lambda handler function.
func NewHandler ¶
func NewHandler(r *gin.Engine) HandlerFunc
NewHandler creates a new Lambda handler function from a *gin.Engine instance. This handler may be passed as the handler argument to lambda.Start().
Example ¶
package main
import (
"context"
"fmt"
"net/http"
"github.com/aws/aws-lambda-go/events"
"github.com/dgravesa/ginlambda"
"github.com/gin-gonic/gin"
)
func main() {
// initialize gin route
r := gin.Default()
r.GET("/greeting/:userName", func(c *gin.Context) {
userName := c.Param("userName")
c.String(http.StatusOK, "Hello, %s!", userName)
})
// test request
request := events.APIGatewayProxyRequest{
HTTPMethod: "GET",
Path: "/greeting/Bruce",
}
// construct lambda handler from gin engine
handler := ginlambda.NewHandler(r)
// execute request
response, _ := handler(context.Background(), request)
fmt.Println(response.StatusCode, response.Body)
}
Output: 200 Hello, Bruce!
Click to show internal directories.
Click to hide internal directories.