Skip to content

Commit f65f171

Browse files
committed
First iteration of v1 lambdarouter, full API change
1 parent 83bb9a2 commit f65f171

File tree

12 files changed

+370
-386
lines changed

12 files changed

+370
-386
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ go:
44
- 1.x
55

66
before_install:
7-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
87
- curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
98

109
install:
10+
- dep ensure -v
11+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
1112
- chmod +x ./cc-test-reporter
12-
- dep ensure
1313

1414
before_script:
1515
- ./cc-test-reporter before-build

Gopkg.lock

Lines changed: 39 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,9 @@
2424
# go-tests = true
2525
# unused-packages = true
2626

27-
28-
[[constraint]]
29-
branch = "master"
30-
name = "github.com/armon/go-radix"
31-
3227
[[constraint]]
3328
name = "github.com/aws/aws-lambda-go"
34-
version = "1.2.0"
35-
36-
[[constraint]]
37-
name = "github.com/smartystreets/goconvey"
38-
version = "1.6.3"
29+
version = "1.x"
3930

4031
[prune]
4132
go-tests = true

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
# lambdarouter
2-
[![GoDoc Reference](https://godoc.org/github.com/mitchelljfs/lambdarouter?status.svg)](https://godoc.org/github.com/mitchelljfs/lambdarouter)
2+
[![GoDoc Reference](https://godoc.org/github.com/mitchell/lambdarouter?status.svg)](https://godoc.org/github.com/mitchell/lambdarouter)
33
[![Build Status](https://travis-ci.org/mitchell/lambdarouter.svg?branch=master)](https://travis-ci.org/mitchell/lambdarouter)
44
[![Test Coverage](https://api.codeclimate.com/v1/badges/7270c6c4017b36d07360/test_coverage)](https://codeclimate.com/github/mitchelljfs/lambdarouter/test_coverage)
55
[![Maintainability](https://api.codeclimate.com/v1/badges/7270c6c4017b36d07360/maintainability)](https://codeclimate.com/github/mitchelljfs/lambdarouter/maintainability)
6-
[![Go Report Card](https://goreportcard.com/badge/github.com/mitchelljfs/lambdarouter)](https://goreportcard.com/report/github.com/mitchelljfs/lambdarouter)
6+
[![Go Report Card](https://goreportcard.com/badge/github.com/mitchell/lambdarouter)](https://goreportcard.com/report/github.com/mitchell/lambdarouter)
77

8-
So far this package can create a router and routes whose execution utilizes a middleware context pattern, all in one Golang Lambda function. It has full test coverage, and is currently deployed in numerous services where I am employed. Check out the GoDoc Reference to see how to instantiate a router and create endpoints.
8+
This package contains a router capable of routing many AWS Lambda API gateway requests to anything
9+
that implements the aws-lambda-go/lambda.Handler interface, all in one Lambda function. It plays
10+
especially well with go-kit's awslambda transport package. Get started by reading below and visiting
11+
the [GoDoc reference](https://godoc.org/github.com/mitchell/lambdarouter).
12+
13+
## Initializing a Router
14+
```
15+
r := lambdarouter.New("prefix/")
16+
17+
r.Get("hello/{name}", helloHandler)
18+
r.Post("hello/server", helloHandler)
19+
r.Delete("hello", lambda.NewHandler(func() (events.APIGatewayProxyResponse, error) {
20+
return events.APIGatewayProxyResponse{
21+
Body: "nothing to delete",
22+
}, nil
23+
}))
24+
25+
lambda.StartHandler(r)
26+
```
27+
28+
Check out the `examples/` folder for more fleshed out examples in the proper context.

examples/hello-world/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Serverless directories
2+
.serverless
3+
4+
# golang output binary directory
5+
bin

examples/hello-world/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.PHONY: all build clean deploy test
2+
3+
build:
4+
env GOOS=linux go build -ldflags="-s -w" -o ./bin/hello ./main.go
5+
6+
clean:
7+
rm -rf ./bin
8+
9+
deploy: clean build
10+
sls deploy --verbose

examples/hello-world/main.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/aws/aws-lambda-go/events"
7+
"github.com/aws/aws-lambda-go/lambda"
8+
"github.com/mitchell/lambdarouter"
9+
)
10+
11+
var r = lambdarouter.New("hellosrv")
12+
13+
func init() {
14+
r.Post("hello", lambda.NewHandler(func() (events.APIGatewayProxyResponse, error) {
15+
return events.APIGatewayProxyResponse{
16+
StatusCode: http.StatusCreated,
17+
Body: "hello world",
18+
}, nil
19+
}))
20+
21+
r.Group("hello", func(r *lambdarouter.Router) {
22+
r.Get("{name}", lambda.NewHandler(func(req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
23+
return events.APIGatewayProxyResponse{
24+
StatusCode: http.StatusOK,
25+
Body: "hello " + req.PathParameters["name"],
26+
}, nil
27+
}))
28+
29+
r.Put("french", lambda.NewHandler(func() (events.APIGatewayProxyResponse, error) {
30+
return events.APIGatewayProxyResponse{
31+
StatusCode: http.StatusOK,
32+
Body: "bonjour le monde",
33+
}, nil
34+
}))
35+
36+
r.Get("french/{prenom}", lambda.NewHandler(func(req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
37+
return events.APIGatewayProxyResponse{
38+
StatusCode: http.StatusOK,
39+
Body: "bonjour " + req.PathParameters["prenom"],
40+
}, nil
41+
}))
42+
})
43+
}
44+
45+
func main() {
46+
lambda.StartHandler(r)
47+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
service: lambdarouter-hello-world
2+
frameworkVersion: ">=1.28.0 <2.0.0"
3+
4+
provider:
5+
name: aws
6+
runtime: go1.x
7+
stage: ${opt:stage, 'dev'}
8+
region: us-west-2
9+
# iamRoleStatements:
10+
# environment:
11+
12+
package:
13+
exclude:
14+
- ./**
15+
include:
16+
- ./bin/**
17+
18+
functions:
19+
hello:
20+
handler: bin/hello
21+
events:
22+
- http:
23+
path: hellosrv/hello
24+
method: post
25+
- http:
26+
path: hellosrv/hello/{name}
27+
method: get
28+
request:
29+
parameters:
30+
path:
31+
name: true
32+
- http:
33+
path: hellosrv/hello/french
34+
method: put
35+
- http:
36+
path: hellosrv/hello/french/{prenom}
37+
method: get
38+
request:
39+
parameters:
40+
path:
41+
prenom: true
42+
#resources:

go.mod

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module github.com/mitchell/lambdarouter
2+
3+
require (
4+
github.com/aws/aws-lambda-go v1.10.0
5+
github.com/davecgh/go-spew v1.1.1 // indirect
6+
github.com/hashicorp/go-immutable-radix v1.0.0
7+
github.com/hashicorp/golang-lru v0.5.1 // indirect
8+
github.com/stretchr/testify v1.3.0
9+
)

go.sum

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
github.com/aws/aws-lambda-go v1.10.0 h1:uafgdfYGQD0UeT7d2uKdyWW8j/ZYRifRPIdmeqLzLCk=
2+
github.com/aws/aws-lambda-go v1.10.0/go.mod h1:zUsUQhAUjYzR8AuduJPCfhBuKWUaDbQiPOG+ouzmE1A=
3+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0=
7+
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
8+
github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM=
9+
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
10+
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
11+
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
12+
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
13+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
14+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
16+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
17+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

0 commit comments

Comments
 (0)