Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn on golint #6546

Merged
merged 2 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ run:
- contrib
- dependencies
- test
- pkg/spec
- pkg/varlink
- pkg/varlinkapi
skip-files:
Expand All @@ -21,7 +22,6 @@ linters:
- gochecknoinits
- goconst
- gocyclo
- golint
- gosec
- lll
- maligned
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/common/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ var (
// DefaultImageVolume default value
DefaultImageVolume = "bind"
// Pull in configured json library
json = registry.JsonLibrary()
json = registry.JSONLibrary()
)
2 changes: 1 addition & 1 deletion cmd/podman/common/specgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ func makeHealthCheckFromCli(inCmd, interval string, retries uint, timeout, start
hc.Interval = intervalDuration

if retries < 1 {
return nil, errors.New("healthcheck-retries must be greater than 0.")
return nil, errors.New("healthcheck-retries must be greater than 0")
}
hc.Retries = int(retries)
timeoutDuration, err := time.ParseDuration(timeout)
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/containers/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
Short: "Attach to a running container",
Long: attachDescription,
RunE: attach,
Args: validate.IdOrLatestArgs,
Args: validate.IDOrLatestArgs,
Example: `podman attach ctrID
podman attach 1234
podman attach --no-stdin foobar`,
Expand All @@ -29,7 +29,7 @@ var (
Short: attachCommand.Short,
Long: attachCommand.Long,
RunE: attachCommand.RunE,
Args: validate.IdOrLatestArgs,
Args: validate.IDOrLatestArgs,
Example: `podman container attach ctrID
podman container attach 1234
podman container attach --no-stdin foobar`,
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/containers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var (
// Pull in configured json library
json = registry.JsonLibrary()
json = registry.JSONLibrary()

// Command: podman _container_
containerCmd = &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/containers/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var (
// podman container _diff_
diffCmd = &cobra.Command{
Use: "diff [flags] CONTAINER",
Args: validate.IdOrLatestArgs,
Args: validate.IDOrLatestArgs,
Short: "Inspect changes on container's file systems",
Long: `Displays changes on a container filesystem. The container will be compared to its parent layer.`,
RunE: diff,
Expand Down
8 changes: 4 additions & 4 deletions cmd/podman/containers/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ func init() {
}

func exec(cmd *cobra.Command, args []string) error {
var nameOrId string
var nameOrID string

if len(args) == 0 && !execOpts.Latest {
return errors.New("exec requires the name or ID of a container or the --latest flag")
}
execOpts.Cmd = args
if !execOpts.Latest {
execOpts.Cmd = args[1:]
nameOrId = args[0]
nameOrID = args[0]
}
// Validate given environment variables
execOpts.Envs = make(map[string]string)
Expand Down Expand Up @@ -122,12 +122,12 @@ func exec(cmd *cobra.Command, args []string) error {
streams.AttachOutput = true
streams.AttachError = true

exitCode, err := registry.ContainerEngine().ContainerExec(registry.GetContext(), nameOrId, execOpts, streams)
exitCode, err := registry.ContainerEngine().ContainerExec(registry.GetContext(), nameOrID, execOpts, streams)
registry.SetExitCode(exitCode)
return err
}

id, err := registry.ContainerEngine().ContainerExecDetached(registry.GetContext(), nameOrId, execOpts)
id, err := registry.ContainerEngine().ContainerExecDetached(registry.GetContext(), nameOrID, execOpts)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/containers/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func listFlagSet(flags *pflag.FlagSet) {
flags.BoolVar(&listOpts.Sync, "sync", false, "Sync container state with OCI runtime")
flags.UintVarP(&listOpts.Watch, "watch", "w", 0, "Watch the ps output on an interval in seconds")

sort := validate.ChoiceValue(&listOpts.Sort, "command", "created", "id", "image", "names", "runningfor", "size", "status")
sort := validate.Value(&listOpts.Sort, "command", "created", "id", "image", "names", "runningfor", "size", "status")
flags.Var(sort, "sort", "Sort output by: "+sort.Choices())

if registry.IsRemote() {
Expand Down
10 changes: 5 additions & 5 deletions cmd/podman/containers/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func init() {
func checkStatOptions(cmd *cobra.Command, args []string) error {
opts := 0
if statsOptions.All {
opts += 1
opts++
}
if statsOptions.Latest {
opts += 1
opts++
}
if len(args) > 0 {
opts += 1
opts++
}
if opts > 1 {
return errors.Errorf("--all, --latest and containers cannot be used together")
Expand Down Expand Up @@ -219,9 +219,9 @@ func combineHumanValues(a, b uint64) string {

func outputJSON(stats []*containerStats) error {
type jstat struct {
Id string `json:"id"`
Id string `json:"id"` //nolint
Name string `json:"name"`
CpuPercent string `json:"cpu_percent"`
CpuPercent string `json:"cpu_percent"` //nolint
MemUsage string `json:"mem_usage"`
MemPerc string `json:"mem_percent"`
NetIO string `json:"net_io"`
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/containers/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
Short: "Block on one or more containers",
Long: waitDescription,
RunE: wait,
Args: validate.IdOrLatestArgs,
Args: validate.IDOrLatestArgs,
Example: `podman wait --interval 5000 ctrID
podman wait ctrID1 ctrID2`,
}
Expand All @@ -33,7 +33,7 @@ var (
Short: waitCommand.Short,
Long: waitCommand.Long,
RunE: waitCommand.RunE,
Args: validate.IdOrLatestArgs,
Args: validate.IDOrLatestArgs,
Example: `podman container wait --interval 5000 ctrID
podman container wait ctrID1 ctrID2`,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
diffDescription = `Displays changes on a container or image's filesystem. The container or image will be compared to its parent layer.`
diffCmd = &cobra.Command{
Use: "diff [flags] {CONTAINER_ID | IMAGE_ID}",
Args: validate.IdOrLatestArgs,
Args: validate.IDOrLatestArgs,
Short: "Display the changes of object's file system",
Long: diffDescription,
TraverseChildren: true,
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/images/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

var (
// Pull in configured json library
json = registry.JsonLibrary()
json = registry.JSONLibrary()

// Command: podman _image_
imageCmd = &cobra.Command{
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/images/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ func images(cmd *cobra.Command, args []string) error {

switch {
case listFlag.quiet:
return writeId(summaries)
return writeID(summaries)
case cmd.Flag("format").Changed && listFlag.format == "json":
return writeJSON(summaries)
default:
return writeTemplate(summaries)
}
}

func writeId(imageS []*entities.ImageSummary) error {
func writeID(imageS []*entities.ImageSummary) error {
var ids = map[string]struct{}{}
for _, e := range imageS {
i := "sha256:" + e.ID
Expand Down
14 changes: 7 additions & 7 deletions cmd/podman/networks/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ var (

var (
networkListOptions entities.NetworkListOptions
headers string = "NAME\tVERSION\tPLUGINS\n"
defaultListRow string = "{{.Name}}\t{{.Version}}\t{{.Plugins}}\n"
headers = "NAME\tVERSION\tPLUGINS\n"
defaultListRow = "{{.Name}}\t{{.Version}}\t{{.Plugins}}\n"
)

func networkListFlags(flags *pflag.FlagSet) {
Expand All @@ -57,7 +57,7 @@ func init() {

func networkList(cmd *cobra.Command, args []string) error {
var (
nlprs []NetworkListPrintReports
nlprs []ListPrintReports
)

// validate the filter pattern.
Expand All @@ -83,7 +83,7 @@ func networkList(cmd *cobra.Command, args []string) error {
}

for _, r := range responses {
nlprs = append(nlprs, NetworkListPrintReports{r})
nlprs = append(nlprs, ListPrintReports{r})
}

row := networkListOptions.Format
Expand Down Expand Up @@ -125,14 +125,14 @@ func jsonOut(responses []*entities.NetworkListReport) error {
return nil
}

type NetworkListPrintReports struct {
type ListPrintReports struct {
*entities.NetworkListReport
}

func (n NetworkListPrintReports) Version() string {
func (n ListPrintReports) Version() string {
return n.CNIVersion
}

func (n NetworkListPrintReports) Plugins() string {
func (n ListPrintReports) Plugins() string {
return network.GetCNIPlugins(n.NetworkConfigList)
}
10 changes: 5 additions & 5 deletions cmd/podman/pods/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func aliasNetworkFlag(_ *pflag.FlagSet, name string) pflag.NormalizedName {

func create(cmd *cobra.Command, args []string) error {
var (
err error
podIdFile *os.File
err error
podIDFD *os.File
)
createOptions.Labels, err = parse.GetAllLabels(labelFile, labels)
if err != nil {
Expand All @@ -101,15 +101,15 @@ func create(cmd *cobra.Command, args []string) error {
}

if cmd.Flag("pod-id-file").Changed {
podIdFile, err = util.OpenExclusiveFile(podIDFile)
podIDFD, err = util.OpenExclusiveFile(podIDFile)
if err != nil && os.IsExist(err) {
return errors.Errorf("pod id file exists. Ensure another pod is not using it or delete %s", podIDFile)
}
if err != nil {
return errors.Errorf("error opening pod-id-file %s", podIDFile)
}
defer errorhandling.CloseQuiet(podIdFile)
defer errorhandling.SyncQuiet(podIdFile)
defer errorhandling.CloseQuiet(podIDFD)
defer errorhandling.SyncQuiet(podIDFD)
}

createOptions.Net, err = common.NetFlagsToNetOptions(cmd)
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/pods/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var (
// Pull in configured json library
json = registry.JsonLibrary()
json = registry.JSONLibrary()

// Command: podman _pod_
podCmd = &cobra.Command{
Expand Down
10 changes: 5 additions & 5 deletions cmd/podman/pods/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (l ListPodReporter) ID() string {
}

// Id returns the Pod id
func (l ListPodReporter) Id() string {
func (l ListPodReporter) Id() string { //nolint
if noTrunc {
return l.ListPodsReport.Id
}
Expand All @@ -209,7 +209,7 @@ func (l ListPodReporter) InfraID() string {

// InfraId returns the infra container id for the pod
// depending on trunc
func (l ListPodReporter) InfraId() string {
func (l ListPodReporter) InfraId() string { //nolint
if len(l.ListPodsReport.InfraId) == 0 {
return ""
}
Expand Down Expand Up @@ -252,7 +252,7 @@ func sortPodPsOutput(sortBy string, lprs []*entities.ListPodsReport) error {
case "created":
sort.Sort(podPsSortedCreated{lprs})
case "id":
sort.Sort(podPsSortedId{lprs})
sort.Sort(podPsSortedID{lprs})
case "name":
sort.Sort(podPsSortedName{lprs})
case "number":
Expand All @@ -276,9 +276,9 @@ func (a podPsSortedCreated) Less(i, j int) bool {
return a.lprSort[i].Created.After(a.lprSort[j].Created)
}

type podPsSortedId struct{ lprSort }
type podPsSortedID struct{ lprSort }

func (a podPsSortedId) Less(i, j int) bool { return a.lprSort[i].Id < a.lprSort[j].Id }
func (a podPsSortedID) Less(i, j int) bool { return a.lprSort[i].Id < a.lprSort[j].Id }

type podPsSortedNumber struct{ lprSort }

Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/pods/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func stats(cmd *cobra.Command, args []string) error {
}

format := statsOptions.Format
doJson := strings.ToLower(format) == formats.JSONString
doJSON := strings.ToLower(format) == formats.JSONString
header := getPodStatsHeader(format)

for {
Expand All @@ -80,7 +80,7 @@ func stats(cmd *cobra.Command, args []string) error {
return err
}
// Print the stats in the requested format and configuration.
if doJson {
if doJSON {
if err := printJSONPodStats(reports); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/registry/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var (
jsonSync sync.Once
)

// JsonLibrary provides a "encoding/json" compatible API
func JsonLibrary() jsoniter.API {
// JSONLibrary provides a "encoding/json" compatible API
func JSONLibrary() jsoniter.API {
jsonSync.Do(func() {
json = jsoniter.ConfigCompatibleWithStandardLibrary
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package report
import "github.com/containers/libpod/cmd/podman/registry"

// Pull in configured json library
var json = registry.JsonLibrary()
var json = registry.JSONLibrary()
8 changes: 4 additions & 4 deletions cmd/podman/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
}

if cmd.Flag("cpu-profile").Changed {
f, err := os.Create(cfg.CpuProfile)
f, err := os.Create(cfg.CPUProfile)
if err != nil {
return errors.Wrapf(err, "unable to create cpu profiling file %s",
cfg.CpuProfile)
cfg.CPUProfile)
}
if err := pprof.StartCPUProfile(f); err != nil {
return err
Expand Down Expand Up @@ -212,13 +212,13 @@ func rootFlags(opts *entities.PodmanConfig, flags *pflag.FlagSet) {
// V2 flags
flags.BoolVarP(&opts.Remote, "remote", "r", false, "Access remote Podman service (default false)")
// TODO Read uri from containers.config when available
flags.StringVar(&opts.Uri, "url", registry.DefaultAPIAddress(), "URL to access Podman service (CONTAINER_HOST)")
flags.StringVar(&opts.URI, "url", registry.DefaultAPIAddress(), "URL to access Podman service (CONTAINER_HOST)")
flags.StringSliceVar(&opts.Identities, "identity", []string{}, "path to SSH identity file, (CONTAINER_SSHKEY)")
flags.StringVar(&opts.PassPhrase, "passphrase", "", "passphrase for identity file (not secure, CONTAINER_PASSPHRASE), ssh-agent always supported")

cfg := opts.Config
flags.StringVar(&cfg.Engine.CgroupManager, "cgroup-manager", cfg.Engine.CgroupManager, "Cgroup manager to use (\"cgroupfs\"|\"systemd\")")
flags.StringVar(&opts.CpuProfile, "cpu-profile", "", "Path for the cpu profiling results")
flags.StringVar(&opts.CPUProfile, "cpu-profile", "", "Path for the cpu profiling results")
flags.StringVar(&opts.ConmonPath, "conmon", "", "Path of the conmon binary")
flags.StringVar(&cfg.Engine.NetworkCmdPath, "network-cmd-path", cfg.Engine.NetworkCmdPath, "Path to the command for configuring the network")
flags.StringVar(&cfg.Network.NetworkConfigDir, "cni-config-dir", cfg.Network.NetworkConfigDir, "Path of the configuration directory for CNI networks")
Expand Down
Loading