Skip to content

Commit

Permalink
formatting go code
Browse files Browse the repository at this point in the history
Signed-off-by: Weifeng Wang <[email protected]>

format go code

Signed-off-by: Weifeng Wang <[email protected]>

formatting go code

Signed-off-by: Weifeng Wang <[email protected]>

Update Makefile
  • Loading branch information
qclaogui committed Aug 22, 2024
1 parent 83dc4cb commit c295920
Show file tree
Hide file tree
Showing 26 changed files with 172 additions and 65 deletions.
12 changes: 12 additions & 0 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ $(COPYRIGHT): $(BINGO_DIR)/copyright.mod
@echo "(re)installing $(GOBIN)/copyright-v0.0.0-20230505153745-6b7392939a60"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=copyright.mod -o=$(GOBIN)/copyright-v0.0.0-20230505153745-6b7392939a60 "github.com/efficientgo/tools/copyright"

GOFUMPT := $(GOBIN)/gofumpt-v0.7.0
$(GOFUMPT): $(BINGO_DIR)/gofumpt.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/gofumpt-v0.7.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=gofumpt.mod -o=$(GOBIN)/gofumpt-v0.7.0 "mvdan.cc/gofumpt"

GOIMPORTS := $(GOBIN)/goimports-v0.24.0
$(GOIMPORTS): $(BINGO_DIR)/goimports.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/goimports-v0.24.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=goimports.mod -o=$(GOBIN)/goimports-v0.24.0 "golang.org/x/tools/cmd/goimports"

GORELEASER := $(GOBIN)/goreleaser-v1.26.2
$(GORELEASER): $(BINGO_DIR)/goreleaser.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
Expand Down
5 changes: 5 additions & 0 deletions .bingo/gofumpt.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.23.0

require mvdan.cc/gofumpt v0.7.0
10 changes: 10 additions & 0 deletions .bingo/gofumpt.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
mvdan.cc/gofumpt v0.7.0 h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU=
mvdan.cc/gofumpt v0.7.0/go.mod h1:txVFJy/Sc/mvaycET54pV8SW8gWxTlUuGHVEcncmNUo=
5 changes: 5 additions & 0 deletions .bingo/goimports.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.23.0

require golang.org/x/tools v0.24.0 // cmd/goimports
6 changes: 6 additions & 0 deletions .bingo/goimports.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
4 changes: 4 additions & 0 deletions .bingo/variables.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ CMCTL="${GOBIN}/cmctl-v2.1.0"

COPYRIGHT="${GOBIN}/copyright-v0.0.0-20230505153745-6b7392939a60"

GOFUMPT="${GOBIN}/gofumpt-v0.7.0"

GOIMPORTS="${GOBIN}/goimports-v0.24.0"

GORELEASER="${GOBIN}/goreleaser-v1.26.2"

GRR="${GOBIN}/grr-v0.4.4"
Expand Down
4 changes: 2 additions & 2 deletions .github/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ builds:
- >-
{{- if eq .Env.RELEASE_BUILD "1" }}-s -w{{- end }}
- -X github.com/qclaogui/codelab-monitoring/pkg/version.Version={{.Version}}
- -X github.com/qclaogui/codelab-monitoring/pkg/version.GitCommit={{.ShortCommit}}
- -X github.com/qclaogui/codelab-monitoring/pkg/version.BuildDate={{.Date}}
- -X github.com/qclaogui/codelab-monitoring/pkg/version.gitCommit={{.ShortCommit}}
- -X github.com/qclaogui/codelab-monitoring/pkg/version.buildDate={{.Date}}
- -X github.com/qclaogui/codelab-monitoring/pkg/version.PreReleaseID={{.Env.PRE_RELEASE_ID}}

# GOOS list to build for.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: '1.23'

- name: Run Dagger pipeline
run: go run ci/main.go
2 changes: 1 addition & 1 deletion .github/workflows/trigger-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: '1.23'
- name: Setup identity
uses: ./.github/actions/setup-identity
with:
Expand Down
22 changes: 18 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,29 @@ copyright: $(COPYRIGHT) ## Add Copyright header to .go files.
@$(COPYRIGHT) $(shell go list -f "{{.Dir}}" ./... | xargs -I {} find {} -name "*.go" | grep -iv "vendor/")
@echo ">> ensured all .go files have copyright headers"

.PHONY: fmt
fmt: go-fmt alloy-fmt


