Skip to content

Commit e2983e1

Browse files
committed
TX-16896: upgrade go to 1.26 and gofmt
bump go to 1.26 go fix ./.. for depracated ioutil gofmt -w . for modern syntax go mod tidy to make transitive depdndencies explicit
1 parent e7feea3 commit e2983e1

38 files changed

+439
-425
lines changed

build/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=${BUILDPLATFORM} golang:1.16.0-alpine AS build
1+
FROM --platform=${BUILDPLATFORM} golang:1.26.0-alpine AS build
22
RUN apk update
33
RUN apk add --no-cache git
44

build/Dockerfile-bin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=${BUILDPLATFORM} golang:1.16.0-alpine AS build
1+
FROM --platform=${BUILDPLATFORM} golang:1.26.0-alpine AS build
22
RUN apk update
33
RUN apk add --no-cache git
44

cmd/tx/main.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,7 @@ func Main() {
331331
languages = strings.Split(c.String("languages"), ",")
332332
}
333333

334-
workers := c.Int("workers")
335-
if workers > 20 {
336-
workers = 20
337-
}
334+
workers := min(c.Int("workers"), 20)
338335

339336
args := txlib.PushCommandArguments{
340337
Source: c.Bool("source"),
@@ -541,10 +538,7 @@ func Main() {
541538
resourceIds = append(resourceIds, extraResourceIds...)
542539
}
543540

544-
workers := c.Int("workers")
545-
if workers > 20 {
546-
workers = 20
547-
}
541+
workers := min(c.Int("workers"), 20)
548542

549543
arguments := txlib.PullCommandArguments{
550544
ContentEncoding: c.String("content_encoding"),

go.mod

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/transifex/cli
22

3-
go 1.16
3+
go 1.26
44

55
require (
66
github.com/blang/semver v3.5.1+incompatible
@@ -11,10 +11,45 @@ require (
1111
github.com/manifoldco/promptui v0.8.0
1212
github.com/mattn/go-isatty v0.0.14
1313
github.com/rhysd/go-github-selfupdate v1.2.3
14-
github.com/smartystreets/goconvey v1.6.4 // indirect
15-
github.com/stretchr/testify v1.7.0 // indirect
14+
github.com/stretchr/testify v1.7.0
1615
github.com/urfave/cli/v2 v2.3.0
17-
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
16+
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d
1817
gopkg.in/ini.v1 v1.62.0
18+
)
19+
20+
require (
21+
github.com/Microsoft/go-winio v0.4.16 // indirect
22+
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
23+
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
24+
github.com/davecgh/go-spew v1.1.1 // indirect
25+
github.com/emirpasic/gods v1.12.0 // indirect
26+
github.com/go-git/gcfg v1.5.0 // indirect
27+
github.com/go-git/go-billy/v5 v5.1.0 // indirect
28+
github.com/golang/protobuf v1.3.2 // indirect
29+
github.com/google/go-github/v30 v30.1.0 // indirect
30+
github.com/google/go-querystring v1.0.0 // indirect
31+
github.com/gosimple/unidecode v1.0.1 // indirect
32+
github.com/imdario/mergo v0.3.12 // indirect
33+
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect
34+
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
35+
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a // indirect
36+
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
37+
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a // indirect
38+
github.com/mattn/go-colorable v0.1.9 // indirect
39+
github.com/mitchellh/go-homedir v1.1.0 // indirect
40+
github.com/pmezard/go-difflib v1.0.0 // indirect
41+
github.com/russross/blackfriday/v2 v2.0.1 // indirect
42+
github.com/sergi/go-diff v1.1.0 // indirect
43+
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
44+
github.com/smartystreets/goconvey v1.6.4 // indirect
45+
github.com/tcnksm/go-gitconfig v0.1.2 // indirect
46+
github.com/ulikunitz/xz v0.5.9 // indirect
47+
github.com/xanzy/ssh-agent v0.3.0 // indirect
48+
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
49+
golang.org/x/net v0.0.0-20210326060303-6b1517762897 // indirect
50+
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288 // indirect
51+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
52+
google.golang.org/appengine v1.3.0 // indirect
53+
gopkg.in/warnings.v0 v0.1.2 // indirect
1954
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
2055
)

internal/txlib/add.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"slices"
89
"strings"
910

1011
"github.com/fatih/color"
@@ -51,7 +52,7 @@ func validateFileFilter(input string) error {
5152
return errors.New("you need to add an extension to your file")
5253
}
5354
input = normaliseFileFilter(input)
54-
for _, part := range strings.Split(input, string(os.PathSeparator)) {
55+
for part := range strings.SplitSeq(input, string(os.PathSeparator)) {
5556
if strings.Count(part, "<lang>") > 1 {
5657
return errors.New(
5758
"<lang> cannot appear more than once in the same part of the path",
@@ -94,13 +95,7 @@ func validateNotEmpty(input string) error {
9495
}
9596

9697
func i18nFormatExists(list []string, ext string) bool {
97-
for _, value := range list {
98-
if value == ext {
99-
return true
100-
}
101-
102-
}
103-
return false
98+
return slices.Contains(list, ext)
10499
}
105100

106101
func getSelectTemplate(str string) *promptui.SelectTemplates {

internal/txlib/add_remote_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package txlib
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"net/url"
77
"os"
88
"reflect"
@@ -147,7 +147,7 @@ func TestAddRemoteInvalidFileFormat(t *testing.T) {
147147
// Restore stdout
148148
w.Close()
149149
os.Stdout = oldStdout
150-
out, _ := ioutil.ReadAll(r)
150+
out, _ := io.ReadAll(r)
151151
r.Close()
152152

153153
testSimpleGet(t, mockData, projectUrl)

internal/txlib/config/local.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func loadLocalConfigFromBytes(data []byte) (*LocalConfig, error) {
8585
}
8686
languageMappings := mainSection.Key("lang_map").String()
8787
if languageMappings != "" {
88-
for _, mapping := range strings.Split(languageMappings, ",") {
88+
for mapping := range strings.SplitSeq(languageMappings, ",") {
8989
err := fmt.Errorf("invalid language mapping '%s'", mapping)
9090

9191
split := strings.Split(mapping, ":")
@@ -170,7 +170,7 @@ func loadLocalConfigFromBytes(data []byte) (*LocalConfig, error) {
170170

171171
languageMappings := section.Key("lang_map").String()
172172
if languageMappings != "" {
173-
for _, mapping := range strings.Split(languageMappings, ",") {
173+
for mapping := range strings.SplitSeq(languageMappings, ",") {
174174
err := fmt.Errorf("invalid language mapping %s", mapping)
175175
split := strings.Split(mapping, ":")
176176
if len(split) != 2 {

internal/txlib/config/main.go

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,32 @@ Slightly object-oriented tx configuration package.
44
55
Usage:
66
7-
import "github.com/transifex/cli/internal/txlib/config"
7+
import "github.com/transifex/cli/internal/txlib/config"
88
9-
cfg, err := config.Load() // Loads based on current directory
10-
if err != nil { ... }
9+
cfg, err := config.Load() // Loads based on current directory
10+
if err != nil { ... }
1111
12-
// Lets add a resource
13-
cfg.AddResource(config.Resource{
14-
OrganizationSlug: "my_org",
15-
ProjectSlug: "my_project",
16-
ResourceSlug: "my_resource",
17-
FileFilter: "locale/<lang>.po",
18-
SourceFile: "locale/en.po",
19-
SourceLanguage: "en",
20-
Type: "PO",
21-
})
12+
// Lets add a resource
13+
cfg.AddResource(config.Resource{
14+
OrganizationSlug: "my_org",
15+
ProjectSlug: "my_project",
16+
ResourceSlug: "my_resource",
17+
FileFilter: "locale/<lang>.po",
18+
SourceFile: "locale/en.po",
19+
SourceLanguage: "en",
20+
Type: "PO",
21+
})
2222
23-
cfg.Save() // Saves changes to disk
23+
cfg.Save() // Saves changes to disk
2424
25-
resource := cfg.FindResource("my_org.my_project")
25+
resource := cfg.FindResource("my_org.my_project")
2626
27-
file, err := os.Open(resource.SourceFile)
28-
if err != nil { ... }
29-
defer file.Close()
30-
31-
resource.LanguageMappings["en_US"] = "en-us"
32-
cfg.Save()
27+
file, err := os.Open(resource.SourceFile)
28+
if err != nil { ... }
29+
defer file.Close()
3330
31+
resource.LanguageMappings["en_US"] = "en-us"
32+
cfg.Save()
3433
*/
3534
package config
3635

@@ -99,10 +98,10 @@ Return the URL that will be used based on the configuration.
9998
10099
The local configuration has a 'host' field in its 'main' section. That host
101100
points to a section in the root configuration. We return the rest_hostname of
102-
that section. The fallback value is `https://rest.api.transifex.com` */
101+
that section. The fallback value is `https://rest.api.transifex.com`
102+
*/
103103
func (cfg *Config) GetActiveHost() *Host {
104-
if cfg.Root.Hosts == nil || len(cfg.Root.Hosts) == 0 ||
105-
cfg.Local == nil {
104+
if len(cfg.Root.Hosts) == 0 || cfg.Local == nil {
106105
return nil
107106
}
108107
activeHostName := cfg.Local.Host
@@ -117,7 +116,8 @@ func (cfg *Config) GetActiveHost() *Host {
117116

118117
/*
119118
Save
120-
Save changes to disk */
119+
Save changes to disk
120+
*/
121121
func (cfg *Config) Save() error {
122122
if cfg.Root != nil {
123123
var oldRootConfig *RootConfig
@@ -193,7 +193,8 @@ func (cfg *Config) FindHost(hostname string) *Host {
193193
/*
194194
FindResource
195195
Return a Resource reference that matches the argument. The format of the
196-
argument is "<project_slug>.<resource_slug>" */
196+
argument is "<project_slug>.<resource_slug>"
197+
*/
197198
func (cfg *Config) FindResource(id string) *Resource {
198199
parts := strings.Split(id, ".")
199200
if len(parts) != 2 {

internal/txlib/credentials.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,62 +12,62 @@ GetHostAndToken
1212
Function for getting the *final* API server hostname and token from a
1313
combination of environment variables, flags, config files and/or user input.
1414
15-
- 'cfg' is a 'config.Config' object that has already been loaded either based
16-
on the default configuration paths or ones that have been supplied by the
17-
user.
15+
- 'cfg' is a 'config.Config' object that has already been loaded either based
16+
on the default configuration paths or ones that have been supplied by the
17+
user.
1818
19-
- 'hostname' is an override for the hostname to used that the user has maybe
20-
provided either as a flag or an environment variable.
19+
- 'hostname' is an override for the hostname to used that the user has maybe
20+
provided either as a flag or an environment variable.
2121
22-
- 'token' is an override for the API token to be used that the user has maybe
23-
provided either as a flag or an environment variable.
22+
- 'token' is an override for the API token to be used that the user has maybe
23+
provided either as a flag or an environment variable.
2424
2525
The logic for retrieving the final hostname and token is:
2626
27-
1. If the hostname flag/env variable is provided, use it as a section *key* in
28-
the root configuration file. For example, if the user provides 'aaa' and the
29-
root configuration file looks like this:
27+
1. If the hostname flag/env variable is provided, use it as a section *key* in
28+
the root configuration file. For example, if the user provides 'aaa' and the
29+
root configuration file looks like this:
3030
31-
[aaa]
32-
rest_hostname = bbb
31+
[aaa]
32+
rest_hostname = bbb
3333
34-
Then, the returned hostname will be 'bbb'.
34+
Then, the returned hostname will be 'bbb'.
3535
36-
If a matching host isn't found, then the returned hostname will be the
37-
provided value.
36+
If a matching host isn't found, then the returned hostname will be the
37+
provided value.
3838
39-
2. If the user didn't provide a hostname, try to find the "active host" based
40-
on both the local and root configuration. For example, if the local
41-
configuration looks like this:
39+
2. If the user didn't provide a hostname, try to find the "active host" based
40+
on both the local and root configuration. For example, if the local
41+
configuration looks like this:
4242
43-
[main]
44-
host = ccc
43+
[main]
44+
host = ccc
4545
46-
And the root configuration looks like this:
46+
And the root configuration looks like this:
4747
48-
[aaa]
49-
rest_hostname = bbb
48+
[aaa]
49+
rest_hostname = bbb
5050
51-
[ccc]
52-
rest_hostname = ddd
51+
[ccc]
52+
rest_hostname = ddd
5353
54-
[eee]
55-
rest_hostname = fff
54+
[eee]
55+
rest_hostname = fff
5656
57-
Then the "active host" will be the second one and the returned hostname will
58-
be 'ddd'.
57+
Then the "active host" will be the second one and the returned hostname will
58+
be 'ddd'.
5959
60-
If an active host cannot be found, then 'https://rest.api.transifex.com'
61-
will be returned.
60+
If an active host cannot be found, then 'https://rest.api.transifex.com'
61+
will be returned.
6262
6363
3. If a token was provided by the user, simply return it.
6464
65-
4. If a token wasn't provided, retrieve the token from either the "matching
66-
host" (see step 1) or the "active host" (see step 2). If a "matching" or
67-
"active" host wasn't found during the resolution of the hostname, the
68-
program will ask the user to provide a token. After the token is provided,
69-
it will be saved in the root configuration using the appropriate section key
70-
and hostname that were already retrieved.
65+
4. If a token wasn't provided, retrieve the token from either the "matching
66+
host" (see step 1) or the "active host" (see step 2). If a "matching" or
67+
"active" host wasn't found during the resolution of the hostname, the
68+
program will ask the user to provide a token. After the token is provided,
69+
it will be saved in the root configuration using the appropriate section key
70+
and hostname that were already retrieved.
7171
*/
7272
func GetHostAndToken(
7373
cfg *config.Config, hostname, token string,

internal/txlib/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func deleteResource(
182182
if remoteStatAttributes.TranslatedStrings > 0 {
183183
msg := fmt.Sprintf("Aborting due to translations in %s",
184184
cfgResource.ResourceSlug)
185-
return fmt.Errorf(msg)
185+
return fmt.Errorf("%s", msg)
186186
}
187187
}
188188
}

0 commit comments

Comments
 (0)