From 43caf7e23d3f448a96b16b8999eae578fc6ee36e Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 6 Jul 2015 21:44:13 +0200 Subject: [PATCH] LINT: Documented source code --- config/config.go | 2 ++ storage/s3.go | 9 +++++++-- structs.go | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index 680e2cc..092884c 100644 --- a/config/config.go +++ b/config/config.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/pflag" ) +// Config is a storage struct for configuration parameters type Config struct { Storage string BaseURL string @@ -16,6 +17,7 @@ type Config struct { } } +// Load parses arguments / ENV variable to load configuration func Load() *Config { cfg := &Config{} pflag.StringVar(&cfg.Storage, "storage", "s3", "Storage engine to use") diff --git a/storage/s3.go b/storage/s3.go index 1e8e591..e73c523 100644 --- a/storage/s3.go +++ b/storage/s3.go @@ -10,11 +10,13 @@ import ( "github.com/aws/aws-sdk-go/service/s3" ) +// S3Storage is a storage adapter storing the data into single S3 files type S3Storage struct { s3connection *s3.S3 cfg *config.Config } +// NewS3Storage instanciates a new S3Storage func NewS3Storage(cfg *config.Config) *S3Storage { s3connection := s3.New(&aws.Config{}) return &S3Storage{ @@ -22,6 +24,7 @@ func NewS3Storage(cfg *config.Config) *S3Storage { } } +// Put writes the given data to S3 func (s *S3Storage) Put(dashboardID string, data []byte) error { _, err := s.s3connection.PutObject(&s3.PutObjectInput{ Bucket: aws.String(s.cfg.S3.Bucket), @@ -33,6 +36,7 @@ func (s *S3Storage) Put(dashboardID string, data []byte) error { return err } +// Get loads the data for the given dashboard from S3 func (s *S3Storage) Get(dashboardID string) ([]byte, error) { res, err := s.s3connection.GetObject(&s3.GetObjectInput{ Bucket: aws.String(s.cfg.S3.Bucket), @@ -52,6 +56,7 @@ func (s *S3Storage) Get(dashboardID string) ([]byte, error) { return data, nil } +// Delete deletes the given dashboard from S3 func (s *S3Storage) Delete(dashboardID string) error { _, err := s.s3connection.DeleteObject(&s3.DeleteObjectInput{ Bucket: aws.String(s.cfg.S3.Bucket), @@ -61,6 +66,7 @@ func (s *S3Storage) Delete(dashboardID string) error { return err } +// Exists checks for the existence of the given dashboard func (s *S3Storage) Exists(dashboardID string) (bool, error) { _, err := s.s3connection.HeadObject(&s3.HeadObjectInput{ Bucket: aws.String(s.cfg.S3.Bucket), @@ -73,9 +79,8 @@ func (s *S3Storage) Exists(dashboardID string) (bool, error) { return false, nil } return false, err - } else { - return false, err } + return false, err } return true, nil diff --git a/structs.go b/structs.go index d47814a..353873b 100644 --- a/structs.go +++ b/structs.go @@ -120,7 +120,7 @@ func absoluteDeviation(values []float64) []float64 { deviation := make([]float64, len(values)) - for i, _ := range values { + for i := range values { deviation[i] = absoluteValue(values[i] - medianValue) } @@ -128,7 +128,7 @@ func absoluteDeviation(values []float64) []float64 { } func (dm *dashboardMetric) getValueArray() []float64 { - values := make([]float64, 0) + values := []float64{} for _, v := range dm.HistoricalData { values = append(values, v.Value)