ALLOY_CONFIG_FILES = $(shell find . -type f -name '*.alloy')
ALLOY_CONFIG_FILES_IN_DOCKER = $(subst ./, /data/, $(ALLOY_CONFIG_FILES))
.PHONY: fmt
fmt: ## Uses Grafana Alloy to fmt the config

.PHONY: alloy-fmt
alloy-fmt: ## Uses Grafana Alloy to fmt the config
@for c in $(ALLOY_CONFIG_FILES_IN_DOCKER); do \
echo "$$c"; \
docker run --rm --volume "$(shell pwd):/data" -u $(shell id -u) grafana/alloy:v1.3.0 fmt -w $$c ; \
done

.PHONY: go-fmt
go-fmt: $(GOIMPORTS) $(GOFUMPT)
@echo ">> formatting go code"
@$(GOFUMPT) -w $(GO_FILES_TO_FMT)
@for file in $(GO_FILES_TO_FMT) ; do \
tools/scripts/goimports.sh "$${file}"; \
done
@$(GOIMPORTS) -w $(GO_FILES_TO_FMT)

##@ Docker compose


Expand Down Expand Up @@ -444,6 +457,7 @@ GOARM ?= $(shell go env GOARM)
CGO_ENABLED ?= 0
RELEASE_BUILD ?= 0

GO_FILES_TO_FMT ?= $(shell find . -path ./vendor -prune -o -name '*.go' -print)

