Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit dc1d75d

Browse files
authored
docs: Document standard library usage
1 parent 0f07840 commit dc1d75d

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

README.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,50 @@
1-
## AWS Lambda Go Api Proxy [![Build Status](https://travis-ci.org/awslabs/aws-lambda-go-api-proxy.svg?branch=master)](https://travis-ci.org/awslabs/aws-lambda-go-api-proxy)
2-
aws-lambda-go-api-proxy makes it easy to run Golang APIs written with frameworks such as [Gin](https://github.com/gin-gonic/gin) with AWS Lambda and Amazon API Gateway.
1+
## AWS Lambda Go API Proxy [![Build Status](https://travis-ci.org/awslabs/aws-lambda-go-api-proxy.svg?branch=master)](https://travis-ci.org/awslabs/aws-lambda-go-api-proxy)
2+
aws-lambda-go-api-proxy makes it easy to run Go APIs written with frameworks such as [Gin](https://github.com/gin-gonic/gin) with AWS Lambda and Amazon API Gateway.
33

44
## Getting started
5-
The first step is to install the required dependencies
5+
6+
Install required dependencies.
67

78
```bash
8-
# First, we install the Lambda go libraries
9+
# First, install the Lambda go libraries.
910
$ go get github.com/aws/aws-lambda-go/events
1011
$ go get github.com/aws/aws-lambda-go/lambda
1112

12-
# Next, we install the core library
13+
# Next, install the core library.
1314
$ go get github.com/awslabs/aws-lambda-go-api-proxy/...
1415
```
1516

16-
Following the instructions from the [Lambda documentation](https://docs.aws.amazon.com/lambda/latest/dg/go-programming-model-handler-types.html), we need to declare a `Handler` method for our main package. We will declare a `ginadapter.GinLambda` object
17-
in the global scope, initialized once it in the Handler with all its API methods, and then use the `Proxy` method to translate requests and responses
17+
### Standard library
18+
19+
To use with the standard library, the `httpadaptor.New` function takes in a `http.Handler`. The `ProxyWithContent` method on the `httpadapter.HandlerAdapter` can then be used as a Lambda handler.
20+
21+
```go
22+
package main
23+
24+
import (
25+
"io"
26+
"net/http"
27+
28+
"github.com/aws/aws-lambda-go/lambda"
29+
"github.com/awslabs/aws-lambda-go-api-proxy/httpadapter"
30+
)
31+
32+
func main() {
33+
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
34+
io.WriteString(w, "Hello")
35+
})
36+
37+
lambda.Start(httpadapter.New(http.DefaultServeMux).ProxyWithContext)
38+
}
39+
```
40+
41+
### Gin
42+
43+
To use with the Gin framework, following the instructions from the [Lambda documentation](https://docs.aws.amazon.com/lambda/latest/dg/go-programming-model-handler-types.html), declare a `Handler` method for the main package.
44+
45+
Declare a `ginadapter.GinLambda` object in the global scope, and initialize it in the `init` function, adding all API methods.
46+
47+
The `ProxyWithContext` method is then used to translate requests and responses.
1848

1949
```go
2050
package main

0 commit comments

Comments
 (0)