Skip to content

Commit 34af98f

Browse files
committed
go fmt
1 parent 193a7f0 commit 34af98f

File tree

18 files changed

+88
-91
lines changed

18 files changed

+88
-91
lines changed

api/datastore/bolt/bolt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414

1515
"github.com/Sirupsen/logrus"
1616
"github.com/boltdb/bolt"
17-
"github.com/iron-io/functions/api/models"
1817
"github.com/iron-io/functions/api/datastore/internal/datastoreutil"
18+
"github.com/iron-io/functions/api/models"
1919
)
2020

2121
type BoltDatastore struct {

api/datastore/internal/datastoreutil/validator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,4 @@ func (v *validator) Get(ctx context.Context, key []byte) ([]byte, error) {
164164
return nil, models.ErrDatastoreEmptyKey
165165
}
166166
return v.ds.Get(ctx, key)
167-
}
167+
}

api/datastore/mock.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
type mock struct {
1111
Apps []*models.App
1212
Routes []*models.Route
13-
data map[string][]byte
13+
data map[string][]byte
1414
}
1515

1616
func NewMock() models.Datastore {

api/datastore/mock_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ import (
88

99
func TestDatastore(t *testing.T) {
1010
datastoretest.Test(t, NewMock())
11-
}
11+
}

api/datastore/postgres/postgres_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ func preparePostgresTest(logf, fatalf func(string, ...interface{})) (func(), fun
5050
}
5151
fmt.Println("postgres for test ready")
5252
return func() {
53-
db, err := sql.Open("postgres", fmt.Sprintf(tmpPostgres, datastoretest.GetContainerHostIP()))
54-
if err != nil {
55-
fatalf("failed to connect for truncation: %s\n", err)
56-
}
57-
for _, table := range []string{"routes", "apps", "extras"} {
58-
_, err = db.Exec(`TRUNCATE TABLE ` + table)
53+
db, err := sql.Open("postgres", fmt.Sprintf(tmpPostgres, datastoretest.GetContainerHostIP()))
5954
if err != nil {
60-
fatalf("failed to truncate table %q: %s\n", table, err)
55+
fatalf("failed to connect for truncation: %s\n", err)
6156
}
62-
}
63-
},
57+
for _, table := range []string{"routes", "apps", "extras"} {
58+
_, err = db.Exec(`TRUNCATE TABLE ` + table)
59+
if err != nil {
60+
fatalf("failed to truncate table %q: %s\n", table, err)
61+
}
62+
}
63+
},
6464
func() {
6565
tryRun(logf, "stop postgres container", exec.Command("docker", "rm", "-f", "iron-postgres-test"))
6666
}
@@ -96,4 +96,4 @@ func mustRun(fatalf func(string, ...interface{}), desc string, cmd *exec.Cmd) {
9696
if err := cmd.Run(); err != nil {
9797
fatalf("failed to %s: %s", desc, b.String())
9898
}
99-
}
99+
}

api/datastore/redis/redis.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212

1313
"github.com/Sirupsen/logrus"
1414
"github.com/garyburd/redigo/redis"
15-
"github.com/iron-io/functions/api/models"
1615
"github.com/iron-io/functions/api/datastore/internal/datastoreutil"
16+
"github.com/iron-io/functions/api/models"
1717
)
1818

