Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Providers concept in the codebase. #389

Merged
merged 15 commits into from
Mar 19, 2018
Merged

Introduce Providers concept in the codebase. #389

merged 15 commits into from
Mar 19, 2018

Conversation

mthenw
Copy link
Contributor

@mthenw mthenw commented Mar 16, 2018

Current implementation

Right now there is no concept of providers in the codebase, it's only in configuration API. Calling AWS Lambda or HTTP endpoint is implemented in Function struct (https://github.com/serverless/event-gateway/blob/master/function/function.go) as callAWSLambda or callHTTP private functions. Depending on provider type defined in a function configuration adequate function is called.

Downsides of that approach:

Proposed solution

function package defines Provider interface that provider need to implement

// Provider is an interface for function provider.
type Provider interface {
        // Call function based on provider configuration
	Call(payload []byte) ([]byte, error) 
        // MarshalLogObject is required for uber/zap logger so we can control how configuration is printed in logs (we need this for hiding sensitive information like AWS keys)
	MarshalLogObject(enc zapcore.ObjectEncoder) error
}

function package defines ProviderLoader interface that returns Provider instance configured based on JSON blob (configuration)

// Provider is an interface for function provider.
type ProviderLoader interface {
	Load(config []byte) (Provider, error)
}

function package exposes RegisterProvider function that expects provider type and provider loader. During function create (unmarshaling) adequate loader is fetched and based on JSON config it returns Provider instance which is attached to function instance.

Each provider needs to register itself in init() function.

Thanks to that

  • each provider can be implemented as a separate struct in separate package
  • we can easily inject dependencies to Provider
  • each provider has separate config object that is validated by provider during loading phase

@mthenw mthenw changed the title [WIP] Introduce Providers concept in the codebase. Introduce Providers concept in the codebase. Mar 16, 2018
@mthenw mthenw requested a review from RaeesBhatti March 16, 2018 17:00
@RaeesBhatti
Copy link
Contributor

@mthenw Can you please do linting in separate PR's next time please 😄

@mthenw
Copy link
Contributor Author

mthenw commented Mar 16, 2018

@elsteelbrain yeah, sorry for that, VSCode did that for me. Just ignore README :)

Copy link
Contributor

@RaeesBhatti RaeesBhatti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@mthenw
Copy link
Contributor Author

mthenw commented Mar 19, 2018

I gonna merge this one and setup CodeCov instead of Coveralls. They have weird configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants