From 34af98f6587de808c2b04f54d6ef9f49ef3375b8 Mon Sep 17 00:00:00 2001 From: Arda Karaduman Date: Tue, 26 Sep 2017 19:10:20 +0900 Subject: [PATCH] go fmt --- api/datastore/bolt/bolt.go | 2 +- .../internal/datastoreutil/validator.go | 2 +- api/datastore/mock.go | 2 +- api/datastore/mock_test.go | 2 +- api/datastore/postgres/postgres_test.go | 20 ++++++------ api/datastore/redis/redis.go | 3 +- api/models/new_task.go | 2 +- api/models/route.go | 28 ++++++++--------- api/runner/async_runner.go | 14 ++++----- api/runner/task.go | 2 +- api/runner/task/task.go | 20 ++++++------ api/runner/worker.go | 15 +++++---- api/server/apps_test.go | 2 +- api/server/runner.go | 31 ++++++++++--------- api/server/server.go | 2 +- examples/postgres/func.go | 4 +-- test/fnlb-test-harness/main.go | 23 +++++++------- test/fnlb-test-harness/primes-func/func.go | 5 ++- 18 files changed, 88 insertions(+), 91 deletions(-) diff --git a/api/datastore/bolt/bolt.go b/api/datastore/bolt/bolt.go index 75a42b16..2400593c 100644 --- a/api/datastore/bolt/bolt.go +++ b/api/datastore/bolt/bolt.go @@ -14,8 +14,8 @@ import ( "github.com/Sirupsen/logrus" "github.com/boltdb/bolt" - "github.com/iron-io/functions/api/models" "github.com/iron-io/functions/api/datastore/internal/datastoreutil" + "github.com/iron-io/functions/api/models" ) type BoltDatastore struct { diff --git a/api/datastore/internal/datastoreutil/validator.go b/api/datastore/internal/datastoreutil/validator.go index 28831c41..c8ffaecf 100644 --- a/api/datastore/internal/datastoreutil/validator.go +++ b/api/datastore/internal/datastoreutil/validator.go @@ -164,4 +164,4 @@ func (v *validator) Get(ctx context.Context, key []byte) ([]byte, error) { return nil, models.ErrDatastoreEmptyKey } return v.ds.Get(ctx, key) -} \ No newline at end of file +} diff --git a/api/datastore/mock.go b/api/datastore/mock.go index 99131227..00f949c3 100644 --- a/api/datastore/mock.go +++ b/api/datastore/mock.go @@ -10,7 +10,7 @@ import ( type mock struct { Apps []*models.App Routes []*models.Route - data map[string][]byte + data map[string][]byte } func NewMock() models.Datastore { diff --git a/api/datastore/mock_test.go b/api/datastore/mock_test.go index fc959132..c47d01cf 100644 --- a/api/datastore/mock_test.go +++ b/api/datastore/mock_test.go @@ -8,4 +8,4 @@ import ( func TestDatastore(t *testing.T) { datastoretest.Test(t, NewMock()) -} \ No newline at end of file +} diff --git a/api/datastore/postgres/postgres_test.go b/api/datastore/postgres/postgres_test.go index e2f2bef1..a9ceda6e 100644 --- a/api/datastore/postgres/postgres_test.go +++ b/api/datastore/postgres/postgres_test.go @@ -50,17 +50,17 @@ func preparePostgresTest(logf, fatalf func(string, ...interface{})) (func(), fun } fmt.Println("postgres for test ready") return func() { - db, err := sql.Open("postgres", fmt.Sprintf(tmpPostgres, datastoretest.GetContainerHostIP())) - if err != nil { - fatalf("failed to connect for truncation: %s\n", err) - } - for _, table := range []string{"routes", "apps", "extras"} { - _, err = db.Exec(`TRUNCATE TABLE ` + table) + db, err := sql.Open("postgres", fmt.Sprintf(tmpPostgres, datastoretest.GetContainerHostIP())) if err != nil { - fatalf("failed to truncate table %q: %s\n", table, err) + fatalf("failed to connect for truncation: %s\n", err) } - } - }, + for _, table := range []string{"routes", "apps", "extras"} { + _, err = db.Exec(`TRUNCATE TABLE ` + table) + if err != nil { + fatalf("failed to truncate table %q: %s\n", table, err) + } + } + }, func() { tryRun(logf, "stop postgres container", exec.Command("docker", "rm", "-f", "iron-postgres-test")) } @@ -96,4 +96,4 @@ func mustRun(fatalf func(string, ...interface{}), desc string, cmd *exec.Cmd) { if err := cmd.Run(); err != nil { fatalf("failed to %s: %s", desc, b.String()) } -} \ No newline at end of file +} diff --git a/api/datastore/redis/redis.go b/api/datastore/redis/redis.go index 024cda1b..366c4567 100644 --- a/api/datastore/redis/redis.go +++ b/api/datastore/redis/redis.go @@ -12,8 +12,8 @@ import ( "github.com/Sirupsen/logrus" "github.com/garyburd/redigo/redis" - "github.com/iron-io/functions/api/models" "github.com/iron-io/functions/api/datastore/internal/datastoreutil" + "github.com/iron-io/functions/api/models" ) type RedisDataStore struct { @@ -181,7 +181,6 @@ func (ds *RedisDataStore) UpdateRoute(ctx context.Context, newroute *models.Rout route.Update(newroute) - hset := fmt.Sprintf("routes:%s", route.AppName) return ds.setRoute(hset, route) diff --git a/api/models/new_task.go b/api/models/new_task.go index 248fd11d..fdc1ce69 100644 --- a/api/models/new_task.go +++ b/api/models/new_task.go @@ -57,7 +57,7 @@ type NewTask struct { /* Hot function idle timeout in seconds before termination. - */ + */ IdleTimeout *int32 `json:"idle_timeout,omitempty"` } diff --git a/api/models/route.go b/api/models/route.go index 57faf691..f2478072 100644 --- a/api/models/route.go +++ b/api/models/route.go @@ -11,7 +11,7 @@ import ( ) const ( - defaultRouteTimeout = 30 // seconds + defaultRouteTimeout = 30 // seconds htfnScaleDownTimeout = 30 // seconds ) @@ -40,23 +40,23 @@ type Route struct { Format string `json:"format"` MaxConcurrency int `json:"max_concurrency"` Timeout int32 `json:"timeout"` - IdleTimeout int32 `json:"idle_timeout"` + IdleTimeout int32 `json:"idle_timeout"` Config `json:"config"` } var ( - ErrRoutesValidationFoundDynamicURL = errors.New("Dynamic URL is not allowed") - ErrRoutesValidationInvalidPath = errors.New("Invalid Path format") - ErrRoutesValidationInvalidType = errors.New("Invalid route Type") - ErrRoutesValidationInvalidFormat = errors.New("Invalid route Format") - ErrRoutesValidationMissingAppName = errors.New("Missing route AppName") - ErrRoutesValidationMissingImage = errors.New("Missing route Image") - ErrRoutesValidationMissingName = errors.New("Missing route Name") - ErrRoutesValidationMissingPath = errors.New("Missing route Path") - ErrRoutesValidationMissingType = errors.New("Missing route Type") - ErrRoutesValidationPathMalformed = errors.New("Path malformed") - ErrRoutesValidationNegativeTimeout = errors.New("Negative timeout") - ErrRoutesValidationNegativeIdleTimeout = errors.New("Negative idle timeout") + ErrRoutesValidationFoundDynamicURL = errors.New("Dynamic URL is not allowed") + ErrRoutesValidationInvalidPath = errors.New("Invalid Path format") + ErrRoutesValidationInvalidType = errors.New("Invalid route Type") + ErrRoutesValidationInvalidFormat = errors.New("Invalid route Format") + ErrRoutesValidationMissingAppName = errors.New("Missing route AppName") + ErrRoutesValidationMissingImage = errors.New("Missing route Image") + ErrRoutesValidationMissingName = errors.New("Missing route Name") + ErrRoutesValidationMissingPath = errors.New("Missing route Path") + ErrRoutesValidationMissingType = errors.New("Missing route Type") + ErrRoutesValidationPathMalformed = errors.New("Path malformed") + ErrRoutesValidationNegativeTimeout = errors.New("Negative timeout") + ErrRoutesValidationNegativeIdleTimeout = errors.New("Negative idle timeout") ErrRoutesValidationNegativeMaxConcurrency = errors.New("Negative MaxConcurrency") ) diff --git a/api/runner/async_runner.go b/api/runner/async_runner.go index e52330f6..7c539e29 100644 --- a/api/runner/async_runner.go +++ b/api/runner/async_runner.go @@ -9,8 +9,8 @@ import ( "net" "net/http" "net/url" - "sync" "strings" + "sync" "time" "github.com/Sirupsen/logrus" @@ -52,13 +52,13 @@ func getCfg(t *models.Task) *task.Config { } cfg := &task.Config{ - Image: *t.Image, - Timeout: time.Duration(*t.Timeout) * time.Second, + Image: *t.Image, + Timeout: time.Duration(*t.Timeout) * time.Second, IdleTimeout: time.Duration(*t.IdleTimeout) * time.Second, - ID: t.ID, - AppName: t.AppName, - Stdin: strings.NewReader(t.Payload), - Env: t.EnvVars, + ID: t.ID, + AppName: t.AppName, + Stdin: strings.NewReader(t.Payload), + Env: t.EnvVars, } return cfg } diff --git a/api/runner/task.go b/api/runner/task.go index 51227239..3f03cdbc 100644 --- a/api/runner/task.go +++ b/api/runner/task.go @@ -9,10 +9,10 @@ import ( "path/filepath" "time" - "github.com/moby/moby/cli/config/configfile" docker "github.com/fsouza/go-dockerclient" "github.com/iron-io/functions/api/runner/task" "github.com/iron-io/runner/drivers" + "github.com/moby/moby/cli/config/configfile" ) var registries dockerRegistries diff --git a/api/runner/task/task.go b/api/runner/task/task.go index a7f7d24b..3b3a4543 100644 --- a/api/runner/task/task.go +++ b/api/runner/task/task.go @@ -9,16 +9,16 @@ import ( ) type Config struct { - ID string - Path string - Image string - Timeout time.Duration - IdleTimeout time.Duration - AppName string - Memory uint64 - Env map[string]string - Format string - MaxConcurrency int + ID string + Path string + Image string + Timeout time.Duration + IdleTimeout time.Duration + AppName string + Memory uint64 + Env map[string]string + Format string + MaxConcurrency int Stdin io.Reader Stdout io.Writer diff --git a/api/runner/worker.go b/api/runner/worker.go index 4a97b4e8..249b45ac 100644 --- a/api/runner/worker.go +++ b/api/runner/worker.go @@ -61,7 +61,6 @@ import ( // Terminate // (internal clock) - // RunTask helps sending a task.Request into the common concurrency stream. // Refer to StartWorkers() to understand what this is about. func RunTask(tasks chan task.Request, ctx context.Context, cfg *task.Config) (drivers.RunResult, error) { @@ -262,13 +261,13 @@ func (hc *htfn) serve(ctx context.Context) { var wg sync.WaitGroup cfg := *hc.cfg logger := logrus.WithFields(logrus.Fields{ - "app": cfg.AppName, - "route": cfg.Path, - "image": cfg.Image, - "memory": cfg.Memory, - "format": cfg.Format, - "max_concurrency": cfg.MaxConcurrency, - "idle_timeout": cfg.IdleTimeout, + "app": cfg.AppName, + "route": cfg.Path, + "image": cfg.Image, + "memory": cfg.Memory, + "format": cfg.Format, + "max_concurrency": cfg.MaxConcurrency, + "idle_timeout": cfg.IdleTimeout, }) wg.Add(1) diff --git a/api/server/apps_test.go b/api/server/apps_test.go index 17f8ed16..2f8750ab 100644 --- a/api/server/apps_test.go +++ b/api/server/apps_test.go @@ -99,7 +99,7 @@ func TestAppDelete(t *testing.T) { {datastore.NewMockInit( []*models.App{{ Name: "myapp", - }},nil, + }}, nil, ), "/v1/apps/myapp", "", http.StatusOK, nil}, } { rnr, cancel := testRunner(t) diff --git a/api/server/runner.go b/api/server/runner.go index 818222f5..94132972 100644 --- a/api/server/runner.go +++ b/api/server/runner.go @@ -162,13 +162,14 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun var stdout bytes.Buffer // TODO: should limit the size of this, error if gets too big. akin to: https://golang.org/pkg/io/#LimitReader envVars := map[string]string{ - "METHOD": c.Request.Method, - "ROUTE": found.Path, + "METHOD": c.Request.Method, + "ROUTE": found.Path, "REQUEST_URL": fmt.Sprintf("%v//%v%v", func() string { if c.Request.TLS == nil { return "http" } - return "https"}(), c.Request.Host, c.Request.URL.String()), + return "https" + }(), c.Request.Host, c.Request.URL.String()), } // app config @@ -190,18 +191,18 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun } cfg := &task.Config{ - AppName: appName, - Path: found.Path, - Env: envVars, - Format: found.Format, - ID: reqID, - Image: found.Image, - MaxConcurrency: found.MaxConcurrency, - Memory: found.Memory, - Stdin: payload, - Stdout: &stdout, - Timeout: time.Duration(found.Timeout) * time.Second, - IdleTimeout: time.Duration(found.IdleTimeout) * time.Second, + AppName: appName, + Path: found.Path, + Env: envVars, + Format: found.Format, + ID: reqID, + Image: found.Image, + MaxConcurrency: found.MaxConcurrency, + Memory: found.Memory, + Stdin: payload, + Stdout: &stdout, + Timeout: time.Duration(found.Timeout) * time.Second, + IdleTimeout: time.Duration(found.IdleTimeout) * time.Second, } s.Runner.Enqueue() diff --git a/api/server/server.go b/api/server/server.go index c75280d8..ad7151ed 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -12,7 +12,6 @@ import ( "sync" "github.com/Sirupsen/logrus" - "github.com/ucirello/supervisor" "github.com/gin-gonic/gin" "github.com/iron-io/functions/api" "github.com/iron-io/functions/api/datastore" @@ -23,6 +22,7 @@ import ( "github.com/iron-io/functions/api/server/internal/routecache" "github.com/iron-io/runner/common" "github.com/spf13/viper" + "github.com/ucirello/supervisor" ) const ( diff --git a/examples/postgres/func.go b/examples/postgres/func.go index b95d18a0..641d4d17 100644 --- a/examples/postgres/func.go +++ b/examples/postgres/func.go @@ -29,7 +29,7 @@ func main() { log.Fatal(errors.Wrap(err, "failed to read stdin")) } - db, err := sql.Open("postgres", "postgres://postgres@" + server + "?sslmode=disable") + db, err := sql.Open("postgres", "postgres://postgres@"+server+"?sslmode=disable") if err != nil { log.Println("Failed to connect to postgres server") log.Fatal(err) @@ -96,7 +96,7 @@ func selectCommand(req []byte, db *sql.DB) (string, error) { func insertCommand(req []byte, db *sql.DB) error { q := "INSERT INTO " + table + " SELECT * FROM json_populate_record(null::" + table + ", $1)" _, err := db.Exec(q, req) - if err != nil { + if err != nil { return errors.Wrap(err, "Failed to execute insert query") } return nil diff --git a/test/fnlb-test-harness/main.go b/test/fnlb-test-harness/main.go index 6b02de16..d541ed18 100644 --- a/test/fnlb-test-harness/main.go +++ b/test/fnlb-test-harness/main.go @@ -1,30 +1,30 @@ package main import ( - "fmt" - "net/http" - "io/ioutil" "encoding/json" - "time" "flag" + "fmt" + "io/ioutil" "log" + "net/http" "strings" + "time" ) type execution struct { DurationSeconds float64 - Hostname string - node string - body string + Hostname string + node string + body string responseSeconds float64 } var ( - lbHostPort, nodesStr, route string + lbHostPort, nodesStr, route string numExecutions, maxPrime, numLoops int - nodes []string - nodesByContainerId map[string]string = make(map[string]string) - verbose bool + nodes []string + nodesByContainerId map[string]string = make(map[string]string) + verbose bool ) func init() { @@ -124,4 +124,3 @@ func main() { discoverContainerIds() invokeLoadBalancer(lbHostPort, route, numExecutions, maxPrime, numLoops) } - diff --git a/test/fnlb-test-harness/primes-func/func.go b/test/fnlb-test-harness/primes-func/func.go index eddecb72..8433820b 100644 --- a/test/fnlb-test-harness/primes-func/func.go +++ b/test/fnlb-test-harness/primes-func/func.go @@ -3,8 +3,8 @@ package main import ( "fmt" "os" - "strings" "strconv" + "strings" "time" ) @@ -50,10 +50,9 @@ func main() { for i := 0; i < numLoops; i++ { primes := sieveOfEratosthenes(maxPrime) _ = primes - if i == numLoops - 1 { + if i == numLoops-1 { //fmt.Printf("Highest three primes: %d %d %d\n", primes[len(primes) - 1], primes[len(primes) - 2], primes[len(primes) - 3]) } } fmt.Printf("{\"durationSeconds\": %f, \"hostname\": \"%s\", \"max\": %d, \"loops\": %d}", time.Since(start).Seconds(), os.Getenv("HOSTNAME"), maxPrime, numLoops) } -