top | item 12871069

Execute Gin, Iris, Gorilla or Whatever Else on AWS Lambda Seamlessly

2 points| fsenart | 9 years ago

Before:

    package main
    
    import (
      "net/http"
    
      "github.com/gin-gonic/gin"
    )
    
    var r *gin.Engine
    
    func handle(ctx *gin.Context) {
      ctx.String(http.StatusOK, "Hello, %s!", ctx.Param("name"))
    }
    
    func init() {
      r = gin.Default()
      r.GET("/hello/:name", handle)
    }
    
    func main() {
      r.Run(":8080")
    }
After:

    package main
    
    import (
      "net/http"
    
      "github.com/eawsy/aws-lambda-go-net/service/lambda/runtime/net"
    
      "github.com/gin-gonic/gin"
    )
    
    var r *gin.Engine
    
    func handle(ctx *gin.Context) {
      ctx.String(http.StatusOK, "Hello, %s!", ctx.Param("name"))
    }
    
    func init() {
      r = gin.Default()
      r.GET("/hello/:name", handle)
    
      go http.Serve(net.Listener(), r)
    }
    
    func main() {
    }
Spot the difference :)

BTW https://github.com/eawsy/aws-lambda-go-net

discuss

order

No comments yet.