mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Merge branch 'master' of https://github.com/treeder/router
This commit is contained in:
@@ -219,7 +219,7 @@ func AddWorker(w http.ResponseWriter, req *http.Request) {
|
|||||||
route.Token = token
|
route.Token = token
|
||||||
route.CodeName = codeName
|
route.CodeName = codeName
|
||||||
// todo: do we need to close body?
|
// todo: do we need to close body?
|
||||||
err := putRoute(route)
|
err := putRoute(&route)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("couldn't register host:", err)
|
fmt.Println("couldn't register host:", err)
|
||||||
common.SendError(w, 400, fmt.Sprintln("Could not register host!", err))
|
common.SendError(w, 400, fmt.Sprintln("Could not register host!", err))
|
||||||
@@ -257,18 +257,27 @@ func AddWorker(w http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRoute(host string) (Route, error) {
|
func getRoute(host string) (*Route, error) {
|
||||||
rx, err := icache.Get(host)
|
rx, err := icache.Get(host)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
rx2 := []byte(rx.(string))
|
||||||
route := Route{}
|
route := Route{}
|
||||||
|
err = json.Unmarshal(rx2, &route)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
route = rx.(Route)
|
route = rx.(Route)
|
||||||
}
|
}
|
||||||
return route, err
|
return &route, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func putRoute(route Route) (error) {
|
func putRoute(route *Route) (error) {
|
||||||
item := cache.Item{}
|
item := cache.Item{}
|
||||||
item.Value = route
|
v, err := json.Marshal(route)
|
||||||
err := icache.Put(route.Host, &item)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
item.Value = string(v)
|
||||||
|
err = icache.Put(route.Host, &item)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user