changed ids to base64 format.

This commit is contained in:
didier amyot committed 2015-07-06 10:43:33 -04:00
1 parent af69e728a2
commit 0c8e5ed294
7 files changed
+115 -56

No files matched your search

+6 -11
View File
@@ -3,11 +3,9 @@ package subscriber
import (
"encoding/json"
"errors"
"fmt"
"github.com/didiercrunch/doorman/httpsubscriber"
"github.com/didiercrunch/doorman/nanomsgsubscriber"
"github.com/didiercrunch/doorman/shared"
"gopkg.in/mgo.v2/bson"
"net/http"
"time"
)
@@ -17,7 +15,7 @@ type Subscriber struct {
}
type subscriber interface {
Subscribe(abtestId bson.ObjectId, update shared.UpdateHandlerFunc) error
Subscribe(abtestId string, update shared.UpdateHandlerFunc) error
}
type ServerSpecification struct {
@@ -29,7 +27,6 @@ type ServerSpecification struct {
func (s *Subscriber) getServerSpecification() (*ServerSpecification, error) {
url := s.URL + "/api/server"
fmt.Println(">>>", url)
resp, err := http.Get(url)
if err != nil {
return nil, err
@@ -41,24 +38,22 @@ func (s *Subscriber) getServerSpecification() (*ServerSpecification, error) {
ret := new(ServerSpecification)
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(ret)
fmt.Println("ok!")
return ret, err
}
func (sub *Subscriber) GetSubsciber(serverSpec *ServerSpecification, doormanId bson.ObjectId) subscriber {
func (sub *Subscriber) GetSubsciber(serverSpec *ServerSpecification, doormanId string) subscriber {
switch serverSpec.MessageQueue {
case "nanomsg":
return &nanomsgsubscriber.NanoMsgSubscriber{serverSpec.NanoMsg["url"]}
}
fmt.Println("shit!", serverSpec)
return &httpsubscriber.HttpSubscriber{sub.getDoormanStatusUrl(doormanId), time.Second * 5}
}
func (sub *Subscriber) getDoormanStatusUrl(doormanId bson.ObjectId) string {
return sub.URL + "/api/doormen/" + doormanId.Hex() + "/status"
func (sub *Subscriber) getDoormanStatusUrl(doormanId string) string {
return sub.URL + "/api/doormen/" + doormanId + "/status"
}
func (sub *Subscriber) SetInitialState(doormanId bson.ObjectId, update shared.UpdateHandlerFunc) error {
func (sub *Subscriber) SetInitialState(doormanId string, update shared.UpdateHandlerFunc) error {
httpSUbscriber := &httpsubscriber.HttpSubscriber{Url: sub.getDoormanStatusUrl(doormanId)}
if du, err := httpSUbscriber.GetDoormanUpdater(); err != nil {
return err
@@ -72,7 +67,7 @@ func startHartBeat() error {
return nil
}
func (sub *Subscriber) Subscribe(doormanId bson.ObjectId, update shared.UpdateHandlerFunc) error {
func (sub *Subscriber) Subscribe(doormanId string, update shared.UpdateHandlerFunc) error {
spec, err := sub.getServerSpecification()
if err != nil {
return err