Skip to content

Commit

Permalink
Applies golint suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciro S. Costa committed Jul 4, 2018
1 parent 76043da commit 1bad58b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
32 changes: 32 additions & 0 deletions commands/transformer/transformer.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Package transformer is an utility package designed to aid
// the process of taking a cast from a given input, applying
// a transformation to it and then outputting the transformed
// cast to somewhere.
package transformer

import (
Expand All @@ -7,16 +11,39 @@ import (
"github.com/pkg/errors"
)

// Transformation describes a generic operation that is meant
// to mutate a single cast at a time.
type Transformation interface {
// Transform performs a mutation (in-place) in a cast.
// note.: no concurrency mechanisms guarantee that this
// is safe to be used across multiple goroutines
Transform(c *cast.Cast) (err error)
}

// Transformer wraps the agents in a tranformation pipeline.
// Once created (see `New`), whenever a transformation is meant
// to be performed (see `Transform`), `Transformer` will read a
// complete cast from `intput`, process it with the trasnformation
// set and then output the resulting cast to `output`.
//
// We can illustrate the whole process like this:
//
// input ==> transformation ==> output
//
// Note.: `input` will be consumed until EOF before the transformation
// is applied.
type Transformer struct {
input *os.File
output *os.File
transformation Transformation
}

// New instantiates a new Transformer instance.
//
// The parameters are:
// - t: a Transformation interface implementor;
// - input: name of a file to read a cast from; and
// - output: name of a file to save the transformed cast to.
func New(t Transformation, input, output string) (m *Transformer, err error) {
if t == nil {
err = errors.Errorf("a transformation must be specified")
Expand Down Expand Up @@ -65,6 +92,10 @@ func New(t Transformation, input, output string) (m *Transformer, err error) {
return
}

// Transform performs the central piece of the cast transformation process:
// 1. decodes a cast from `input`; then
// 2. applies the transformation in the cast that now lives in memory; then
// 3. encodes the cast, saving it to `output`.
func (m *Transformer) Transform() (err error) {
var decodedCast *cast.Cast

Expand Down Expand Up @@ -92,6 +123,7 @@ func (m *Transformer) Transform() (err error) {
return
}

// Close closes any open resources (input and output).
func (m *Transformer) Close() (err error) {
if m.output != nil && m.output != os.Stdout {
m.output.Close()
Expand Down
4 changes: 2 additions & 2 deletions editor/speed.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ func Speed(c *cast.Cast, factor, from, to float64) (err error) {
accumulatedDelta += (newDelta - delta)

deltas[k] = newDelta
k += 1
k++
}

k = 0
for i = fromIdx; i < toIdx; i++ {
c.EventStream[i+1].Time = c.EventStream[i].Time + deltas[k]
k += 1
k++
}

if toIdx+1 < len(c.EventStream) {
Expand Down

0 comments on commit 1bad58b

Please sign in to comment.