Labels sorting by default and enhancements

Faster building,
disable API fix.
This commit is contained in:
Adam Štrauch 2021-09-07 01:18:17 +02:00
parent 2f4203e7c3
commit 58495d59c1
Signed by: cx
GPG Key ID: 018304FFA8988F8D
5 changed files with 37 additions and 9 deletions

View File

@ -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

View File

@ -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)

View File

@ -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
// -----------------

View File

@ -138,6 +138,7 @@ func (l *LocalHost) GetIdentification() (Discovery, error) {
}
discovery.Labels = append(l.InitialLabels, localLabels...)
discovery.SortLabels()
return discovery, nil
}

View File

@ -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)
}