Skip to content

Commit

Permalink
adding more language support
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwelin committed Feb 10, 2020
1 parent 5b8c349 commit 308e9d8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 34 deletions.
40 changes: 6 additions & 34 deletions new-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ func initMap(projectName string) map[string]LanguageMapper {
"python": LanguageMapper{
AppFile: "app.py",
DepsFile: "requirements.txt",
TmplAppVar: "",
TmplDepsVar: "",
TmplAppVar: pythonFunction,
TmplDepsVar: requirementsFile,
AppPath: appPath,
DepsPath: appPath,
},
"ruby": LanguageMapper{
AppFile: "app.rb",
DepsFile: "Gemfile",
TmplAppVar: "",
TmplDepsVar: "",
TmplAppVar: rubyFunction,
TmplDepsVar: gemFile,
AppPath: appPath,
DepsPath: appPath,
},
"go": LanguageMapper{
AppFile: "main.go",
DepsFile: "go.mod",
TmplAppVar: "",
TmplDepsVar: "",
TmplAppVar: goFunction,
TmplDepsVar: goMod,
AppPath: appPath,
DepsPath: appPath,
},
Expand Down Expand Up @@ -153,31 +153,3 @@ func (tmpl *TmplData) bootstrapAPI() error {
}
return nil
}

/*func main() {
apiTmpl := &TmplData{
ApiProtocol: "rest",
ApiEndpoints: "regional",
LambdaFunctionName: "helloworld",
ApiProjectName: "Hello-World-API",
Language: "node",
}
err := apiTmpl.createFileFromTemplate(apiGWConf, "", "apigw.yml")
if err != nil {
panic(err)
}
err = apiTmpl.createFileFromTemplate(swagger, "", "swagger-api.yml")
if err != nil {
panic(err)
}
err = createFileFromStruct(languages[apiTmpl.Language])
if err != nil {
panic(err)
}
}
*/
64 changes: 64 additions & 0 deletions tmpl-languages.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,67 @@ def lambda_handler(event, context):
'body': json.dumps(dict)
}
`

const requirementsFile = `
`

// ruby
const rubyFunction = `
require 'json'
def handler(event:, context:)
{ statusCode: 200, body: JSON.generate('hello world') }
end
`
const gemFile = `
`

// go
const goFunction = `
package main
import (
"context"
"encoding/json"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
type Response events.APIGatewayProxyResponse
type helloWorld struct {
Msg string` + "`" + `json:"msg"` + "`" + `
}
func Handler(ctx context.Context) (Response, error) {
msg := helloWorld{Msg: "hwllo world"}
resp, err := json.Marshal(msg)
if err != nil {
return Response{StatusCode: 500}, err
}
gwResp := Response{
StatusCode: 200,
Body: string(resp),
Headers: map[string]string{
"Content-Type": "application/json",
},
}
return gwResp, nil
}
func main() {
lambda.Start(Handler)
}
`

const goMod = `
module helloworld
go 1.13
require github.com/aws/aws-lambda-go v1.13.3
`

0 comments on commit 308e9d8

Please sign in to comment.