GOPROXY ?= https://proxy.golang.org
export GOPROXY
Expand All @@ -456,8 +470,8 @@ GIT_COMMIT ?= $(if $(shell git status --porcelain --untracked-files=no),${COMMI
VPREFIX := github.com/qclaogui/codelab-monitoring/pkg/version

GO_LDFLAGS := -X $(VPREFIX).Version=$(VERSION) \
-X $(VPREFIX).GitCommit=$(GIT_COMMIT) \
-X $(VPREFIX).BuildDate=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
-X $(VPREFIX).gitCommit=$(GIT_COMMIT) \
-X $(VPREFIX).buildDate=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")

DEFAULT_FLAGS := $(GO_FLAGS)

Expand Down
4 changes: 2 additions & 2 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ func EmbedFsToGenDirectory() error {

info := hdr.FileInfo()
if info.IsDir() {
if err = os.MkdirAll(target, 0777); err != nil {
if err = os.MkdirAll(target, 0o777); err != nil {
return err
}
continue
}

w, openErr := os.OpenFile(target, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666|info.Mode()&0777)
w, openErr := os.OpenFile(target, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0o666|info.Mode()&0o777)
if openErr != nil {
return openErr
}
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc h1:GN2Lv3MGO7AS6PrRoT6yV5+wkrOpcszoIsO4+4ds248=
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc/go.mod h1:+JKpmjMGhpgPL+rXZ5nsZieVzvarn86asRlBg4uNGnk=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand Down
10 changes: 6 additions & 4 deletions pkg/cmd/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ package all

import (
"fmt"
"github.com/qclaogui/codelab-monitoring/pkg"
"slices"
"strings"

"github.com/MakeNowJust/heredoc"
"github.com/qclaogui/codelab-monitoring/pkg"
"github.com/spf13/cobra"
)

var supportedModes = []string{"monolithic-mode"}
var mode string
var (
supportedModes = []string{"monolithic-mode"}
mode string
)

func NewCmdAll() *cobra.Command {
var allCmd = &cobra.Command{
allCmd := &cobra.Command{
Short: "Run Grafana LGTMP Stack All-in-one.",
Use: "all",
Example: heredoc.Doc(`
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import (
"github.com/qclaogui/codelab-monitoring/pkg/cmd/metrics"
"github.com/qclaogui/codelab-monitoring/pkg/cmd/profiles"
"github.com/qclaogui/codelab-monitoring/pkg/cmd/traces"

"github.com/spf13/cobra"
)

func NewCmdDelete() *cobra.Command {
var cmd = &cobra.Command{
cmd := &cobra.Command{
Use: "delete",
Short: "Clean up Grafana LGTMP stack from Kubernetes",
Example: heredoc.Doc(`
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import (
"github.com/qclaogui/codelab-monitoring/pkg/cmd/metrics"
"github.com/qclaogui/codelab-monitoring/pkg/cmd/profiles"
"github.com/qclaogui/codelab-monitoring/pkg/cmd/traces"

"github.com/spf13/cobra"
)

func NewCmdDeploy() *cobra.Command {
var cmd = &cobra.Command{
cmd := &cobra.Command{
Use: "deploy",
Short: "Provisioning Grafana LGTMP stack by Kubernetes",
Example: heredoc.Doc(`
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import (
"github.com/qclaogui/codelab-monitoring/pkg/cmd/metrics"
"github.com/qclaogui/codelab-monitoring/pkg/cmd/profiles"
"github.com/qclaogui/codelab-monitoring/pkg/cmd/traces"

"github.com/spf13/cobra"
)

func NewCmdDown() *cobra.Command {
var cmd = &cobra.Command{
cmd := &cobra.Command{
Use: "down",
Short: "Clean up Grafana LGTMP stack from Docker Compose",
Example: heredoc.Doc(`
Expand Down
10 changes: 6 additions & 4 deletions pkg/cmd/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ package logs

import (
"fmt"
"github.com/qclaogui/codelab-monitoring/pkg"
"slices"
"strings"

"github.com/MakeNowJust/heredoc"
"github.com/qclaogui/codelab-monitoring/pkg"
"github.com/spf13/cobra"
)

var supportedModes = []string{"monolithic-mode", "read-write-mode", "microservices-mode"}
var mode string
var (
supportedModes = []string{"monolithic-mode", "read-write-mode", "microservices-mode"}
mode string
)

func NewCmdLogs() *cobra.Command {
var logsCmd = &cobra.Command{
logsCmd := &cobra.Command{
Short: "Run Loki for Logs.",
Use: "logs",
Example: heredoc.Doc(`
Expand Down
10 changes: 6 additions & 4 deletions pkg/cmd/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ package metrics

import (
"fmt"
"github.com/qclaogui/codelab-monitoring/pkg"
"slices"
"strings"

"github.com/MakeNowJust/heredoc"
"github.com/qclaogui/codelab-monitoring/pkg"
"github.com/spf13/cobra"
)

var supportedModes = []string{"monolithic-mode", "read-write-mode", "microservices-mode"}
var mode string
var (
supportedModes = []string{"monolithic-mode", "read-write-mode", "microservices-mode"}
mode string
)

func NewCmdMetrics() *cobra.Command {
var metricsCmd = &cobra.Command{
metricsCmd := &cobra.Command{
Short: "Run Mimir for Metrics.",
Use: "metrics",
Example: heredoc.Doc(`
Expand Down
10 changes: 6 additions & 4 deletions pkg/cmd/profiles/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ package profiles

import (
"fmt"
"github.com/qclaogui/codelab-monitoring/pkg"
"slices"
"strings"

"github.com/MakeNowJust/heredoc"
"github.com/qclaogui/codelab-monitoring/pkg"
"github.com/spf13/cobra"
)

var supportedModes = []string{"monolithic-mode", "microservices-mode"}
var mode string
var (
supportedModes = []string{"monolithic-mode", "microservices-mode"}
mode string
)

func NewCmdProfiles() *cobra.Command {
var profilesCmd = &cobra.Command{
profilesCmd := &cobra.Command{
Short: "Run Pyroscope for Profiles.",
Use: "profiles",
Example: heredoc.Doc(`
Expand Down
10 changes: 6 additions & 4 deletions pkg/cmd/traces/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ package traces

import (
"fmt"
"github.com/qclaogui/codelab-monitoring/pkg"
"slices"
"strings"

"github.com/MakeNowJust/heredoc"
"github.com/qclaogui/codelab-monitoring/pkg"
"github.com/spf13/cobra"
)

var supportedModes = []string{"monolithic-mode", "microservices-mode"}
var mode string
var (
supportedModes = []string{"monolithic-mode", "microservices-mode"}
mode string
)

func NewCmdTraces() *cobra.Command {
var tracesCmd = &cobra.Command{
tracesCmd := &cobra.Command{
Short: "Run Tempo for Traces.",
Use: "traces",
Example: heredoc.Doc(`
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import (
"github.com/qclaogui/codelab-monitoring/pkg/cmd/metrics"
"github.com/qclaogui/codelab-monitoring/pkg/cmd/profiles"
"github.com/qclaogui/codelab-monitoring/pkg/cmd/traces"

"github.com/spf13/cobra"
)

func NewCmdUp() *cobra.Command {
var cmd = &cobra.Command{
cmd := &cobra.Command{
Use: "up",
Short: "Provisioning Grafana LGTMP stack by Docker Compose",
Example: heredoc.Doc(`
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// NewCmdVersion represents the version command
func NewCmdVersion() *cobra.Command {
var cmd = &cobra.Command{
cmd := &cobra.Command{
Use: "version",
Short: "Output the version of lgtmp",
Example: heredoc.Doc(`
Expand Down
Loading

0 comments on commit c295920

Please sign in to comment.