Skip to content

Commit

Permalink
lib reg linter issues resolved (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Kaley authored and josephgorse committed Aug 22, 2016
1 parent 0c38553 commit 278634a
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 68 deletions.
103 changes: 98 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,112 @@
ORGANIZATION = RackHD
PROJECT = neighborhood-manager
REGISTRY = registry
PROXY = rackhd


TTY = $(shell if [ -t 0 ]; then echo "-ti"; fi)

PROJECT_DIR = /go/src/github.com/${ORGANIZATION}/${PROJECT}
DOCKER_DIR = ${PROJECT_DIR}
DOCKER_DIR = /go/src/github.com/${ORGANIZATION}/${PROJECT}
DOCKER_IMAGE = rackhd/golang:1.7.0-wheezy
DOCKER_CMD = docker run --rm -v ${PWD}:${PROJECT_DIR} ${TTY} -w ${DOCKER_DIR} ${DOCKER_IMAGE}
DOCKER_CMD = docker run --rm -v ${PWD}:${DOCKER_DIR} ${TTY} -w ${DOCKER_DIR} ${DOCKER_IMAGE}


# variable definitions
COMMITHASH = $(shell git describe --tags --always --dirty)
BUILDDATE = $(shell date -u)
BUILDER = $(shell echo "`git config user.name` <`git config user.email`>")
GOVERSION = $(shell go version)
OSARCH = $(shell uname -sm)
RELEASEVERSION = 0.1



#Flags to pass to main.go
REGFLAGS = -ldflags "-X 'main.binaryName=${REGISTRY}' \
-X 'main.buildDate=${BUILDDATE}' \
-X 'main.buildUser=${BUILDER}' \
-X 'main.commitHash=${COMMITHASH}' \
-X 'main.goVersion=${GOVERSION}' \
-X 'main.osArch=${OSARCH}' \
-X 'main.releaseVersion=${RELEASEVERSION}' "

PROXYFLAGS = -ldflags "-X 'main.binaryName=${PROXY}' \
-X 'main.buildDate=${BUILDDATE}' \
-X 'main.buildUser=${BUILDER}' \
-X 'main.commitHash=${COMMITHASH}' \
-X 'main.goVersion=${GOVERSION}' \
-X 'main.osArch=${OSARCH}' \
-X 'main.releaseVersion=${RELEASEVERSION}' "

noop:
@echo Neighborhood Manager
#Some tests need to run for 5+ seconds, which trips Ginkgo Slow Test warning
SLOWTEST = 10

.PHONY: shell deps deps-local build build-local lint lint-local test test-local release

default: deps test build

coveralls:
@go get github.com/mattn/goveralls
@go get github.com/modocache/gover
@go get golang.org/x/tools/cmd/cover
@gover
@goveralls -coverprofile=gover.coverprofile -service=travis-ci

shell:
@${DOCKER_CMD} /bin/bash

consul-shell:
@docker run --rm -ti --net nmregistry_default -v ${PWD}:${DOCKER_DIR} -w ${DOCKER_DIR} ${DOCKER_IMAGE} /bin/bash

clean:
@${DOCKER_CMD} make clean-local

clean-local:
@rm -rf bin vendor

deps:
@${DOCKER_CMD} make deps-local

deps-local:
@if ! [ -f glide.lock ]; then glide init --non-interactive; fi
@glide install --strip-vcs --strip-vendor

build:
@build-reg
@build-proxy

build-proxy:
@${DOCKER_CMD} make build-proxy-local

build-proxy-local:
@go build -o bin/${PROXY} ${PROXYFLAGS} rackhd/cmd/rackhd/*.go
@go build -o bin/endpoint rackhd/cmd/utils/*.go

build-reg:
@${DOCKER_CMD} make build-reg-local

build-reg-local: lint-local
@go build -o bin/${REGISTRY} ${LDFLAGS} registry/cmd/registry/*.go
@go build -o registry/cmd/ssdpspoofer/bin/ssdpspoofer registry/cmd/ssdpspoofer/*.go

lint:
@${DOCKER_CMD} make lint-local

lint-local:
@gometalinter --vendor --fast --disable=dupl --disable=gotype --skip=grpc ./...

test:
@${DOCKER_CMD} make test-local

test-local: lint-local
@ginkgo -r -race -trace -cover -randomizeAllSpecs --slowSpecThreshold=${SLOWTEST}

release: deps build
@docker build -t rackhd/${REGISTRY} registry
@docker build -t rackhd/ssdpspoofer registry/cmd/ssdpspoofer/
@docker build -t rackhd/${PROXY} rackhd
@docker build -t rackhd/endpoint rackhd/cmd/utils/


run: release
@docker-compose up --force-recreate
16 changes: 12 additions & 4 deletions registry/glide.lock → glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions registry/glide.yaml → glide.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package: github.com/RackHD/neighborhood-manager/registry
package: github.com/RackHD/neighborhood-manager
import:
- package: github.com/hashicorp/consul
subpackages:
- api
- package: github.com/king-jam/gossdp
- package: github.com/spf13/viper
- package: github.com/hashicorp/consul
ignore:
- github.com/RackHD/neighborhood-manager
14 changes: 0 additions & 14 deletions libreg/glide.lock

This file was deleted.

5 changes: 0 additions & 5 deletions libreg/glide.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion libreg/registry/consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (s *Consul) setTimeout(time time.Duration) {
s.config.WaitTime = time
}

// Register adds an entry into the consul backend
func (s *Consul) Register(reg *registry.CatalogRegistration, options *registry.WriteOptions) error {
catalog := s.client.Catalog()
writeOps := s.getWriteOptions(options)
Expand Down Expand Up @@ -202,7 +203,7 @@ func (s *Consul) Node(node string, options *registry.QueryOptions) (*registry.Ca
return nil, nil
}

var retNode *registry.Node = &registry.Node{
var retNode = &registry.Node{
Node: n.Node.Node,
Address: n.Node.Address,
}
Expand Down
8 changes: 5 additions & 3 deletions libreg/registry/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ import (
"github.com/RackHD/neighborhood-manager/libreg/registry"
)

// Mock is...
type Mock struct {
Catalog map[*registry.CatalogRegistration]bool
sync.RWMutex
}

// Register inits a new MOCK
func Register() {
libreg.AddRegistry(registry.MOCK, New)
}

// New instantiates a new registry
func New(endpoints []string, options *registry.Config) (registry.Registry, error) {
m := &Mock{}
m.Catalog = make(map[*registry.CatalogRegistration]bool)
return m, nil
}

// GetSearchTerms returns the whitelist of SSDP URNs to act on
// GetCatalog returns the whitelist of SSDP URNs to act on
func (m *Mock) GetCatalog() map[registry.CatalogRegistration]bool {
c := make(map[registry.CatalogRegistration]bool)

Expand Down Expand Up @@ -131,8 +134,7 @@ func (m *Mock) Service(service, tag string, options *registry.QueryOptions) ([]*
containsTag = true
}

if r.Service.Service == service &&
containsTag == true {
if r.Service.Service == service && containsTag {
catalogService := registry.CatalogService{
Node: r.Node,
Address: r.Address,
Expand Down
9 changes: 7 additions & 2 deletions libreg/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
ErrNotReachable = errors.New("API not reachable")
// ErrNodeNotFound is thrown when the node is not found int he registry
ErrNodeNotFound = errors.New("Node not found in registry")
// ErrKSvcNotFound is thrown when the service is not found in the registry
// ErrSvcNotFound is thrown when the service is not found in the registry
ErrSvcNotFound = errors.New("Service not found in registry")
)

Expand All @@ -40,7 +40,7 @@ type Config struct {
Password string
}

/// ClientTLSConfig contains data for a Client TLS configuration in the form
// ClientTLSConfig contains data for a Client TLS configuration in the form
// the etcd client wants it. Eventually we'll adapt it for ZK and Consul.
type ClientTLSConfig struct {
CertFile string
Expand Down Expand Up @@ -74,11 +74,13 @@ type Registry interface {
Node(node string, options *QueryOptions) (*CatalogNode, error)
}

// Node is ...
type Node struct {
Node string
Address string
}

// CatalogService is ...
type CatalogService struct {
Node string
Address string
Expand All @@ -90,11 +92,13 @@ type CatalogService struct {
ServiceEnableTagOverride bool
}

// CatalogNode is ...
type CatalogNode struct {
Node *Node
Services map[string]*AgentService
}

// CatalogRegistration is ...
type CatalogRegistration struct {
Node string
Address string
Expand All @@ -103,6 +107,7 @@ type CatalogRegistration struct {
Check *AgentCheck
}

//CatalogDeregistration is ...
type CatalogDeregistration struct {
Node string
Address string
Expand Down
23 changes: 0 additions & 23 deletions rackhd/glide.lock

This file was deleted.

7 changes: 0 additions & 7 deletions rackhd/glide.yaml

This file was deleted.

0 comments on commit 278634a

Please sign in to comment.