1919
type RedisDataStore struct {
@@ -181,7 +181,6 @@ func (ds *RedisDataStore) UpdateRoute(ctx context.Context, newroute *models.Rout
181181

182182
route.Update(newroute)
183183

184-
185184
hset := fmt.Sprintf("routes:%s", route.AppName)
186185

187186
return ds.setRoute(hset, route)

api/models/new_task.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type NewTask struct {
5757

5858
/* Hot function idle timeout in seconds before termination.
5959
60-
*/
60+
*/
6161
IdleTimeout *int32 `json:"idle_timeout,omitempty"`
6262
}
6363

api/models/route.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
const (
14-
defaultRouteTimeout = 30 // seconds
14+
defaultRouteTimeout = 30 // seconds
1515
htfnScaleDownTimeout = 30 // seconds
1616
)
1717

@@ -40,23 +40,23 @@ type Route struct {
4040
Format string `json:"format"`
4141
MaxConcurrency int `json:"max_concurrency"`
4242
Timeout int32 `json:"timeout"`
43-
IdleTimeout int32 `json:"idle_timeout"`
43+
IdleTimeout int32 `json:"idle_timeout"`
4444
Config `json:"config"`
4545
}
4646

4747
var (
48-
ErrRoutesValidationFoundDynamicURL = errors.New("Dynamic URL is not allowed")
49-
ErrRoutesValidationInvalidPath = errors.New("Invalid Path format")
50-
ErrRoutesValidationInvalidType = errors.New("Invalid route Type")
51-
ErrRoutesValidationInvalidFormat = errors.New("Invalid route Format")
52-
ErrRoutesValidationMissingAppName = errors.New("Missing route AppName")
53-
ErrRoutesValidationMissingImage = errors.New("Missing route Image")
54-
ErrRoutesValidationMissingName = errors.New("Missing route Name")
55-
ErrRoutesValidationMissingPath = errors.New("Missing route Path")
56-
ErrRoutesValidationMissingType = errors.New("Missing route Type")
57-
ErrRoutesValidationPathMalformed = errors.New("Path malformed")
58-
ErrRoutesValidationNegativeTimeout = errors.New("Negative timeout")
59-
ErrRoutesValidationNegativeIdleTimeout = errors.New("Negative idle timeout")
48+
ErrRoutesValidationFoundDynamicURL = errors.New("Dynamic URL is not allowed")
49+
ErrRoutesValidationInvalidPath = errors.New("Invalid Path format")
50+
ErrRoutesValidationInvalidType = errors.New("Invalid route Type")
51+
ErrRoutesValidationInvalidFormat = errors.New("Invalid route Format")
52+
ErrRoutesValidationMissingAppName = errors.New("Missing route AppName")
53+
ErrRoutesValidationMissingImage = errors.New("Missing route Image")
54+
ErrRoutesValidationMissingName = errors.New("Missing route Name")
55+
ErrRoutesValidationMissingPath = errors.New("Missing route Path")
56+
ErrRoutesValidationMissingType = errors.New("Missing route Type")
57+
ErrRoutesValidationPathMalformed = errors.New("Path malformed")
58+
ErrRoutesValidationNegativeTimeout = errors.New("Negative timeout")
59+
ErrRoutesValidationNegativeIdleTimeout = errors.New("Negative idle timeout")
6060
ErrRoutesValidationNegativeMaxConcurrency = errors.New("Negative MaxConcurrency")
6161
)
6262

api/runner/async_runner.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"net"
1010
"net/http"
1111
"net/url"
12-
"sync"
1312
"strings"
13+
"sync"
1414
"time"
1515

1616
"github.com/Sirupsen/logrus"
@@ -52,13 +52,13 @@ func getCfg(t *models.Task) *task.Config {
5252
}
5353

5454
cfg := &task.Config{
55-
Image: *t.Image,
56-
Timeout: time.Duration(*t.Timeout) * time.Second,
55+
Image: *t.Image,
56+
Timeout: time.Duration(*t.Timeout) * time.Second,
5757
IdleTimeout: time.Duration(*t.IdleTimeout) * time.Second,
58-
ID: t.ID,
59-
AppName: t.AppName,
60-
Stdin: strings.NewReader(t.Payload),
61-
Env: t.EnvVars,
58+
ID: t.ID,
59+
AppName: t.AppName,
60+
Stdin: strings.NewReader(t.Payload),
61+
Env: t.EnvVars,
6262
}
6363
return cfg
6464
}

api/runner/task.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
"path/filepath"
1010
"time"
1111

12-
"github.com/moby/moby/cli/config/configfile"
1312
docker "github.com/fsouza/go-dockerclient"
1413
"github.com/iron-io/functions/api/runner/task"
1514
"github.com/iron-io/runner/drivers"
15+
"github.com/moby/moby/cli/config/configfile"
1616
)
1717

