Skip to content

Commit fb2f5ea

Browse files
committed
refactoring using Go
1 parent 2460fa2 commit fb2f5ea

File tree

140 files changed

+25874
-3250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+25874
-3250
lines changed

.gitignore

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,21 @@
1-
# Temporary and binary files
2-
*~
3-
*.py[cod]
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
45
*.so
5-
*.cfg
6-
!.isort.cfg
7-
!setup.cfg
8-
*.orig
9-
*.log
10-
*.pot
11-
__pycache__/*
12-
.cache/*
13-
.*.swp
14-
*/.ipynb_checkpoints/*
15-
.DS_Store
6+
*.dylib
167

17-
# Project files
18-
.ropeproject
19-
.project
20-
.pydevproject
21-
.settings
22-
.idea
23-
.vscode
24-
tags
8+
# Test binary, built with `go test -c`
9+
*.test
2510

26-
# Package files
27-
*.egg
28-
*.eggs/
29-
.installed.cfg
30-
*.egg-info
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
3113

32-
# Unittest and coverage
33-
htmlcov/*
34-
.coverage
35-
.coverage.*
36-
.tox
37-
junit*.xml
38-
coverage.xml
39-
.pytest_cache/
14+
# Dependency directories (remove the comment below to include it)
15+
vendor/
4016

41-
# Build and docs folder/files
42-
build/*
43-
dist/*
44-
sdist/*
45-
docs/api/*
46-
docs/_rst/*
47-
docs/_build/*
48-
cover/*
49-
MANIFEST
50-
.pybuild
51-
debian/purity-fa-prometheus-exporter
52-
debian/.debhelper
53-
debian/debhelper-build-stamp
54-
debian/*debhelper
55-
debian/*substvars
17+
# Go workspace file
18+
go.work
5619

57-
# Per-project virtualenvs
58-
.venv*/
59-
.conda*/
20+
# Build directory
21+
out/

Dockerfile.rhubi

Lines changed: 0 additions & 23 deletions
This file was deleted.

Dockerfile.slim

Lines changed: 0 additions & 25 deletions
This file was deleted.

LICENSE.txt

Whitespace-only changes.

