mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Upgrade to Go 1.7 (#128)
* Upgrade to stdlib context package * Modernized syntax
This commit is contained in:
committed by
Seif Lotfy سيف لطفي
parent
e90a109ed5
commit
3ca137a01c
@@ -1,8 +1,9 @@
|
||||
package ifaces
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type AppListener interface {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
import "context"
|
||||
|
||||
// Titan uses a Message Queue to impose a total ordering on jobs that it will
|
||||
// execute in order. Tasks are added to the queue via the Push() interface. The
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mqs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -14,7 +15,6 @@ import (
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/runner/common"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type BoltDbMQ struct {
|
||||
@@ -104,7 +104,7 @@ func NewBoltMQ(url *url.URL) (*BoltDbMQ, error) {
|
||||
func (mq *BoltDbMQ) Start() {
|
||||
go func() {
|
||||
// It would be nice to switch to a tick-less, next-event Timer based model.
|
||||
for _ = range mq.ticker.C {
|
||||
for range mq.ticker.C {
|
||||
err := mq.db.Update(func(tx *bolt.Tx) error {
|
||||
now := uint64(time.Now().UnixNano())
|
||||
for i := 0; i < 3; i++ {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mqs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math/rand"
|
||||
"sync"
|
||||
@@ -10,7 +11,6 @@ import (
|
||||
"github.com/google/btree"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/runner/common"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type MemoryMQ struct {
|
||||
@@ -59,7 +59,7 @@ func NewMemoryMQ() *MemoryMQ {
|
||||
func (mq *MemoryMQ) start() {
|
||||
// start goroutine to check for delayed jobs and put them onto regular queue when ready
|
||||
go func() {
|
||||
for _ = range mq.Ticker.C {
|
||||
for range mq.Ticker.C {
|
||||
ji := &TaskItem{
|
||||
StartAt: time.Now(),
|
||||
}
|
||||
@@ -80,7 +80,7 @@ func (mq *MemoryMQ) start() {
|
||||
// start goroutine to check for messages that have timed out and put them back onto regular queue
|
||||
// TODO: this should be like the delayed messages above. Could even be the same thing as delayed messages, but remove them if job is completed.
|
||||
go func() {
|
||||
for _ = range mq.Ticker.C {
|
||||
for range mq.Ticker.C {
|
||||
ji := &TaskItem{
|
||||
StartAt: time.Now(),
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package mqs
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type Mock struct {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mqs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -12,7 +13,6 @@ import (
|
||||
"github.com/garyburd/redigo/redis"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/runner/common"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type RedisMQ struct {
|
||||
@@ -162,7 +162,7 @@ func (mq *RedisMQ) start() {
|
||||
logrus.WithError(err).Fatal("Could not start redis MQ reservation system")
|
||||
}
|
||||
|
||||
for _ = range mq.ticker.C {
|
||||
for range mq.ticker.C {
|
||||
mq.processPendingReservations(conn)
|
||||
mq.processDelayedTasks(conn)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package runner
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
@@ -13,7 +14,6 @@ import (
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func getTask(url string) (*models.Task, error) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@@ -15,7 +16,6 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/functions/api/mqs"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func getMockTask() models.Task {
|
||||
@@ -97,7 +97,7 @@ func TestGetTask(t *testing.T) {
|
||||
|
||||
func TestGetTaskError(t *testing.T) {
|
||||
tests := []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
{
|
||||
"url": "/invalid",
|
||||
"task": getMockTask(),
|
||||
"error": "invalid character 'p' after top-level value",
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/iron-io/runner/common"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type Logger interface {
|
||||
|
||||
@@ -2,6 +2,7 @@ package runner
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -12,8 +13,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/iron-io/runner/common"
|
||||
"github.com/iron-io/runner/drivers"
|
||||
|
||||
@@ -2,12 +2,12 @@ package runner
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func TestRunnerHello(t *testing.T) {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
dockercli "github.com/fsouza/go-dockerclient"
|
||||
"github.com/iron-io/runner/common"
|
||||
"github.com/iron-io/runner/drivers"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/runner/common"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/runner/common"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/runner/common"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/runner/common"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/runner/common"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -8,8 +9,6 @@ import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/functions/api/runner"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/functions/api/runner"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/runner/common"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/runner/common"
|
||||
|
||||
@@ -2,16 +2,14 @@ package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"encoding/json"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
|
||||
@@ -97,8 +97,8 @@ func TestRouteRunnerExecution(t *testing.T) {
|
||||
{Name: "myapp", Config: models.Config{}},
|
||||
},
|
||||
FakeRoutes: []*models.Route{
|
||||
{Path: "/myroute", AppName: "myapp", Image: "iron/hello", Headers: map[string][]string{"X-Function": []string{"Test"}}},
|
||||
{Path: "/myerror", AppName: "myapp", Image: "iron/error", Headers: map[string][]string{"X-Function": []string{"Test"}}},
|
||||
{Path: "/myroute", AppName: "myapp", Image: "iron/hello", Headers: map[string][]string{"X-Function": {"Test"}}},
|
||||
{Path: "/myerror", AppName: "myapp", Image: "iron/error", Headers: map[string][]string{"X-Function": {"Test"}}},
|
||||
},
|
||||
}, &mqs.Mock{}, testRunner(t))
|
||||
router := testRouter()
|
||||
@@ -109,12 +109,12 @@ func TestRouteRunnerExecution(t *testing.T) {
|
||||
expectedCode int
|
||||
expectedHeaders map[string][]string
|
||||
}{
|
||||
{"/r/myapp/myroute", ``, http.StatusOK, map[string][]string{"X-Function": []string{"Test"}}},
|
||||
{"/r/myapp/myerror", ``, http.StatusInternalServerError, map[string][]string{"X-Function": []string{"Test"}}},
|
||||
{"/r/myapp/myroute", ``, http.StatusOK, map[string][]string{"X-Function": {"Test"}}},
|
||||
{"/r/myapp/myerror", ``, http.StatusInternalServerError, map[string][]string{"X-Function": {"Test"}}},
|
||||
|
||||
// Added same tests again to check if time is reduced by the auth cache
|
||||
{"/r/myapp/myroute", ``, http.StatusOK, map[string][]string{"X-Function": []string{"Test"}}},
|
||||
{"/r/myapp/myerror", ``, http.StatusInternalServerError, map[string][]string{"X-Function": []string{"Test"}}},
|
||||
{"/r/myapp/myroute", ``, http.StatusOK, map[string][]string{"X-Function": {"Test"}}},
|
||||
{"/r/myapp/myerror", ``, http.StatusInternalServerError, map[string][]string{"X-Function": {"Test"}}},
|
||||
} {
|
||||
body := bytes.NewBuffer([]byte(test.body))
|
||||
_, rec := routerRequest(t, router, "GET", test.path, body)
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/ifaces"
|
||||
|
||||
Reference in New Issue
Block a user