Skip to content

Commit

Permalink
Use goimports to enforce codebase format style check. (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
qingling128 authored May 11, 2021
1 parent 2f916fe commit 542d04d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ go:
go_import_path: github.com/GoogleCloudPlatform/ops-agent

before_install:
- go get golang.org/x/tools/cmd/goimports
- go get github.com/mattn/goveralls

script:
# Only enforce the format check on Linux to avoid the newline difference in Linux and Windows.
- if [ "$TRAVIS_OS_NAME" = "linux" ] && [ $(goimports -l .) ]; then goimports -d .; echo 'Failed the goimports format check. Please format the code using "goimports -w ."'; exit 1; fi
- go test -mod=mod ./...

after_success:
Expand Down
17 changes: 10 additions & 7 deletions confgenerator/confgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import (
"path/filepath"
"sort"
"strings"

"github.com/GoogleCloudPlatform/ops-agent/collectd"
"github.com/GoogleCloudPlatform/ops-agent/fluentbit/conf"
"github.com/GoogleCloudPlatform/ops-agent/internal/version"
"github.com/GoogleCloudPlatform/ops-agent/otel"
"github.com/shirou/gopsutil/host"
"github.com/GoogleCloudPlatform/ops-agent/internal/version"

"text/template"

yaml "gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -227,14 +229,15 @@ func defaultStackdriverOutputs() (stackdrivers []*conf.Stackdriver) {
}

var userAgentTemplate = template.Must(template.New("useragent").Parse(`{{.Prefix}}/{{.AgentVersion}} (BuildDistro={{.BuildDistro}};Platform={{.Platform}};ShortName={{.ShortName}};ShortVersion={{.ShortVersion}},gzip(gfe))`))

func getUserAgent(prefix string, hostInfo *host.InfoStat) (string, error) {
userAgent := map[string]string{
"Prefix": prefix,
"AgentVersion": version.Version,
"BuildDistro": version.BuildDistro,
"Platform": hostInfo.OS,
"ShortName": hostInfo.Platform,
"ShortVersion": hostInfo.PlatformVersion,
"Prefix": prefix,
"AgentVersion": version.Version,
"BuildDistro": version.BuildDistro,
"Platform": hostInfo.OS,
"ShortName": hostInfo.Platform,
"ShortVersion": hostInfo.PlatformVersion,
}
var userAgentBuilder strings.Builder
if err := userAgentTemplate.Execute(&userAgentBuilder, userAgent); err != nil {
Expand Down
1 change: 1 addition & 0 deletions confgenerator/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path/filepath"

"github.com/shirou/gopsutil/host"
)

Expand Down
12 changes: 6 additions & 6 deletions fluentbit/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ func (w WindowsEventlog) renderConfig() (string, error) {

// A Stackdriver represents the configurable data for fluentBit's stackdriver output plugin.
type Stackdriver struct {
Match string
Match string
UserAgent string
}

Expand All @@ -754,11 +754,11 @@ func (s Stackdriver) renderConfig() (string, error) {
}
}
if s.UserAgent == "" {
return "", emptyFieldErr{
plugin: "stackdriver",
field: "stackdriver_agent",
}
}
return "", emptyFieldErr{
plugin: "stackdriver",
field: "stackdriver_agent",
}
}

var renderedStackdriverConfig strings.Builder
if err := stackdriverTemplate.Execute(&renderedStackdriverConfig, s); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion fluentbit/conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func TestWinlogErrors(t *testing.T) {

func TestStackdriver(t *testing.T) {
s := Stackdriver{
Match: "test_match",
Match: "test_match",
UserAgent: "user_agent",
}
want := `[OUTPUT]
Expand Down
1 change: 0 additions & 1 deletion internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ var Version = "latest"

// BuildDistro variable will be replaced at link time after `make` has been run.
var BuildDistro = "build_distro"

0 comments on commit 542d04d

Please sign in to comment.