Skip to content

Commit

Permalink
go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
c0ze committed Sep 26, 2017
1 parent 193a7f0 commit 34af98f
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 91 deletions.
2 changes: 1 addition & 1 deletion api/datastore/bolt/bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion api/datastore/internal/datastoreutil/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion api/datastore/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion api/datastore/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ import (

func TestDatastore(t *testing.T) {
datastoretest.Test(t, NewMock())
}
}
20 changes: 10 additions & 10 deletions api/datastore/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand Down Expand Up @@ -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())
}
}
}
3 changes: 1 addition & 2 deletions api/datastore/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion api/models/new_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type NewTask struct {

/* Hot function idle timeout in seconds before termination.
*/
*/
IdleTimeout *int32 `json:"idle_timeout,omitempty"`
}

Expand Down
28 changes: 14 additions & 14 deletions api/models/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
defaultRouteTimeout = 30 // seconds
defaultRouteTimeout = 30 // seconds
htfnScaleDownTimeout = 30 // seconds
)

Expand Down Expand Up @@ -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")
)

Expand Down
14 changes: 7 additions & 7 deletions api/runner/async_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"net"
"net/http"
"net/url"
"sync"
"strings"
"sync"
"time"

"github.com/Sirupsen/logrus"
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion api/runner/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions api/runner/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions api/runner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion api/server/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 16 additions & 15 deletions api/server/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion api/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions examples/postgres/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
23 changes: 11 additions & 12 deletions test/fnlb-test-harness/main.go
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -124,4 +124,3 @@ func main() {
discoverContainerIds()
invokeLoadBalancer(lbHostPort, route, numExecutions, maxPrime, numLoops)
}

5 changes: 2 additions & 3 deletions test/fnlb-test-harness/primes-func/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"fmt"
"os"
"strings"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -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)
}

0 comments on commit 34af98f

Please sign in to comment.