Skip to content

Commit 8c4a282

Browse files
committed
Fix golint warnings for builder
Addresses: moby#14756 Signed-off-by: Qiang Huang <[email protected]>
1 parent c986f85 commit 8c4a282

File tree

13 files changed

+131
-107
lines changed

13 files changed

+131
-107
lines changed

api/server/server.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ func (s *Server) postCommit(version version.Version, w http.ResponseWriter, r *h
688688
return err
689689
}
690690

691-
commitCfg := &builder.BuilderCommitConfig{
691+
commitCfg := &builder.CommitConfig{
692692
Pause: pause,
693693
Repo: r.Form.Get("repo"),
694694
Tag: r.Form.Get("tag"),
@@ -1276,11 +1276,11 @@ func (s *Server) postBuild(version version.Version, w http.ResponseWriter, r *ht
12761276
buildConfig.AuthConfigs = authConfigs
12771277
buildConfig.MemorySwap = int64ValueOrZero(r, "memswap")
12781278
buildConfig.Memory = int64ValueOrZero(r, "memory")
1279-
buildConfig.CpuShares = int64ValueOrZero(r, "cpushares")
1280-
buildConfig.CpuPeriod = int64ValueOrZero(r, "cpuperiod")
1281-
buildConfig.CpuQuota = int64ValueOrZero(r, "cpuquota")
1282-
buildConfig.CpuSetCpus = r.FormValue("cpusetcpus")
1283-
buildConfig.CpuSetMems = r.FormValue("cpusetmems")
1279+
buildConfig.CPUShares = int64ValueOrZero(r, "cpushares")
1280+
buildConfig.CPUPeriod = int64ValueOrZero(r, "cpuperiod")
1281+
buildConfig.CPUQuota = int64ValueOrZero(r, "cpuquota")
1282+
buildConfig.CPUSetCpus = r.FormValue("cpusetcpus")
1283+
buildConfig.CPUSetMems = r.FormValue("cpusetmems")
12841284
buildConfig.CgroupParent = r.FormValue("cgroupparent")
12851285

12861286
// Job cancellation. Note: not all job types support this.

builder/bflag.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,40 @@ import (
55
"strings"
66
)
77

8+
// FlagType is the type of the build flag
89
type FlagType int
910

1011
const (
1112
boolType FlagType = iota
1213
stringType
1314
)
1415

15-
type BuilderFlags struct {
16+
// BFlags contains all flags information for the builder
17+
type BFlags struct {
1618
Args []string // actual flags/args from cmd line
1719
flags map[string]*Flag
1820
used map[string]*Flag
1921
Err error
2022
}
2123

24+
// Flag contains all information for a flag
2225
type Flag struct {
23-
bf *BuilderFlags
26+
bf *BFlags
2427
name string
2528
flagType FlagType
2629
Value string
2730
}
2831

29-
func NewBuilderFlags() *BuilderFlags {
30-
return &BuilderFlags{
32+
// NewBFlags return the new BFlags struct
33+
func NewBFlags() *BFlags {
34+
return &BFlags{
3135
flags: make(map[string]*Flag),
3236
used: make(map[string]*Flag),
3337
}
3438
}
3539

36-
func (bf *BuilderFlags) AddBool(name string, def bool) *Flag {
40+
// AddBool adds a bool flag to BFlags
41+
func (bf *BFlags) AddBool(name string, def bool) *Flag {
3742
flag := bf.addFlag(name, boolType)
3843
if flag == nil {
3944
return nil
@@ -46,7 +51,8 @@ func (bf *BuilderFlags) AddBool(name string, def bool) *Flag {
4651
return flag
4752
}
4853

49-
func (bf *BuilderFlags) AddString(name string, def string) *Flag {
54+
// AddString adds a string flag to BFlags
55+
func (bf *BFlags) AddString(name string, def string) *Flag {
5056
flag := bf.addFlag(name, stringType)
5157
if flag == nil {
5258
return nil
@@ -55,7 +61,7 @@ func (bf *BuilderFlags) AddString(name string, def string) *Flag {
5561
return flag
5662
}
5763

58-
func (bf *BuilderFlags) addFlag(name string, flagType FlagType) *Flag {
64+
func (bf *BFlags) addFlag(name string, flagType FlagType) *Flag {
5965
if _, ok := bf.flags[name]; ok {
6066
bf.Err = fmt.Errorf("Duplicate flag defined: %s", name)
6167
return nil
@@ -71,13 +77,15 @@ func (bf *BuilderFlags) addFlag(name string, flagType FlagType) *Flag {
7177
return newFlag
7278
}
7379

80+
// IsUsed checks if the flag is used
7481
func (fl *Flag) IsUsed() bool {
7582
if _, ok := fl.bf.used[fl.name]; ok {
7683
return true
7784
}
7885
return false
7986
}
8087

88+
// IsTrue checks if a bool flag is true
8189
func (fl *Flag) IsTrue() bool {
8290
if fl.flagType != boolType {
8391
// Should never get here
@@ -86,7 +94,8 @@ func (fl *Flag) IsTrue() bool {
8694
return fl.Value == "true"
8795
}
8896

89-
func (bf *BuilderFlags) Parse() error {
97+
// Parse parses and checks if the BFlags is valid
98+
func (bf *BFlags) Parse() error {
9099
// If there was an error while defining the possible flags
91100
// go ahead and bubble it back up here since we didn't do it
92101
// earlier in the processing

builder/bflag_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ func TestBuilderFlags(t *testing.T) {
1010

1111
// ---
1212

13-
bf := NewBuilderFlags()
13+
bf := NewBFlags()
1414
bf.Args = []string{}
1515
if err := bf.Parse(); err != nil {
1616
t.Fatalf("Test1 of %q was supposed to work: %s", bf.Args, err)
1717
}
1818

1919
// ---
2020

21-
bf = NewBuilderFlags()
21+
bf = NewBFlags()
2222
bf.Args = []string{"--"}
2323
if err := bf.Parse(); err != nil {
2424
t.Fatalf("Test2 of %q was supposed to work: %s", bf.Args, err)
2525
}
2626

2727
// ---
2828

29-
bf = NewBuilderFlags()
29+
bf = NewBFlags()
3030
flStr1 := bf.AddString("str1", "")
3131
flBool1 := bf.AddBool("bool1", false)
3232
bf.Args = []string{}
@@ -43,7 +43,7 @@ func TestBuilderFlags(t *testing.T) {
4343

4444
// ---
4545

46-
bf = NewBuilderFlags()
46+
bf = NewBFlags()
4747
flStr1 = bf.AddString("str1", "HI")
4848
flBool1 = bf.AddBool("bool1", false)
4949
bf.Args = []string{}
@@ -67,7 +67,7 @@ func TestBuilderFlags(t *testing.T) {
6767

6868
// ---
6969

70-
bf = NewBuilderFlags()
70+
bf = NewBFlags()
7171
flStr1 = bf.AddString("str1", "HI")
7272
bf.Args = []string{"--str1"}
7373

@@ -77,7 +77,7 @@ func TestBuilderFlags(t *testing.T) {
7777

7878
// ---
7979

80-
bf = NewBuilderFlags()
80+
bf = NewBFlags()
8181
flStr1 = bf.AddString("str1", "HI")
8282
bf.Args = []string{"--str1="}
8383

@@ -92,7 +92,7 @@ func TestBuilderFlags(t *testing.T) {
9292

9393
// ---
9494

95-
bf = NewBuilderFlags()
95+
bf = NewBFlags()
9696
flStr1 = bf.AddString("str1", "HI")
9797
bf.Args = []string{"--str1=BYE"}
9898

@@ -107,7 +107,7 @@ func TestBuilderFlags(t *testing.T) {
107107

108108
// ---
109109

110-
bf = NewBuilderFlags()
110+
bf = NewBFlags()
111111
flBool1 = bf.AddBool("bool1", false)
112112
bf.Args = []string{"--bool1"}
113113

@@ -121,7 +121,7 @@ func TestBuilderFlags(t *testing.T) {
121121

122122
// ---
123123

124-
bf = NewBuilderFlags()
124+
bf = NewBFlags()
125125
flBool1 = bf.AddBool("bool1", false)
126126
bf.Args = []string{"--bool1=true"}
127127

@@ -135,7 +135,7 @@ func TestBuilderFlags(t *testing.T) {
135135

136136
// ---
137137

138-
bf = NewBuilderFlags()
138+
bf = NewBFlags()
139139
flBool1 = bf.AddBool("bool1", false)
140140
bf.Args = []string{"--bool1=false"}
141141

@@ -149,7 +149,7 @@ func TestBuilderFlags(t *testing.T) {
149149

150150
// ---
151151

152-
bf = NewBuilderFlags()
152+
bf = NewBFlags()
153153
flBool1 = bf.AddBool("bool1", false)
154154
bf.Args = []string{"--bool1=false1"}
155155

@@ -159,7 +159,7 @@ func TestBuilderFlags(t *testing.T) {
159159

160160
// ---
161161

162-
bf = NewBuilderFlags()
162+
bf = NewBFlags()
163163
flBool1 = bf.AddBool("bool1", false)
164164
bf.Args = []string{"--bool2"}
165165

@@ -169,7 +169,7 @@ func TestBuilderFlags(t *testing.T) {
169169

170170
// ---
171171

172-
bf = NewBuilderFlags()
172+
bf = NewBFlags()
173173
flStr1 = bf.AddString("str1", "HI")
174174
flBool1 = bf.AddBool("bool1", false)
175175
bf.Args = []string{"--bool1", "--str1=BYE"}

builder/command/command.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// This package contains the set of Dockerfile commands.
1+
// Package command contains the set of Dockerfile commands.
22
package command
33

4+
// Define constants for the command strings
45
const (
56
Env = "env"
67
Label = "label"

0 commit comments

Comments
 (0)