Skip to content

Instantly share code, notes, and snippets.

type helloWorldResponse struct {
Message string
Request spartaAPIG.APIGatewayRequest
}
////////////////////////////////////////////////////////////////////////////////
// Hello world event handler
func helloWorld(ctx context.Context,
gatewayEvent spartaAPIG.APIGatewayRequest) (helloWorldResponse, error) {
// AWS Lambda go style
func helloWorld() string {
return “Hello World”
}
lambdaFn := sparta.HandleAWSLambda(“Hello World”,
helloWorld,
sparta.IAMRoleDefinition{})
// AWS Lambda Go style
func helloWorld() (string, error) {
return "Hello World", nil
}
Simple Sparta application that demonstrates core functionality
Usage:
main [command]
Available Commands:
delete Delete service
describe Describe service
execute Execute
help Help about any command
@mweagle
mweagle / oldmodel.go
Created January 22, 2018 02:13
sparta_old_model
// filename: cmd/main.go
package main
import (
“io”
“net/http”
“os”
sparta “github.com/mweagle/Sparta”
)
// http.HandlerFunc style
func helloWorld(w http.ResponseWriter, r *http.Request) {
loggerVal, loggerValOk := r.Context().Value(sparta.ContextKeyLogger).(*logrus.Logger)
func helloSpartaWorld(w http.ResponseWriter, r *http.Request) {
...
}
// Standard http.HandlerFunc() that will be run as a lambda function
func helloSpartaWorld(w http.ResponseWriter, r *http.Request) {
messageText := os.Getenv("MESSAGE")
if "" == messageText {
messageText = "$MESSAGE not defined"
}
fmt.Fprint(w, messageText)
}
func init() {
sparta.RegisterCodePipelineEnvironment("test", map[string]string{
"MESSAGE": "Hello Test!",
})
sparta.RegisterCodePipelineEnvironment("production", map[string]string{
"MESSAGE": "Hello Production!",
})
}