mweagle / Sparta

go microservices, powered by AWS Lambda
https://gosparta.io
MIT License
717 stars 48 forks source link

Issue with sparta.ServiceDecoratorHook #152

Closed paulbdavis closed 4 years ago

paulbdavis commented 4 years ago

I am trying to run the example for the environment setup and I am running into the following issue

in env/default.go

// +build !dev,!staging,!production

// Package env handles the environment
package env

import (
    "fmt"

    "github.com/aws/aws-sdk-go/aws/session"
    gocf "github.com/crewjam/go-cloudformation"
    sparta "github.com/mweagle/Sparta"
    "github.com/sirupsen/logrus"
)

// Stage is the deployment stage
const Stage = ""

// ServiceDecoratorHook decorates the service
func ServiceDecoratorHook(buildTags string) sparta.ServiceDecoratorHook {
    return func(context map[string]interface{},
        serviceName string,
        template *gocf.Template,
        S3Bucket string,
        S3Key string,
        buildID string,
        awsSession *session.Session,
        noop bool,
        logger *logrus.Logger) error {
        if len(buildTags) <= 0 {
            return fmt.Errorf("Please provide a --tags value for environment target")
        }
        return nil
    }
}

When trying to run with no build tags specified I get a compilation error

env/default.go:20:9: cannot use func literal (type func(map[string]interface {}, string, *"github.com/crewjam/go-cloudformation".Template, string, string, string, *session.Session, bool, *logrus.Logger) error) as type sparta.ServiceDecoratorHook in return argument

I've checked all of the function args and I don't see anything I'm missing.

paulbdavis commented 4 years ago

Basing off the environments example yields a similar error.

package env

import (
    "mytestmodule/env/targets"

    "github.com/aws/aws-sdk-go/aws/session"
    sparta "github.com/mweagle/Sparta"
    gocf "github.com/mweagle/go-cloudformation"
    "github.com/sirupsen/logrus"
)

// ServiceDecoratorHook returns a service decorator hook with the supplied
// tags
func ServiceDecoratorHook() sparta.ServiceDecoratorHookFunc {
    return func(context map[string]interface{},
        serviceName string,
        template *gocf.Template,
        S3Bucket string,
        buildID string,
        awsSession *session.Session,
        noop bool,
        logger *logrus.Logger) error {
        template.Outputs["Environment"] = &gocf.Output{
            Description: "Sparta Config target environment",
            Value:       targets.Stage,
        }
        return nil
    }
}
env/default.go:15:9: cannot use func literal (type func(map[string]interface {}, string, *"github.com/mweagle/go-cloudformation".Template, string, string, *session.Session, bool, *logrus.Logger) error) as type sparta.ServiceDecoratorHookFunc in return argument
mweagle commented 4 years ago

Patched up the example with https://github.com/mweagle/SpartaConfig/commit/0e4f554d2d1e7531de7c065f203f795f23c93abc

paulbdavis commented 4 years ago

Yeah, that fixes the issue. Sorry, I didn't check the code from the example repo as closely.