Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwelin committed Feb 10, 2020
1 parent b485d71 commit 46effb5
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 9 deletions.
56 changes: 49 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,64 @@ import (
"text/template"
)

var (
defaultAppPath = "src/helloworld/app"
allowedAPIProtocols = []string{"rest", "websocket"}
allowedRestAPIEndpoints = []string{"regional", "edge", "private"}
)

type TmplData struct {
ApiProtocol string
ApiEndpoints string
LambdaFunctionName string
ApiProjectName string
}

var allowedAPIProtocols = []string{"rest", "websocket"}
var allowedRestAPIEndpoints = []string{"regional", "edge", "private"}
type LanguageMapper struct {
Files []string
TmplAppVar string
TmplDepsVar string
AppPath string
DepsPath string
}

// Usage to-do
var languages = map[string][]string{
"node": []string{"index.js", "package.json"},
"java": []string{"App.java", "pom.xml"},
"python": []string{"app.py", "requirements.txt"},
"go": []string{"main.go"},
var languages = map[string]LanguageMapper{
"node": LanguageMapper{
Files: []string{"index.js", "package.json"},
TmplAppVar: "nodeFunction",
TmplDepsVar: "packageJson",
AppPath: defaultAppPath,
DepsPath: defaultAppPath,
},
"java": LanguageMapper{
Files: []string{"App.java", "pom.xml"},
TmplAppVar: "",
TmplDepsVar: "",
AppPath: defaultAppPath + "/com/api",
DepsPath: defaultAppPath,
},
"python": LanguageMapper{
Files: []string{"app.py", "requirements.txt"},
TmplAppVar: "",
TmplDepsVar: "",
AppPath: defaultAppPath,
DepsPath: defaultAppPath,
},
"ruby": LanguageMapper{
Files: []string{"app.rb", "Gemfile"},
TmplAppVar: "",
TmplDepsVar: "",
AppPath: defaultAppPath,
DepsPath: defaultAppPath,
},
"go": LanguageMapper{
Files: []string{"main.go", "go.mod"},
TmplAppVar: "",
TmplDepsVar: "",
AppPath: defaultAppPath,
DepsPath: defaultAppPath,
},
}

func createDir(path string) error {
Expand Down
20 changes: 18 additions & 2 deletions tmpl-nodejs.go → tmpl-languages.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

var nodeFunction = `
// node.js

const nodeFunction = `
'use strict'
const winston = require('winston')
Expand All @@ -26,7 +28,7 @@ exports.handler = function(event, context) {
};
`

var packageJson = `
const packageJson = `
{
"name": "hello",
"version": "1.0.0",
Expand All @@ -46,3 +48,17 @@ var packageJson = `
}
}
`

// python
const pythonFunction = `
import json
def lambda_handler(event, context):
dict = { "msg" : "hello world" }
return {
'statusCode': 200,
'body': json.dumps(dict)
}
`

0 comments on commit 46effb5

Please sign in to comment.