mirror of
https://github.com/mitchell/lambdarouter.git
synced 2025-12-17 22:17:22 +00:00
First iteration of v1 lambdarouter, full API change
This commit is contained in:
parent
83bb9a2aa1
commit
f65f17158c
12 changed files with 376 additions and 392 deletions
5
examples/hello-world/.gitignore
vendored
Normal file
5
examples/hello-world/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Serverless directories
|
||||
.serverless
|
||||
|
||||
# golang output binary directory
|
||||
bin
|
||||
10
examples/hello-world/Makefile
Normal file
10
examples/hello-world/Makefile
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
.PHONY: all build clean deploy test
|
||||
|
||||
build:
|
||||
env GOOS=linux go build -ldflags="-s -w" -o ./bin/hello ./main.go
|
||||
|
||||
clean:
|
||||
rm -rf ./bin
|
||||
|
||||
deploy: clean build
|
||||
sls deploy --verbose
|
||||
47
examples/hello-world/main.go
Normal file
47
examples/hello-world/main.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/aws/aws-lambda-go/events"
|
||||
"github.com/aws/aws-lambda-go/lambda"
|
||||
"github.com/mitchell/lambdarouter"
|
||||
)
|
||||
|
||||
var r = lambdarouter.New("hellosrv")
|
||||
|
||||
func init() {
|
||||
r.Post("hello", lambda.NewHandler(func() (events.APIGatewayProxyResponse, error) {
|
||||
return events.APIGatewayProxyResponse{
|
||||
StatusCode: http.StatusCreated,
|
||||
Body: "hello world",
|
||||
}, nil
|
||||
}))
|
||||
|
||||
r.Group("hello", func(r *lambdarouter.Router) {
|
||||
r.Get("{name}", lambda.NewHandler(func(req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
|
||||
return events.APIGatewayProxyResponse{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: "hello " + req.PathParameters["name"],
|
||||
}, nil
|
||||
}))
|
||||
|
||||
r.Put("french", lambda.NewHandler(func() (events.APIGatewayProxyResponse, error) {
|
||||
return events.APIGatewayProxyResponse{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: "bonjour le monde",
|
||||
}, nil
|
||||
}))
|
||||
|
||||
r.Get("french/{prenom}", lambda.NewHandler(func(req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
|
||||
return events.APIGatewayProxyResponse{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: "bonjour " + req.PathParameters["prenom"],
|
||||
}, nil
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
lambda.StartHandler(r)
|
||||
}
|
||||
42
examples/hello-world/serverless.yml
Normal file
42
examples/hello-world/serverless.yml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
service: lambdarouter-hello-world
|
||||
frameworkVersion: ">=1.28.0 <2.0.0"
|
||||
|
||||
provider:
|
||||
name: aws
|
||||
runtime: go1.x
|
||||
stage: ${opt:stage, 'dev'}
|
||||
region: us-west-2
|
||||
# iamRoleStatements:
|
||||
# environment:
|
||||
|
||||
package:
|
||||
exclude:
|
||||
- ./**
|
||||
include:
|
||||
- ./bin/**
|
||||
|
||||
functions:
|
||||
hello:
|
||||
handler: bin/hello
|
||||
events:
|
||||
- http:
|
||||
path: hellosrv/hello
|
||||
method: post
|
||||
- http:
|
||||
path: hellosrv/hello/{name}
|
||||
method: get
|
||||
request:
|
||||
parameters:
|
||||
path:
|
||||
name: true
|
||||
- http:
|
||||
path: hellosrv/hello/french
|
||||
method: put
|
||||
- http:
|
||||
path: hellosrv/hello/french/{prenom}
|
||||
method: get
|
||||
request:
|
||||
parameters:
|
||||
path:
|
||||
prenom: true
|
||||
#resources:
|
||||
Loading…
Add table
Add a link
Reference in a new issue