@@ -72,7 +72,7 @@ func (gb *GoBrew) getGroupedVersion(versions []string, print bool) map[string][]
72
72
sort .Sort (semver .Collection (versionsSemantic ))
73
73
74
74
// match 1.0.0 or 2.0.0
75
- reTopVersion , _ := regexp .Compile ("[0-9]+.0.0" )
75
+ reTopVersion := regexp .MustCompile ("[0-9]+.0.0" )
76
76
77
77
for _ , versionSemantic := range versionsSemantic {
78
78
maxPerLine := 0
@@ -101,7 +101,6 @@ func (gb *GoBrew) getGroupedVersion(versions []string, print bool) map[string][]
101
101
if v , err := semver .NewVersion (r ); err == nil {
102
102
groupedVersionsSemantic = append (groupedVersionsSemantic , v )
103
103
}
104
-
105
104
}
106
105
// sort semantic versions
107
106
sort .Sort (semver .Collection (groupedVersionsSemantic ))
@@ -169,7 +168,7 @@ func (gb *GoBrew) cleanDownloadsDir() {
169
168
}
170
169
171
170
func (gb * GoBrew ) judgeVersion (version string ) string {
172
- judgedVersion := "None"
171
+ judgedVersion := NoneVersion
173
172
rcBetaOk := false
174
173
reRcOrBeta := regexp .MustCompile ("beta.*|rc.*" )
175
174
@@ -194,7 +193,7 @@ func (gb *GoBrew) judgeVersion(version string) string {
194
193
modVersion := gb .getModVersion ()
195
194
// if modVersion is like 1.19, 1.20, 1.21 then appened @latest to it
196
195
if strings .Count (modVersion , "." ) == 1 {
197
- modVersion = modVersion + "@latest"
196
+ modVersion += "@latest"
198
197
}
199
198
return gb .judgeVersion (modVersion )
200
199
}
@@ -214,7 +213,7 @@ func (gb *GoBrew) judgeVersion(version string) string {
214
213
}
215
214
}
216
215
if len (versionsSemantic ) == 0 {
217
- return "None"
216
+ return NoneVersion
218
217
}
219
218
220
219
// sort semantic versions
@@ -225,7 +224,7 @@ func (gb *GoBrew) judgeVersion(version string) string {
225
224
// get last element
226
225
if version == "dev-latest" {
227
226
if len (judgedVersions ) == 0 {
228
- return "None"
227
+ return NoneVersion
229
228
}
230
229
// Filter versions containing "rc" or "beta"
231
230
filteredVersions := gb .filterVersions (judgedVersions , []string {"rc" , "beta" })
@@ -252,7 +251,7 @@ func (gb *GoBrew) judgeVersion(version string) string {
252
251
return gb .judgeVersion (latest )
253
252
}
254
253
255
- if judgedVersion != "None" {
254
+ if judgedVersion != NoneVersion {
256
255
// check if judgedVersion is in the groupedVersions
257
256
if _ , ok := groupedVersions [judgedVersion ]; ok {
258
257
// get last item in the groupedVersions excluding rc and beta
@@ -274,7 +273,7 @@ func (gb *GoBrew) judgeVersion(version string) string {
274
273
}
275
274
276
275
func (gb * GoBrew ) hasModFile () bool {
277
- modFilePath := filepath . Join ( "go.mod" )
276
+ modFilePath := "go.mod"
278
277
_ , err := os .Stat (modFilePath )
279
278
if err == nil {
280
279
return true
@@ -289,10 +288,10 @@ func (gb *GoBrew) hasModFile() bool {
289
288
// Do not use go to get the version as go list -m -f '{{.GoVersion}}'
290
289
// Because go might not be installed
291
290
func (gb * GoBrew ) getModVersion () string {
292
- modFilePath := filepath . Join ( "go.mod" )
291
+ modFilePath := "go.mod"
293
292
modFile , err := os .Open (modFilePath )
294
293
if err != nil {
295
- return "None"
294
+ return NoneVersion
296
295
}
297
296
defer func (modFile * os.File ) {
298
297
_ = modFile .Close ()
@@ -308,9 +307,9 @@ func (gb *GoBrew) getModVersion() string {
308
307
309
308
if err = scanner .Err (); err != nil {
310
309
color .Errorln (err )
311
- os .Exit (1 )
310
+ os .Exit (1 ) // nolint:gocritic
312
311
}
313
- return "None"
312
+ return NoneVersion
314
313
}
315
314
316
315
func (gb * GoBrew ) mkDirs (version string ) {
@@ -342,10 +341,10 @@ func (gb *GoBrew) filterVersions(versions []string, contains []string) []string
342
341
func (gb * GoBrew ) downloadAndExtract (version string ) {
343
342
tarName := "go" + version + "." + gb .getArch () + tarNameExt
344
343
345
- downloadURL , _ := url .JoinPath (gb .RegistryPathUrl , tarName )
344
+ downloadURL , _ := url .JoinPath (gb .RegistryPathURL , tarName )
346
345
color .Infoln ("==> [Info] Downloading from:" , downloadURL )
347
346
348
- dstDownloadDir := filepath . Join ( gb .downloadsDir )
347
+ dstDownloadDir := gb .downloadsDir
349
348
color .Infoln ("==> [Info] Downloading to:" , dstDownloadDir )
350
349
err := utils .DownloadWithProgress (downloadURL , tarName , dstDownloadDir )
351
350
@@ -385,7 +384,7 @@ func (gb *GoBrew) changeSymblinkGo(version string) {
385
384
}
386
385
387
386
func (gb * GoBrew ) getGobrewVersion () string {
388
- data := doRequest (gb .GobrewVersionsUrl )
387
+ data := doRequest (gb .GobrewVersionsURL )
389
388
if len (data ) == 0 {
390
389
return ""
391
390
}
@@ -426,7 +425,7 @@ func doRequest(url string) (data []byte) {
426
425
request , err := http .NewRequest ("GET" , url , nil )
427
426
utils .CheckError (err , "==> [Error] Cannot create request" )
428
427
429
- request .Header .Set ("User-Agent" , "gobrew" )
428
+ request .Header .Set ("User-Agent" , ProgramName )
430
429
431
430
response , err := client .Do (request )
432
431
utils .CheckError (err , "==> [Error] Cannot get response" )
@@ -438,12 +437,12 @@ func doRequest(url string) (data []byte) {
438
437
if response .StatusCode == http .StatusTooManyRequests ||
439
438
response .StatusCode == http .StatusForbidden {
440
439
color .Errorln ("==> [Error] Rate limit exhausted" )
441
- os .Exit (1 )
440
+ os .Exit (1 ) // nolint:gocritic
442
441
}
443
442
444
443
if response .StatusCode != http .StatusOK {
445
444
color .Errorln ("==> [Error] Cannot read response:" , response .Status )
446
- os .Exit (1 )
445
+ os .Exit (1 ) // nolint:gocritic
447
446
}
448
447
449
448
data , err = io .ReadAll (response .Body )
0 commit comments