mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Removed "name" from route, only need path.
This commit is contained in:
@@ -29,7 +29,6 @@ Now add routes to the app. First we'll add a route to the output of a docker con
|
|||||||
```sh
|
```sh
|
||||||
curl -H "Content-Type: application/json" -X POST -d '{
|
curl -H "Content-Type: application/json" -X POST -d '{
|
||||||
"route": {
|
"route": {
|
||||||
"name": "hello",
|
|
||||||
"path":"/hello",
|
"path":"/hello",
|
||||||
"image":"iron/hello"
|
"image":"iron/hello"
|
||||||
}
|
}
|
||||||
@@ -46,7 +45,7 @@ curl http://localhost:8080/r/myapp/hello
|
|||||||
|
|
||||||
### To pass in data to your function
|
### To pass in data to your function
|
||||||
|
|
||||||
Your function will get the body of the request as is, and the headers of the request will be passed in as env vars.
|
Your function will get the body of the request as is, and the headers of the request will be passed in as env vars. Try this:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
curl -H "Content-Type: application/json" -X POST -d '{
|
curl -H "Content-Type: application/json" -X POST -d '{
|
||||||
@@ -65,8 +64,8 @@ curl -H "Authorization: Bearer IRON_TOKEN" -H "Content-Type: application/json" -
|
|||||||
And you'll get an ironfunctions.com host for your app:
|
And you'll get an ironfunctions.com host for your app:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
APP_NAME.USER_ID.ironfunctions.com/PATH
|
myapp.USER_ID.ironfunctions.com/hello
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuring your API
|
## Configuring your API
|
||||||
|
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ func (ds *BoltDatastore) StoreRoute(route *models.Route) (*models.Route, error)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = b.Put([]byte(route.Name), buf)
|
err = b.Put([]byte(route.Path), buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ func TestBolt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testRoute := &models.Route{
|
testRoute := &models.Route{
|
||||||
Name: "test",
|
|
||||||
AppName: testApp.Name,
|
AppName: testApp.Name,
|
||||||
Path: "/test",
|
Path: "/test",
|
||||||
Image: "iron/hello",
|
Image: "iron/hello",
|
||||||
@@ -114,12 +113,12 @@ func TestBolt(t *testing.T) {
|
|||||||
t.Fatalf("Test GetRoute: expected error when using empty app name", err)
|
t.Fatalf("Test GetRoute: expected error when using empty app name", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
route, err := ds.GetRoute(testApp.Name, testRoute.Name)
|
route, err := ds.GetRoute(testApp.Name, testRoute.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Test GetRoute: error: %s", err)
|
t.Fatalf("Test GetRoute: error: %s", err)
|
||||||
}
|
}
|
||||||
if route.Name != testRoute.Name {
|
if route.Path != testRoute.Path {
|
||||||
t.Fatalf("Test GetRoute: expected `route.Name` to be `%s` but it was `%s`", route.Name, testRoute.Name)
|
t.Fatalf("Test GetRoute: expected `route.Name` to be `%s` but it was `%s`", route.Path, testRoute.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing list routes
|
// Testing list routes
|
||||||
@@ -130,8 +129,8 @@ func TestBolt(t *testing.T) {
|
|||||||
if len(routes) == 0 {
|
if len(routes) == 0 {
|
||||||
t.Fatal("Test GetRoutes: expected result count to be greater than 0")
|
t.Fatal("Test GetRoutes: expected result count to be greater than 0")
|
||||||
}
|
}
|
||||||
if routes[0].Name != testRoute.Name {
|
if routes[0].Path != testRoute.Path {
|
||||||
t.Fatalf("Test GetRoutes: expected `app.Name` to be `%s` but it was `%s`", testRoute.Name, routes[0].Name)
|
t.Fatalf("Test GetRoutes: expected `app.Name` to be `%s` but it was `%s`", testRoute.Path, routes[0].Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing app delete
|
// Testing app delete
|
||||||
@@ -145,12 +144,12 @@ func TestBolt(t *testing.T) {
|
|||||||
t.Fatalf("Test RemoveRoute: expected error when using empty route name", err)
|
t.Fatalf("Test RemoveRoute: expected error when using empty route name", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ds.RemoveRoute(testRoute.AppName, testRoute.Name)
|
err = ds.RemoveRoute(testRoute.AppName, testRoute.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Test RemoveApp: error: %s", err)
|
t.Fatalf("Test RemoveApp: error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
route, err = ds.GetRoute(testRoute.AppName, testRoute.Name)
|
route, err = ds.GetRoute(testRoute.AppName, testRoute.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Test GetRoute: error: %s", err)
|
t.Fatalf("Test GetRoute: error: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,8 @@ import (
|
|||||||
|
|
||||||
const routesTableCreate = `
|
const routesTableCreate = `
|
||||||
CREATE TABLE IF NOT EXISTS routes (
|
CREATE TABLE IF NOT EXISTS routes (
|
||||||
name character varying(256) NOT NULL PRIMARY KEY,
|
app_name character varying(256) NOT NULL,
|
||||||
path text NOT NULL,
|
path text NOT NULL,
|
||||||
app_name character varying(256) NOT NULL,
|
|
||||||
image character varying(256) NOT NULL,
|
image character varying(256) NOT NULL,
|
||||||
headers text NOT NULL
|
headers text NOT NULL
|
||||||
);`
|
);`
|
||||||
@@ -24,7 +23,7 @@ const appsTableCreate = `CREATE TABLE IF NOT EXISTS apps (
|
|||||||
name character varying(256) NOT NULL PRIMARY KEY
|
name character varying(256) NOT NULL PRIMARY KEY
|
||||||
);`
|
);`
|
||||||
|
|
||||||
const routeSelector = `SELECT name, path, app_name, image, headers FROM routes`
|
const routeSelector = `SELECT app_name, path, image, headers FROM routes`
|
||||||
|
|
||||||
type rowScanner interface {
|
type rowScanner interface {
|
||||||
Scan(dest ...interface{}) error
|
Scan(dest ...interface{}) error
|
||||||
@@ -159,16 +158,15 @@ func (ds *PostgresDatastore) StoreRoute(route *models.Route) (*models.Route, err
|
|||||||
|
|
||||||
_, err = ds.db.Exec(`
|
_, err = ds.db.Exec(`
|
||||||
INSERT INTO routes (
|
INSERT INTO routes (
|
||||||
name, app_name, path, image,
|
app_name, path, image,
|
||||||
headers
|
headers
|
||||||
)
|
)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
VALUES ($1, $2, $3, $4, $5)
|
||||||
ON CONFLICT (name) DO UPDATE SET
|
ON CONFLICT (name) DO UPDATE SET
|
||||||
path = $3,
|
path = $1,
|
||||||
image = $4,
|
image = $2,
|
||||||
headers = $5;
|
headers = $3;
|
||||||
`,
|
`,
|
||||||
route.Name,
|
|
||||||
route.AppName,
|
route.AppName,
|
||||||
route.Path,
|
route.Path,
|
||||||
route.Image,
|
route.Image,
|
||||||
@@ -196,9 +194,9 @@ func (ds *PostgresDatastore) RemoveRoute(appName, routeName string) error {
|
|||||||
func scanRoute(scanner rowScanner, route *models.Route) error {
|
func scanRoute(scanner rowScanner, route *models.Route) error {
|
||||||
var headerStr string
|
var headerStr string
|
||||||
err := scanner.Scan(
|
err := scanner.Scan(
|
||||||
&route.Name,
|
// &route.Name,
|
||||||
&route.Path,
|
|
||||||
&route.AppName,
|
&route.AppName,
|
||||||
|
&route.Path,
|
||||||
&route.Image,
|
&route.Image,
|
||||||
&headerStr,
|
&headerStr,
|
||||||
)
|
)
|
||||||
|
|||||||
16
api/ifaces/app.go
Normal file
16
api/ifaces/app.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package ifaces
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
type App interface {
|
||||||
|
Name() string
|
||||||
|
Routes() Route
|
||||||
|
Validate() error
|
||||||
|
}
|
||||||
|
|
||||||
|
type Route interface {
|
||||||
|
// AppName() string `json:"appname"`
|
||||||
|
Path() string
|
||||||
|
Image() string
|
||||||
|
Headers() http.Header
|
||||||
|
}
|
||||||
@@ -21,7 +21,6 @@ var (
|
|||||||
type Routes []*Route
|
type Routes []*Route
|
||||||
|
|
||||||
type Route struct {
|
type Route struct {
|
||||||
Name string `json:"name"`
|
|
||||||
AppName string `json:"appname"`
|
AppName string `json:"appname"`
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
@@ -39,10 +38,6 @@ var (
|
|||||||
func (r *Route) Validate() error {
|
func (r *Route) Validate() error {
|
||||||
var res []error
|
var res []error
|
||||||
|
|
||||||
if r.Name == "" {
|
|
||||||
res = append(res, ErrRoutesValidationMissingName)
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.Image == "" {
|
if r.Image == "" {
|
||||||
res = append(res, ErrRoutesValidationMissingImage)
|
res = append(res, ErrRoutesValidationMissingImage)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ func handleRouteUpdate(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wroute.Route.AppName = c.Param("app")
|
wroute.Route.AppName = c.Param("app")
|
||||||
wroute.Route.Name = c.Param("route")
|
log.Infoln("Route: ", c.Param("route"))
|
||||||
|
wroute.Route.Path = c.Param("route")
|
||||||
|
|
||||||
if err := wroute.Validate(); err != nil {
|
if err := wroute.Validate(); err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
|||||||
8
main.go
8
main.go
@@ -1,10 +1,3 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
For keeping a minimum running, perhaps when doing a routing table update, if destination hosts are all
|
|
||||||
expired or about to expire we start more.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -16,6 +9,7 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// See comments below for how to extend Functions
|
||||||
func main() {
|
func main() {
|
||||||
c := &models.Config{}
|
c := &models.Config{}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user