-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add simple golang http endpoint example (#494)
* initial commit, serverless golang example * moving to aws folder for proper provider * updating naming convention * moving folders to match examples repo structure * moving into alignment with existing example repo
- Loading branch information
Showing
17 changed files
with
2,917 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
|
||
|
||
[[constraint]] | ||
name = "github.com/aws/aws-lambda-go" | ||
version = "1.x" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
build: | ||
dep ensure -v | ||
env GOOS=linux go build -ldflags="-s -w" -o bin/hello hello/main.go | ||
env GOOS=linux go build -ldflags="-s -w" -o bin/world world/main.go | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf ./bin ./vendor Gopkg.lock | ||
|
||
.PHONY: deploy | ||
deploy: clean build | ||
sls deploy --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/aws/aws-lambda-go/lambda" | ||
) | ||
|
||
// Response is of type APIGatewayProxyResponse since we're leveraging the | ||
// AWS Lambda Proxy Request functionality (default behavior) | ||
// | ||
// https://serverless.com/framework/docs/providers/aws/events/apigateway/#lambda-proxy-integration | ||
type Response events.APIGatewayProxyResponse | ||
|
||
// Handler is our lambda handler invoked by the `lambda.Start` function call | ||
func Handler(ctx context.Context) (Response, error) { | ||
var buf bytes.Buffer | ||
|
||
body, err := json.Marshal(map[string]interface{}{ | ||
"message": "Go Serverless v1.0! Your function executed successfully!", | ||
}) | ||
if err != nil { | ||
return Response{StatusCode: 404}, err | ||
} | ||
json.HTMLEscape(&buf, body) | ||
|
||
resp := Response{ | ||
StatusCode: 200, | ||
IsBase64Encoded: false, | ||
Body: buf.String(), | ||
Headers: map[string]string{ | ||
"Content-Type": "application/json", | ||
"X-MyCompany-Func-Reply": "hello-handler", | ||
}, | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
func main() { | ||
lambda.Start(Handler) | ||
} |
Oops, something went wrong.