Skip to content

Commit d4f14e9

Browse files
authored
Remove go-utils/v1 dependency (#165)
1 parent b3416e3 commit d4f14e9

File tree

6 files changed

+177
-19
lines changed

6 files changed

+177
-19
lines changed

analytics/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"net/http"
77
"time"
88

9-
"github.com/bitrise-io/go-utils/retry"
109
"github.com/bitrise-io/go-utils/v2/log"
10+
"github.com/bitrise-io/go-utils/v2/retryhttp"
1111
)
1212

1313
const trackEndpoint = "https://bitrise-step-analytics.herokuapp.com/track"
@@ -26,7 +26,7 @@ type client struct {
2626

2727
// NewDefaultClient ...
2828
func NewDefaultClient(logger log.Logger, timeout time.Duration) Client {
29-
httpClient := retry.NewHTTPClient().StandardClient()
29+
httpClient := retryhttp.NewClient(logger).StandardClient()
3030
httpClient.Timeout = timeout
3131
return NewClient(httpClient, trackEndpoint, logger, timeout)
3232
}

go.mod

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
module github.com/bitrise-io/go-utils/v2
22

3-
go 1.16
3+
go 1.17
44

55
require (
6-
github.com/bitrise-io/go-utils v1.0.1
76
github.com/gofrs/uuid v4.2.0+incompatible
87
github.com/hashicorp/go-retryablehttp v0.7.1
98
github.com/mitchellh/mapstructure v1.4.3
109
github.com/stretchr/testify v1.7.0
1110
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e
1211
)
12+
13+
require (
14+
github.com/davecgh/go-spew v1.1.1 // indirect
15+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
16+
github.com/pmezard/go-difflib v1.0.0 // indirect
17+
github.com/stretchr/objx v0.3.0 // indirect
18+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
19+
)

go.sum

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
github.com/bitrise-io/go-utils v1.0.1 h1:e7mepVBkVN1DXRPESNXb0djEw6bxB6B93p/Q74zzcvk=
2-
github.com/bitrise-io/go-utils v1.0.1/go.mod h1:ZY1DI+fEpZuFpO9szgDeICM4QbqoWVt0RSY3tRI1heY=
31
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
42
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
53
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -10,7 +8,6 @@ github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9n
108
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
119
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
1210
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
13-
github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
1411
github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ=
1512
github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
1613
github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
@@ -24,21 +21,10 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
2421
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
2522
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
2623
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
27-
golang.org/x/crypto v0.0.0-20211202192323-5770296d904e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
28-
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
29-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
30-
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
31-
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
32-
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3324
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e h1:NHvCuwuS43lGnYhten69ZWqi2QOj/CiDNcKbVqwVoew=
3425
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
35-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
36-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
37-
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
38-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
3926
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
4027
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
41-
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
4228
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4329
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
4430
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

log/colorstring/colorstring.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package colorstring
2+
3+
// ANSI color escape sequences
4+
5+
import (
6+
"fmt"
7+
)
8+
9+
// Color ...
10+
type Color string
11+
12+
const (
13+
blackColor Color = "\x1b[30;1m"
14+
redColor Color = "\x1b[31;1m"
15+
greenColor Color = "\x1b[32;1m"
16+
yellowColor Color = "\x1b[33;1m"
17+
blueColor Color = "\x1b[34;1m"
18+
magentaColor Color = "\x1b[35;1m"
19+
cyanColor Color = "\x1b[36;1m"
20+
resetColor Color = "\x1b[0m"
21+
)
22+
23+
// ColorFunc ...
24+
type ColorFunc func(a ...interface{}) string
25+
26+
func addColor(color Color, msg string) string {
27+
return string(color) + msg + string(resetColor)
28+
}
29+
30+
// NoColor ...
31+
func NoColor(a ...interface{}) string {
32+
return fmt.Sprint(a...)
33+
}
34+
35+
// Black ...
36+
func Black(a ...interface{}) string {
37+
return addColor(blackColor, fmt.Sprint(a...))
38+
}
39+
40+
// Red ...
41+
func Red(a ...interface{}) string {
42+
return addColor(redColor, fmt.Sprint(a...))
43+
}
44+
45+
// Green ...
46+
func Green(a ...interface{}) string {
47+
return addColor(greenColor, fmt.Sprint(a...))
48+
}
49+
50+
// Yellow ...
51+
func Yellow(a ...interface{}) string {
52+
return addColor(yellowColor, fmt.Sprint(a...))
53+
}
54+
55+
// Blue ...
56+
func Blue(a ...interface{}) string {
57+
return addColor(blueColor, fmt.Sprint(a...))
58+
}
59+
60+
// Magenta ...
61+
func Magenta(a ...interface{}) string {
62+
return addColor(magentaColor, fmt.Sprint(a...))
63+
}
64+
65+
// Cyan ...
66+
func Cyan(a ...interface{}) string {
67+
return addColor(cyanColor, fmt.Sprint(a...))
68+
}
69+
70+
// ColorfFunc ...
71+
type ColorfFunc func(format string, a ...interface{}) string
72+
73+
// NoColorf ...
74+
func NoColorf(format string, a ...interface{}) string {
75+
return NoColor(fmt.Sprintf(format, a...))
76+
}
77+
78+
// Blackf ...
79+
func Blackf(format string, a ...interface{}) string {
80+
return Black(fmt.Sprintf(format, a...))
81+
}
82+
83+
// Redf ...
84+
func Redf(format string, a ...interface{}) string {
85+
return Red(fmt.Sprintf(format, a...))
86+
}
87+
88+
// Greenf ...
89+
func Greenf(format string, a ...interface{}) string {
90+
return Green(fmt.Sprintf(format, a...))
91+
}
92+
93+
// Yellowf ...
94+
func Yellowf(format string, a ...interface{}) string {
95+
return Yellow(fmt.Sprintf(format, a...))
96+
}
97+
98+
// Bluef ...
99+
func Bluef(format string, a ...interface{}) string {
100+
return Blue(fmt.Sprintf(format, a...))
101+
}
102+
103+
// Magentaf ...
104+
func Magentaf(format string, a ...interface{}) string {
105+
return Magenta(fmt.Sprintf(format, a...))
106+
}
107+
108+
// Cyanf ...
109+
func Cyanf(format string, a ...interface{}) string {
110+
return Cyan(fmt.Sprintf(format, a...))
111+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package colorstring
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestAddColor(t *testing.T) {
11+
/*
12+
blackColor Color = "\x1b[30;1m"
13+
resetColor Color = "\x1b[0m"
14+
*/
15+
16+
t.Log("colored_string = color + string + reset_color")
17+
{
18+
desiredColored := "\x1b[30;1m" + "test" + "\x1b[0m"
19+
colored := addColor(blackColor, "test")
20+
require.Equal(t, desiredColored, colored)
21+
}
22+
}
23+
24+
func TestBlack(t *testing.T) {
25+
t.Log("Simple string can be blacked")
26+
{
27+
desiredColored := "\x1b[30;1m" + "test" + "\x1b[0m"
28+
colored := Black("test")
29+
require.Equal(t, desiredColored, colored)
30+
}
31+
32+
t.Log("Multiple strings can be blacked")
33+
{
34+
desiredColored := "\x1b[30;1m" + "Hello Bitrise !" + "\x1b[0m"
35+
colored := Black("Hello ", "Bitrise ", "!")
36+
require.Equal(t, desiredColored, colored)
37+
}
38+
}
39+
40+
func TestBlackf(t *testing.T) {
41+
t.Log("Simple format can be blacked")
42+
{
43+
desiredColored := "\x1b[30;1m" + fmt.Sprintf("Hello %s", "bitrise") + "\x1b[0m"
44+
colored := Blackf("Hello %s", "bitrise")
45+
require.Equal(t, desiredColored, colored)
46+
}
47+
48+
t.Log("Complex format can be blacked")
49+
{
50+
desiredColored := "\x1b[30;1m" + fmt.Sprintf("Hello %s %s", "bitrise", "!") + "\x1b[0m"
51+
colored := Blackf("Hello %s %s", "bitrise", "!")
52+
require.Equal(t, desiredColored, colored)
53+
}
54+
}

log/severity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package log
22

3-
import "github.com/bitrise-io/go-utils/colorstring"
3+
import "github.com/bitrise-io/go-utils/v2/log/colorstring"
44

55
// Severity ...
66
type Severity uint8

0 commit comments

Comments
 (0)