1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-12-22 20:11:18 +00:00

LINT: Documented source code

This commit is contained in:
Knut Ahlers 2015-07-06 21:44:13 +02:00
parent 632ab60018
commit 43caf7e23d
3 changed files with 11 additions and 4 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
// Config is a storage struct for configuration parameters
type Config struct { type Config struct {
Storage string Storage string
BaseURL string BaseURL string
@ -16,6 +17,7 @@ type Config struct {
} }
} }
// Load parses arguments / ENV variable to load configuration
func Load() *Config { func Load() *Config {
cfg := &Config{} cfg := &Config{}
pflag.StringVar(&cfg.Storage, "storage", "s3", "Storage engine to use") pflag.StringVar(&cfg.Storage, "storage", "s3", "Storage engine to use")

View file

@ -10,11 +10,13 @@ import (
"github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3"
) )
// S3Storage is a storage adapter storing the data into single S3 files
type S3Storage struct { type S3Storage struct {
s3connection *s3.S3 s3connection *s3.S3
cfg *config.Config cfg *config.Config
} }
// NewS3Storage instanciates a new S3Storage
func NewS3Storage(cfg *config.Config) *S3Storage { func NewS3Storage(cfg *config.Config) *S3Storage {
s3connection := s3.New(&aws.Config{}) s3connection := s3.New(&aws.Config{})
return &S3Storage{ 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 { func (s *S3Storage) Put(dashboardID string, data []byte) error {
_, err := s.s3connection.PutObject(&s3.PutObjectInput{ _, err := s.s3connection.PutObject(&s3.PutObjectInput{
Bucket: aws.String(s.cfg.S3.Bucket), Bucket: aws.String(s.cfg.S3.Bucket),
@ -33,6 +36,7 @@ func (s *S3Storage) Put(dashboardID string, data []byte) error {
return err return err
} }
// Get loads the data for the given dashboard from S3
func (s *S3Storage) Get(dashboardID string) ([]byte, error) { func (s *S3Storage) Get(dashboardID string) ([]byte, error) {
res, err := s.s3connection.GetObject(&s3.GetObjectInput{ res, err := s.s3connection.GetObject(&s3.GetObjectInput{
Bucket: aws.String(s.cfg.S3.Bucket), Bucket: aws.String(s.cfg.S3.Bucket),
@ -52,6 +56,7 @@ func (s *S3Storage) Get(dashboardID string) ([]byte, error) {
return data, nil return data, nil
} }
// Delete deletes the given dashboard from S3
func (s *S3Storage) Delete(dashboardID string) error { func (s *S3Storage) Delete(dashboardID string) error {
_, err := s.s3connection.DeleteObject(&s3.DeleteObjectInput{ _, err := s.s3connection.DeleteObject(&s3.DeleteObjectInput{
Bucket: aws.String(s.cfg.S3.Bucket), Bucket: aws.String(s.cfg.S3.Bucket),
@ -61,6 +66,7 @@ func (s *S3Storage) Delete(dashboardID string) error {
return err return err
} }
// Exists checks for the existence of the given dashboard
func (s *S3Storage) Exists(dashboardID string) (bool, error) { func (s *S3Storage) Exists(dashboardID string) (bool, error) {
_, err := s.s3connection.HeadObject(&s3.HeadObjectInput{ _, err := s.s3connection.HeadObject(&s3.HeadObjectInput{
Bucket: aws.String(s.cfg.S3.Bucket), Bucket: aws.String(s.cfg.S3.Bucket),
@ -73,9 +79,8 @@ func (s *S3Storage) Exists(dashboardID string) (bool, error) {
return false, nil return false, nil
} }
return false, err return false, err
} else {
return false, err
} }
return false, err
} }
return true, nil return true, nil

View file

@ -120,7 +120,7 @@ func absoluteDeviation(values []float64) []float64 {
deviation := make([]float64, len(values)) deviation := make([]float64, len(values))
for i, _ := range values { for i := range values {
deviation[i] = absoluteValue(values[i] - medianValue) deviation[i] = absoluteValue(values[i] - medianValue)
} }
@ -128,7 +128,7 @@ func absoluteDeviation(values []float64) []float64 {
} }
func (dm *dashboardMetric) getValueArray() []float64 { func (dm *dashboardMetric) getValueArray() []float64 {
values := make([]float64, 0) values := []float64{}
for _, v := range dm.HistoricalData { for _, v := range dm.HistoricalData {
values = append(values, v.Value) values = append(values, v.Value)