1818
var registries dockerRegistries

api/runner/task/task.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import (
99
)
1010

1111
type Config struct {
12-
ID string
13-
Path string
14-
Image string
15-
Timeout time.Duration
16-
IdleTimeout time.Duration
17-
AppName string
18-
Memory uint64
19-
Env map[string]string
20-
Format string
21-
MaxConcurrency int
12+
ID string
13+
Path string
14+
Image string
15+
Timeout time.Duration
16+
IdleTimeout time.Duration
17+
AppName string
18+
Memory uint64
19+
Env map[string]string
20+
Format string
21+
MaxConcurrency int
2222

2323
Stdin io.Reader
2424
Stdout io.Writer

api/runner/worker.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import (
6161
// Terminate
6262
// (internal clock)
6363

64-
6564
// RunTask helps sending a task.Request into the common concurrency stream.
6665
// Refer to StartWorkers() to understand what this is about.
6766
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) {
262261
var wg sync.WaitGroup
263262
cfg := *hc.cfg
264263
logger := logrus.WithFields(logrus.Fields{
265-
"app": cfg.AppName,
266-
"route": cfg.Path,
267-
"image": cfg.Image,
268-
"memory": cfg.Memory,
269-
"format": cfg.Format,
270-
"max_concurrency": cfg.MaxConcurrency,
271-
"idle_timeout": cfg.IdleTimeout,
264+
"app": cfg.AppName,
265+
"route": cfg.Path,
266+
"image": cfg.Image,
267+
"memory": cfg.Memory,
268+
"format": cfg.Format,
269+
"max_concurrency": cfg.MaxConcurrency,
270+
"idle_timeout": cfg.IdleTimeout,
272271
})
273272

274273
wg.Add(1)

api/server/apps_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestAppDelete(t *testing.T) {
9999
{datastore.NewMockInit(
100100
[]*models.App{{
101101
Name: "myapp",
102-
}},nil,
102+
}}, nil,
103103
), "/v1/apps/myapp", "", http.StatusOK, nil},
104104
} {
105105
rnr, cancel := testRunner(t)

api/server/runner.go

+16-15
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,14 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
162162
var stdout bytes.Buffer // TODO: should limit the size of this, error if gets too big. akin to: https://golang.org/pkg/io/#LimitReader
163163

164164
envVars := map[string]string{
165-
"METHOD": c.Request.Method,
166-
"ROUTE": found.Path,
165+
"METHOD": c.Request.Method,
166+
"ROUTE": found.Path,
167167
"REQUEST_URL": fmt.Sprintf("%v//%v%v", func() string {
168168
if c.Request.TLS == nil {
169169
return "http"
170170
}
171-
return "https"}(), c.Request.Host, c.Request.URL.String()),
171+
return "https"
172+
}(), c.Request.Host, c.Request.URL.String()),
172173
}
173174

174175
// app config
@@ -190,18 +191,18 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
190191
}
191192

192193
cfg := &task.Config{
193-
AppName: appName,
194-
Path: found.Path,
195-
Env: envVars,
196-
Format: found.Format,
197-
ID: reqID,
198-
Image: found.Image,
199-
MaxConcurrency: found.MaxConcurrency,
200-
Memory: found.Memory,
201-
Stdin: payload,
202-
Stdout: &stdout,
203-
Timeout: time.Duration(found.Timeout) * time.Second,
204-
IdleTimeout: time.Duration(found.IdleTimeout) * time.Second,
194+
AppName: appName,
195+
Path: found.Path,
196+
Env: envVars,
197+
Format: found.Format,
198+
ID: reqID,
199+
Image: found.Image,
200+
MaxConcurrency: found.MaxConcurrency,
201+
Memory: found.Memory,
202+
Stdin: payload,
203+
Stdout: &stdout,
204+
Timeout: time.Duration(found.Timeout) * time.Second,
205+
IdleTimeout: time.Duration(found.IdleTimeout) * time.Second,
205206
}
206207