Makefile

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
GOCMD=go
2+
GOTEST=$(GOCMD) test
3+
GOVET=$(GOCMD) vet
4+
BINARY_NAME=pure-fa-om-exporter
5+
MODULE_NAME=go mod init purestorage/fa-openmetrics-exporter
6+
VERSION?=0.2.0
7+
SERVICE_PORT?=9491
8+
DOCKER_REGISTRY?= quay.io/purestorage/
9+
EXPORT_RESULT?=false # for CI please set EXPORT_RESULT to true
10+
11+
GREEN := $(shell tput -Txterm setaf 2)
12+
YELLOW := $(shell tput -Txterm setaf 3)
13+
WHITE := $(shell tput -Txterm setaf 7)
14+
CYAN := $(shell tput -Txterm setaf 6)
15+
RESET := $(shell tput -Txterm sgr0)
16+
17+
.PHONY: all test build
18+
19+
all: help
20+
21+
## Build:
22+
init:
23+
$(GOCMD) init go mod init $(MODULE_NAME)
24+
$(GOCMD) mod tidy
25+
26+
build: ## Build your project and put the output binary in out/bin/
27+
mkdir -p out/bin
28+
GO111MODULE=on $(GOCMD) build -o out/bin/$(BINARY_NAME) cmd/fa-om-exporter/main.go
29+
30+
clean: ## Remove build related file
31+
rm -fr ./bin
32+
rm -fr ./out
33+
rm -f ./junit-report.xml checkstyle-report.xml ./coverage.xml ./profile.cov yamllint-checkstyle.xml
34+
35+
watch: ## Run the code with cosmtrek/air to have automatic reload on changes
36+
$(eval PACKAGE_NAME=$(shell head -n 1 go.mod | cut -d ' ' -f2))
37+
docker run -it --rm -w /go/src/$(PACKAGE_NAME) -v $(shell pwd):/go/src/$(PACKAGE_NAME) -p $(SERVICE_PORT):$(SERVICE_PORT) cosmtrek/air
38+
39+
## Test:
40+
test: ## Run the tests of the project
41+
ifeq ($(EXPORT_RESULT), true)
42+
GO111MODULE=off go get -u github.com/jstemmer/go-junit-report
43+
$(eval OUTPUT_OPTIONS = | tee /dev/tty | go-junit-report -set-exit-code > junit-report.xml)
44+
endif
45+
$(GOTEST) -v -race ./... $(OUTPUT_OPTIONS)
46+
47+
coverage: ## Run the tests of the project and export the coverage
48+
$(GOTEST) -cover -covermode=count -coverprofile=profile.cov ./...
49+
$(GOCMD) tool cover -func profile.cov
50+
ifeq ($(EXPORT_RESULT), true)
51+
GO111MODULE=off go get -u github.com/AlekSi/gocov-xml
52+
GO111MODULE=off go get -u github.com/axw/gocov/gocov
53+
gocov convert profile.cov | gocov-xml > coverage.xml
54+
endif
55+
56+
## Lint:
57+
lint: lint-go lint-dockerfile lint-yaml ## Run all available linters
58+
59+
lint-dockerfile: ## Lint your Dockerfile
60+
# If dockerfile is present we lint it.
61+
ifeq ($(shell test -e ./Dockerfile && echo -n yes),yes)
62+
$(eval CONFIG_OPTION = $(shell [ -e $(shell pwd)/.hadolint.yaml ] && echo "-v $(shell pwd)/.hadolint.yaml:/root/.config/hadolint.yaml" || echo "" ))
63+
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--format checkstyle" || echo "" ))
64+
$(eval OUTPUT_FILE = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "| tee /dev/tty > checkstyle-report.xml" || echo "" ))
65+
docker run --rm -i $(CONFIG_OPTION) hadolint/hadolint hadolint $(OUTPUT_OPTIONS) - < ./Dockerfile $(OUTPUT_FILE)
66+
endif
67+
68+
lint-go: ## Use golintci-lint on your project
69+
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--out-format checkstyle ./... | tee /dev/tty > checkstyle-report.xml" || echo "" ))
70+
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run --deadline=65s $(OUTPUT_OPTIONS)
71+
72+
lint-yaml: ## Use yamllint on the yaml file of your projects
73+
ifeq ($(EXPORT_RESULT), true)
74+
GO111MODULE=off go get -u github.com/thomaspoignant/yamllint-checkstyle
75+
$(eval OUTPUT_OPTIONS = | tee /dev/tty | yamllint-checkstyle > yamllint-checkstyle.xml)
76+
endif
77+
docker run --rm -it -v $(shell pwd):/data cytopia/yamllint -f parsable $(shell git ls-files '*.yml' '*.yaml') $(OUTPUT_OPTIONS)
78+
79+
## Docker:
80+
docker-build: ## Use the dockerfile to build the container
81+
docker build --rm --tag $(BINARY_NAME) --file build/docker/Dockerfile .
82+
83+
docker-release: ## Release the container with tag latest and version
84+
docker tag $(BINARY_NAME) $(DOCKER_REGISTRY)$(BINARY_NAME):latest
85+
docker tag $(BINARY_NAME) $(DOCKER_REGISTRY)$(BINARY_NAME):$(VERSION)
86+
# Push the docker images
87+
docker push $(DOCKER_REGISTRY)$(BINARY_NAME):latest
88+
docker push $(DOCKER_REGISTRY)$(BINARY_NAME):$(VERSION)
89+
90+
## Help:
91+
help: ## Show this help.
92+
@echo ''
93+
@echo 'Usage:'
94+
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
95+
@echo ''
96+
@echo 'Targets:'
97+
@awk 'BEGIN {FS = ":.*?## "} { \
98+
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
99+
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
100+
}' $(MAKEFILE_LIST)

README.md

Lines changed: 0 additions & 101 deletions
This file was deleted.

cmd/fa-om-exporter/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"purestorage/fa-openmetrics-exporter/internal/rest-client"
6+
)
7+
8+
9+
func main() {
10+
c := client.NewRestClient("10.225.112.90", "b5cb29e7-a93c-b40a-b02f-da2b90c8c65e", "latest")
11+
defer c.Close()
12+
var cli client.Client
13+
cli = c
14+
al := cli.GetArrays()
15+
for _, a := range al.Items {
16+
fmt.Println(a)
17+
}
18+
}

examples/config/docker/README.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

examples/config/k8s/grafana-datasource.yaml

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)