diff --git a/Makefile b/Makefile index ce1e972..bbd8200 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=1.0 +VERSION=1.1 .PHONY: all @@ -12,25 +12,39 @@ clean: test: go test -v server/*.go -.PHONY: build -build: test clean +init: mkdir -p ./bin + +.PHONY: build +build: test clean init linux-amd64 linux-arm linux-arm64 darwin-amd64 darwin-arm64 + + +.PHONY: linux-amd64 +linux-amd64: clean init # linux amd64 env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/lobbyd-${VERSION}-linux-amd64 daemon/*.go env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/lobbyctl-${VERSION}-linux-amd64 ctl/*.go +.PHONY: linux-arm +linux-arm: clean init # linux arm env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o ./bin/lobbyd-${VERSION}-linux-arm daemon/*.go env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o ./bin/lobbyctl-${VERSION}-linux-arm ctl/*.go +.PHONY: linux-arm64 +linux-arm64: clean init # linux arm64 env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o ./bin/lobbyd-${VERSION}-linux-arm64 daemon/*.go env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o ./bin/lobbyctl-${VERSION}-linux-arm64 ctl/*.go +.PHONY: darwin-amd64 +darwin-amd64: clean init # darwin amd64 - env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/lobbyd-${VERSION}-darwin-amd64 daemon/*.go - env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/lobbyctl-${VERSION}-darwin-amd64 ctl/*.go + env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ./bin/lobbyd-${VERSION}-darwin-amd64 daemon/*.go + env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ./bin/lobbyctl-${VERSION}-darwin-amd64 ctl/*.go +.PHONY: darwin-arm64 +darwin-arm64: clean init # darwin arm64 - env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o ./bin/lobbyd-${VERSION}-darwin-arm64 daemon/*.go - env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o ./bin/lobbyctl-${VERSION}-darwin-arm64 ctl/*.go + env CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o ./bin/lobbyd-${VERSION}-darwin-arm64 daemon/*.go + env CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o ./bin/lobbyctl-${VERSION}-darwin-arm64 ctl/*.go diff --git a/daemon/main.go b/daemon/main.go index be20766..2574836 100644 --- a/daemon/main.go +++ b/daemon/main.go @@ -163,7 +163,7 @@ func main() { e.Use(middleware.Recover()) // Routes - if config.DisableAPI { + if !config.DisableAPI { e.GET("/", listHandler) e.GET("/v1/discovery", getIdentificationHandler) e.GET("/v1/discoveries", listHandler) diff --git a/server/discovery.go b/server/discovery.go index 162011e..3d5fd6d 100644 --- a/server/discovery.go +++ b/server/discovery.go @@ -3,6 +3,7 @@ package server import ( "encoding/json" "fmt" + "sort" "strings" "time" ) @@ -56,6 +57,18 @@ func (d *Discovery) FindLabels(prefix string) Labels { return labels } +func (d *Discovery) SortLabels() { + labelStrings := d.Labels.StringSlice() + sort.Strings(labelStrings) + + labels := Labels{} + for _, label := range labelStrings { + labels = append(labels, Label(label)) + } + + d.Labels = labels +} + // ----------------- // Discovery storage // ----------------- diff --git a/server/identification.go b/server/identification.go index 5939bda..6c7adb4 100644 --- a/server/identification.go +++ b/server/identification.go @@ -138,6 +138,7 @@ func (l *LocalHost) GetIdentification() (Discovery, error) { } discovery.Labels = append(l.InitialLabels, localLabels...) + discovery.SortLabels() return discovery, nil } diff --git a/server/identification_test.go b/server/identification_test.go index 336069f..43960de 100644 --- a/server/identification_test.go +++ b/server/identification_test.go @@ -32,7 +32,7 @@ func TestGetIdentification(t *testing.T) { discovery, err = localHost.GetIdentification() assert.Nil(t, err) - assert.Equal(t, Label("public_ip:1.2.3.4"), discovery.Labels[3]) + assert.Equal(t, Label("test:1"), discovery.Labels[3]) os.RemoveAll(tmpPath) }