207208
s.Runner.Enqueue()

api/server/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"sync"
1313

1414
"github.com/Sirupsen/logrus"
15-
"github.com/ucirello/supervisor"
1615
"github.com/gin-gonic/gin"
1716
"github.com/iron-io/functions/api"
1817
"github.com/iron-io/functions/api/datastore"
@@ -23,6 +22,7 @@ import (
2322
"github.com/iron-io/functions/api/server/internal/routecache"
2423
"github.com/iron-io/runner/common"
2524
"github.com/spf13/viper"
25+
"github.com/ucirello/supervisor"
2626
)
2727

2828
const (

examples/postgres/func.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func main() {
2929
log.Fatal(errors.Wrap(err, "failed to read stdin"))
3030
}
3131

32-
db, err := sql.Open("postgres", "postgres://postgres@" + server + "?sslmode=disable")
32+
db, err := sql.Open("postgres", "postgres://postgres@"+server+"?sslmode=disable")
3333
if err != nil {
3434
log.Println("Failed to connect to postgres server")
3535
log.Fatal(err)
@@ -96,7 +96,7 @@ func selectCommand(req []byte, db *sql.DB) (string, error) {
9696
func insertCommand(req []byte, db *sql.DB) error {
9797
q := "INSERT INTO " + table + " SELECT * FROM json_populate_record(null::" + table + ", $1)"
9898
_, err := db.Exec(q, req)
99-
if err != nil {
99+
if err != nil {
100100
return errors.Wrap(err, "Failed to execute insert query")
101101
}
102102
return nil

test/fnlb-test-harness/main.go

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
package main
22

33
import (
4-
"fmt"
5-
"net/http"
6-
"io/ioutil"
74
"encoding/json"
8-
"time"
95
"flag"
6+
"fmt"
7+
"io/ioutil"
108
"log"
9+
"net/http"
1110
"strings"
11+
"time"
1212
)
1313

1414
type execution struct {
1515
DurationSeconds float64
16-
Hostname string
17-
node string
18-
body string
16+
Hostname string
17+
node string
18+
body string
1919
responseSeconds float64
2020
}
2121

2222
var (
23-
lbHostPort, nodesStr, route string
23+
lbHostPort, nodesStr, route string
2424
numExecutions, maxPrime, numLoops int
25-
nodes []string
26-
nodesByContainerId map[string]string = make(map[string]string)
27-
verbose bool
25+
nodes []string
26+
nodesByContainerId map[string]string = make(map[string]string)
27+
verbose bool
2828
)
2929

3030
func init() {
@@ -124,4 +124,3 @@ func main() {
124124
discoverContainerIds()
125125
invokeLoadBalancer(lbHostPort, route, numExecutions, maxPrime, numLoops)
126126
}
127-

test/fnlb-test-harness/primes-func/func.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package main
33
import (
44
"fmt"
55
"os"
6-
"strings"
76
"strconv"
7+
"strings"
88
"time"
99
)
1010

@@ -50,10 +50,9 @@ func main() {
5050
for i := 0; i < numLoops; i++ {
5151
primes := sieveOfEratosthenes(maxPrime)
5252
_ = primes
53-
if i == numLoops - 1 {
53+
if i == numLoops-1 {
5454
//fmt.Printf("Highest three primes: %d %d %d\n", primes[len(primes) - 1], primes[len(primes) - 2], primes[len(primes) - 3])
5555
}
5656
}
5757
fmt.Printf("{\"durationSeconds\": %f, \"hostname\": \"%s\", \"max\": %d, \"loops\": %d}", time.Since(start).Seconds(), os.Getenv("HOSTNAME"), maxPrime, numLoops)
5858
}
59-

0 commit comments

Comments
 (0)