一个无缝的方式执行Go web应用程序在AWS Lambda和AWS API 网关

一个无缝的方式执行Go web应用程序在AWS Lambda和AWS API 网关

Go Web框架

访问GitHub主页

共152Star

详细介绍

Powered by Amazon Web Services Created by eawsy

eawsy/aws-lambda-go-net

A seamless way to execute Go web applications on AWS Lambda and AWS API Gateway.

Runtime Api Chat Status License Hire us

AWS Lambda lets you run code without provisioning or managing servers. AWS API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale.

This projects provides an AWS Lambda network interface for Go. You can leverage AWS Lambda and AWS API Gateway to handle web requests using any Go application framework.

Preview

Below are some examples with popular Go frameworks. These examples are not exhaustive. You are free to use anything you want!

go get -u -d github.com/eawsy/aws-lambda-go-net/...

Using Go

package main

import (
  "net/http"

  "github.com/eawsy/aws-lambda-go-net/service/lambda/runtime/net"
)

func handle(w http.ResponseWriter, r *http.Request) {
  w.Write([]byte("Hello, World!"))
}

func init() {
  go http.Serve(net.Listener(), http.HandlerFunc(handle))
}

func main() {}

Using Gin

go get gopkg.in/gin-gonic/gin.v1
package main

import (
  "net/http"

  "github.com/eawsy/aws-lambda-go-net/service/lambda/runtime/net"

  "github.com/gin-gonic/gin"
)

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() {}

Using Gorilla

go get -u github.com/gorilla/mux
package main

import (
  "fmt"
  "net/http"

  "github.com/eawsy/aws-lambda-go-net/service/lambda/runtime/net"

  "github.com/gorilla/mux"
)

func handle(w http.ResponseWriter, r *http.Request) {
  w.Write([]byte(fmt.Sprintf("Hello, %s!", mux.Vars(r)["name"])))
}

func init() {
  r := mux.NewRouter()
  r.HandleFunc("/hello/{name}", handle)
  go http.Serve(net.Listener(), r)
}

func main() {}

Documentation

This wiki is the main source of documentation for developers working with or contributing to the project.

About

eawsy

This project is maintained and funded by Alsanium, SAS.

We ❤️ AWS and open source software. See our other projects, or hire us to help you build modern applications on AWS.

License

This product is licensed to you under the Apache License, Version 2.0 (the "License"); you may not use this product except in compliance with the License. See LICENSE and NOTICE for more information.

Trademark

Alsanium, eawsy, the "Created by eawsy" logo, and the "eawsy" logo are trademarks of Alsanium, SAS. or its affiliates in France and/or other countries.

Amazon Web Services, the "Powered by Amazon Web Services" logo, and AWS Lambda are trademarks of Amazon.com, Inc. or its affiliates in the United States and/or other countries.