Skip to content

Commit

Permalink
Make anything that doesn't need to be exported private (closes #111)
Browse files Browse the repository at this point in the history
  • Loading branch information
TiganeteaRobert committed Jun 10, 2022
1 parent 2c97c6f commit 50107e2
Show file tree
Hide file tree
Showing 26 changed files with 237 additions and 237 deletions.
32 changes: 16 additions & 16 deletions config/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,47 @@

package config

// ComponentConfigurable is the interface that wraps the ProvideDefault method.
type ComponentConfigurable interface {
// componentConfigurable is the interface that wraps the ProvideDefault method.
type componentConfigurable interface {
// ProvideDefault returns a pointer to a structure that will be
// written with the decoded configuration.
ProvideDefault() (interface{}, error)
}

// ComponentCreator is the interface that wraps the Create method.
type ComponentCreator interface {
// componentCreator is the interface that wraps the Create method.
type componentCreator interface {
// Create returns a pointer to an output structure given a pointer
// to an input structure. This interface is expected to be implemented
// by components that are creatable through a configuration.
Create(i interface{}) (interface{}, error)
}

// Pluggable is the interface that groups
// ComponentConfigurable and ComponentCreator.
// componentConfigurable and componentCreator.
type Pluggable interface {
ComponentConfigurable
ComponentCreator
componentConfigurable
componentCreator
}

// DecodingHandler is the type of any function that, given a ComponentConfigurable
// and a Decoder, returns a pointer to a structure that was decoded.
type DecodingHandler func(c ComponentConfigurable, d Decoder) (interface{}, error)
// decodingHandler is the type of any function that, given a componentConfigurable
// and a decoder, returns a pointer to a structure that was decoded.
type decodingHandler func(c componentConfigurable, d decoder) (interface{}, error)

// WithDecoderOptions returns a DecodingHandler closed over some DecoderOptions.
func WithDecoderOptions(opts *DecoderOptions) DecodingHandler {
return func(c ComponentConfigurable, d Decoder) (interface{}, error) {
return Configure(c, d, opts)
// withDecoderOptions returns a decodingHandler closed over some DecoderOptions.
func withDecoderOptions(opts *DecoderOptions) decodingHandler {
return func(c componentConfigurable, d decoder) (interface{}, error) {
return configure(c, d, opts)
}
}

// Configure returns the decoded target.
func Configure(c ComponentConfigurable, d Decoder, opts *DecoderOptions) (interface{}, error) {
func configure(c componentConfigurable, d decoder, opts *DecoderOptions) (interface{}, error) {
target, err := c.ProvideDefault() // target is ptr
if err != nil {
return nil, err
}

if err = d.Decode(opts, target); err != nil {
if err = d.decode(opts, target); err != nil {
return nil, err
}

Expand Down
80 changes: 40 additions & 40 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,71 +30,71 @@ import (

// Config holds the configuration data along with the decoder to decode them
type Config struct {
Data *ConfigurationData
Decoder Decoder
Data *configurationData
Decoder decoder
}

// ConfigurationData for holding all configuration options
type ConfigurationData struct {
Source *Component `hcl:"source,block" envPrefix:"SOURCE_"`
Target *Component `hcl:"target,block" envPrefix:"TARGET_"`
FailureTarget *FailureConfig `hcl:"failure_target,block"`
Sentry *SentryConfig `hcl:"sentry,block"`
StatsReceiver *StatsConfig `hcl:"stats_receiver,block"`
// configurationData for holding all configuration options
type configurationData struct {
Source *component `hcl:"source,block" envPrefix:"SOURCE_"`
Target *component `hcl:"target,block" envPrefix:"TARGET_"`
FailureTarget *failureConfig `hcl:"failure_target,block"`
Sentry *sentryConfig `hcl:"sentry,block"`
StatsReceiver *statsConfig `hcl:"stats_receiver,block"`
Transformation string `hcl:"message_transformation,optional" env:"MESSAGE_TRANSFORMATION"`
LogLevel string `hcl:"log_level,optional" env:"LOG_LEVEL"`
GoogleServiceAccountB64 string `hcl:"google_application_credentials_b64,optional" env:"GOOGLE_APPLICATION_CREDENTIALS_B64"`
UserProvidedID string `hcl:"user_provided_id,optional" env:"USER_PROVIDED_ID"`
}

// Component is a type to abstract over configuration blocks.
type Component struct {
Use *Use `hcl:"use,block"`
// component is a type to abstract over configuration blocks.
type component struct {
Use *use `hcl:"use,block"`
}

// Use is a type to denote what a component will be configured to use.
type Use struct {
// use is a type to denote what a component will be configured to use.
type use struct {
Name string `hcl:",label" env:"NAME"`
Body hcl.Body `hcl:",remain"`
}

// FailureConfig holds configuration for the failure target.
// failureConfig holds configuration for the failure target.
// It includes the target component to use.
type FailureConfig struct {
Target *Use `hcl:"use,block" envPrefix:"FAILURE_TARGET_"`
type failureConfig struct {
Target *use `hcl:"use,block" envPrefix:"FAILURE_TARGET_"`
Format string `hcl:"format,optional" env:"FAILURE_TARGETS_FORMAT"`
}

// SentryConfig configures the Sentry error tracker.
type SentryConfig struct {
// sentryConfig configures the Sentry error tracker.
type sentryConfig struct {
Dsn string `hcl:"dsn" env:"SENTRY_DSN"`
Tags string `hcl:"tags,optional" env:"SENTRY_TAGS"`
Debug bool `hcl:"debug,optional" env:"SENTRY_DEBUG"`
}

// StatsConfig holds configuration for stats receivers.
// statsConfig holds configuration for stats receivers.
// It includes a receiver component to use.
type StatsConfig struct {
Receiver *Use `hcl:"use,block" envPrefix:"STATS_RECEIVER_"`
type statsConfig struct {
Receiver *use `hcl:"use,block" envPrefix:"STATS_RECEIVER_"`
TimeoutSec int `hcl:"timeout_sec,optional" env:"STATS_RECEIVER_TIMEOUT_SEC"`
BufferSec int `hcl:"buffer_sec,optional" env:"STATS_RECEIVER_BUFFER_SEC"`
}

// defaultConfigData returns the initial main configuration target.
func defaultConfigData() *ConfigurationData {
return &ConfigurationData{
Source: &Component{&Use{Name: "stdin"}},
Target: &Component{&Use{Name: "stdout"}},
func defaultConfigData() *configurationData {
return &configurationData{
Source: &component{&use{Name: "stdin"}},
Target: &component{&use{Name: "stdout"}},

FailureTarget: &FailureConfig{
Target: &Use{Name: "stdout"},
FailureTarget: &failureConfig{
Target: &use{Name: "stdout"},
Format: "snowplow",
},
Sentry: &SentryConfig{
Sentry: &sentryConfig{
Tags: "{}",
},
StatsReceiver: &StatsConfig{
Receiver: &Use{},
StatsReceiver: &statsConfig{
Receiver: &use{},
TimeoutSec: 1,
BufferSec: 15,
},
Expand Down Expand Up @@ -122,11 +122,11 @@ func newEnvConfig() (*Config, error) {
var err error

decoderOpts := &DecoderOptions{}
envDecoder := &EnvDecoder{}
envDecoder := &envDecoder{}

configData := defaultConfigData()

err = envDecoder.Decode(decoderOpts, configData)
err = envDecoder.decode(decoderOpts, configData)
if err != nil {
return nil, err
}
Expand All @@ -153,14 +153,14 @@ func newHclConfig(filename string) (*Config, error) {
}

// Creating EvalContext
evalContext := CreateHclContext() // ptr
evalContext := createHclContext() // ptr

// Decoding
configData := defaultConfigData()
decoderOpts := &DecoderOptions{Input: fileHCL.Body}
hclDecoder := &HclDecoder{EvalContext: evalContext}
hclDecoder := &hclDecoder{EvalContext: evalContext}

err = hclDecoder.Decode(decoderOpts, configData)
err = hclDecoder.decode(decoderOpts, configData)
if err != nil {
return nil, err
}
Expand All @@ -175,7 +175,7 @@ func newHclConfig(filename string) (*Config, error) {

// CreateComponent creates a pluggable component given the decoder options.
func (c *Config) CreateComponent(p Pluggable, opts *DecoderOptions) (interface{}, error) {
componentConfigure := WithDecoderOptions(opts)
componentConfigure := withDecoderOptions(opts)

decodedConfig, err := componentConfigure(p, c.Decoder)
if err != nil {
Expand Down Expand Up @@ -363,15 +363,15 @@ func (c *Config) GetTags() (map[string]string, error) {
// GetObserver builds and returns the observer with the embedded
// optional stats receiver
func (c *Config) GetObserver(tags map[string]string) (*observer.Observer, error) {
sr, err := c.GetStatsReceiver(tags)
sr, err := c.getStatsReceiver(tags)
if err != nil {
return nil, err
}
return observer.New(sr, time.Duration(c.Data.StatsReceiver.TimeoutSec)*time.Second, time.Duration(c.Data.StatsReceiver.BufferSec)*time.Second), nil
}

// GetStatsReceiver builds and returns the stats receiver
func (c *Config) GetStatsReceiver(tags map[string]string) (statsreceiveriface.StatsReceiver, error) {
// getStatsReceiver builds and returns the stats receiver
func (c *Config) getStatsReceiver(tags map[string]string) (statsreceiveriface.StatsReceiver, error) {
useReceiver := c.Data.StatsReceiver.Receiver
decoderOpts := &DecoderOptions{
Input: useReceiver.Body,
Expand Down
34 changes: 17 additions & 17 deletions config/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import (
"github.com/zclconf/go-cty/cty/function"
)

// Decoder is the interface that wraps the Decode method.
type Decoder interface {
// decoder is the interface that wraps the Decode method.
type decoder interface {
// Decode decodes onto target given DecoderOptions.
// The target argument must be a pointer to an allocated structure.
Decode(opts *DecoderOptions, target interface{}) error
decode(opts *DecoderOptions, target interface{}) error
}

// DecoderOptions represent the options for a Decoder.
// DecoderOptions represent the options for a decoder.
// The purpose of this type is to unify the input to the different available
// Decoders. The zero value of DecoderOptions means no-prefix/nil-input,
// which should be usable by the Decoders.
Expand All @@ -33,15 +33,15 @@ type DecoderOptions struct {
Input hcl.Body
}

// EnvDecoder implements Decoder.
type EnvDecoder struct{}
// envDecoder implements decoder.
type envDecoder struct{}

// Decode populates target from the environment.
// The target argument must be a pointer to a struct type value.
func (e *EnvDecoder) Decode(opts *DecoderOptions, target interface{}) error {
// Decoder Options cannot be missing
func (e *envDecoder) decode(opts *DecoderOptions, target interface{}) error {
// decoder Options cannot be missing
if opts == nil {
return errors.New("missing DecoderOptions for EnvDecoder")
return errors.New("missing DecoderOptions for envDecoder")
}

// If target is nil then we assume that target is not decodable.
Expand All @@ -56,19 +56,19 @@ func (e *EnvDecoder) Decode(opts *DecoderOptions, target interface{}) error {
return env.Parse(target, envOpts)
}

// HclDecoder implements Decoder.
type HclDecoder struct {
// hclDecoder implements decoder.
type hclDecoder struct {
EvalContext *hcl.EvalContext
}

// Decode populates target given HCL input through DecoderOptions.
// The target argument must be a pointer to an allocated structure.
// If the HCL input is nil, we assume there is nothing to do and the target
// stays unaffected. If the target is nil, we assume is not decodable.
func (h *HclDecoder) Decode(opts *DecoderOptions, target interface{}) error {
// Decoder Options cannot be missing
func (h *hclDecoder) decode(opts *DecoderOptions, target interface{}) error {
// decoder Options cannot be missing
if opts == nil {
return errors.New("missing DecoderOptions for HclDecoder")
return errors.New("missing DecoderOptions for hclDecoder")
}

src := opts.Input
Expand All @@ -81,7 +81,7 @@ func (h *HclDecoder) Decode(opts *DecoderOptions, target interface{}) error {
return nil
}

// Decode
// decode
diag := gohcl.DecodeBody(src, h.EvalContext, target)
if len(diag) > 0 {
return diag
Expand All @@ -90,12 +90,12 @@ func (h *HclDecoder) Decode(opts *DecoderOptions, target interface{}) error {
return nil
}

// CreateHclContext creates an *hcl.EvalContext that is used in decoding HCL.
// createHclContext creates an *hcl.EvalContext that is used in decoding HCL.
// Here we can add the evaluation features available for the HCL configuration
// users.
// For now, below is an example of 2 different ways users can reference
// environment variables in their HCL configuration file.
func CreateHclContext() *hcl.EvalContext {
func createHclContext() *hcl.EvalContext {
evalCtx := &hcl.EvalContext{
Functions: hclCtxFunctions(),
Variables: hclCtxVariables(),
Expand Down
14 changes: 7 additions & 7 deletions config/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type testStruct struct {
}

func TestEnvDecode(t *testing.T) {
envDecoder := EnvDecoder{}
envDecoder := envDecoder{}

testCases := []struct {
TestName string
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestEnvDecode(t *testing.T) {
t.Setenv("TEST_STRING", "ateststring")
t.Setenv("PREFIX_TEST_STRING", "ateststringprefixed")

err := envDecoder.Decode(tt.DecoderOpts, tt.Target)
err := envDecoder.decode(tt.DecoderOpts, tt.Target)
assert.Nil(err)

if !reflect.DeepEqual(tt.Target, tt.Expected) {
Expand All @@ -76,7 +76,7 @@ func TestEnvDecode(t *testing.T) {

func TestHclDecode(t *testing.T) {
evalCtx := &hcl.EvalContext{}
hclDecoder := HclDecoder{evalCtx}
hclDecoder := hclDecoder{evalCtx}
hclSrc := `
test_string = "ateststring"
`
Expand Down Expand Up @@ -124,7 +124,7 @@ test_string = "ateststring"
for _, tt := range testCases {
t.Run(tt.TestName, func(t *testing.T) {
assert := assert.New(t)
err := hclDecoder.Decode(tt.DecoderOpts, tt.Target)
err := hclDecoder.decode(tt.DecoderOpts, tt.Target)
if err != nil {
t.Errorf("decoding failed")
}
Expand All @@ -147,8 +147,8 @@ func TestCreateHclContext(t *testing.T) {
TestInt int `hcl:"test_int"`
}

evalCtx := CreateHclContext()
hclDecoder := HclDecoder{evalCtx}
evalCtx := createHclContext()
hclDecoder := hclDecoder{evalCtx}
hclSrc := `
test_string = env.TEST_STRING
test_int = env("TEST_INT")
Expand Down Expand Up @@ -183,7 +183,7 @@ test_int = env("TEST_INT")
t.Run(tt.TestName, func(t *testing.T) {
assert := assert.New(t)

err := hclDecoder.Decode(tt.DecoderOpts, tt.Target)
err := hclDecoder.decode(tt.DecoderOpts, tt.Target)
if err != nil {
t.Errorf(err.Error())
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/models/filter_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ type FilterResult struct {
AvgFilterLatency time.Duration
}

// NewFilterResult uses the current time as the timeOfFilter and calls NewFilterResultWithTime
// NewFilterResult uses the current time as the timeOfFilter and calls newFilterResultWithTime
func NewFilterResult(filtered []*Message) *FilterResult {
return NewFilterResultWithTime(filtered, time.Now().UTC())
return newFilterResultWithTime(filtered, time.Now().UTC())
}

// NewFilterResultWithTime builds a result structure to return from a filtered message slice
// newFilterResultWithTime builds a result structure to return from a filtered message slice
// attempt which contains the filtered message count as well as several
// derived latency measures.
func NewFilterResultWithTime(filtered []*Message, timeOfFilter time.Time) *FilterResult {
func newFilterResultWithTime(filtered []*Message, timeOfFilter time.Time) *FilterResult {
r := FilterResult{
FilteredCount: int64(len(filtered)),
}
Expand Down
Loading

0 comments on commit 50107e2

Please sign in to comment.