major refactoring of the api

This commit is contained in:
didier amyot committed 2015-03-28 20:53:28 -07:00
1 parent d4f7dc57fc
commit f0628e4682
38 files changed
+821 -367

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
package serverstat
import (
"runtime"
"strings"
"github.com/didiercrunch/doormanserver/shared"
)
type m map[string]interface{}
var GO_VERSION = runtime.Version()
type ServerStat struct {
Hostname string `json:"hostname"`
Port int `json:"port"`
Go string `json:"go_version"`
MessageQueue string `json:"message_queue"`
NSQ m `json:"nsq,omitempty"`
Nanomsg m `json:"nano_msg,omitempty"`
}
func Get(p *shared.Params) *ServerStat {
r := new(ServerStat)
r.Hostname = p.Host
r.Port = p.Port
r.Go = GO_VERSION
r.MessageQueue = strings.ToLower(p.MessageQueue)
if p.UseNSQ() {
r.NSQ = m{"ns_lookup_url": p.NSQ.NSQLookupdUrl}
}
if p.UseNanomsg() {
r.Nanomsg = m{"url": p.NanoMsg.NanoMsgUrl}
}
return r
}
+28
View File
@@ -0,0 +1,28 @@
package serverstat
import (
"encoding/json"
"reflect"
"testing"
)
import "github.com/didiercrunch/doormanserver/shared"
func deserializeServerStats(data []byte) *ServerStat {
ret := new(ServerStat)
if err := json.Unmarshal(data, ret); err != nil {
panic("cannot deserialize data")
}
return ret
}
func ServerStatsEqual(a, b *ServerStat) bool {
return reflect.DeepEqual(a, b)
}
func TestGetTrivial(t *testing.T) {
p := new(shared.Params)
expected := &ServerStat{Go: GO_VERSION}
if s := Get(p); !ServerStatsEqual(s, expected) {
t.Error(s)
}
}