Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

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.

@mthenw mthenw merged commit 7be10b0 into master Mar 19, 2018
@mthenw mthenw deleted the providers branch March 19, 2018 11:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants