File tree Expand file tree Collapse file tree 5 files changed +64
-2
lines changed Expand file tree Collapse file tree 5 files changed +64
-2
lines changed Original file line number Diff line number Diff line change 5
5
.PHONY : lint
6
6
lint :
7
7
go vet ./...
8
+
9
+ .PHONY : format
10
+ format :
11
+ go fmt ./...
Original file line number Diff line number Diff line change 1
1
package flareio
2
+
3
+ type ApiClient struct {
4
+ tenantId int
5
+ apiKey string
6
+ }
7
+
8
+ type ApiClientOption func (* ApiClient )
9
+
10
+ func WithTenantId (tenantId int ) ApiClientOption {
11
+ return func (client * ApiClient ) {
12
+ client .tenantId = tenantId
13
+ }
14
+ }
15
+
16
+ func NewClient (
17
+ apiKey string ,
18
+ optionFns ... ApiClientOption ,
19
+ ) * ApiClient {
20
+ c := & ApiClient {
21
+ apiKey : apiKey ,
22
+ }
23
+ for _ , optionFn := range optionFns {
24
+ optionFn (c )
25
+ }
26
+ return c
27
+ }
Original file line number Diff line number Diff line change 1
1
package flareio
2
2
3
- import "testing"
3
+ import (
4
+ "testing"
4
5
5
- func TestExample (t * testing.T ) {
6
+ "github.com/stretchr/testify/assert"
7
+ )
8
+
9
+ func TestCreateClientWithApiKey (t * testing.T ) {
10
+ c := NewClient ("test-key" )
11
+ assert .Equal (t , "test-key" , c .apiKey )
12
+ assert .Equal (t , 0 , c .tenantId )
13
+ }
14
+
15
+ func TestCreateClientWithTenantId (t * testing.T ) {
16
+ c := NewClient (
17
+ "test-key" ,
18
+ WithTenantId (42 ),
19
+ )
20
+ assert .Equal (t , "test-key" , c .apiKey )
21
+ assert .Equal (t , 42 , c .tenantId )
6
22
}
Original file line number Diff line number Diff line change 1
1
module github.com/Flared/go-flareio
2
2
3
3
go 1.23.1
4
+
5
+ require (
6
+ github.com/davecgh/go-spew v1.1.1 // indirect
7
+ github.com/pmezard/go-difflib v1.0.0 // indirect
8
+ github.com/stretchr/testify v1.9.0 // indirect
9
+ gopkg.in/yaml.v3 v3.0.1 // indirect
10
+ )
Original file line number Diff line number Diff line change
1
+ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c =
2
+ github.com/davecgh/go-spew v1.1.1 /go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38 =
3
+ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM =
4
+ github.com/pmezard/go-difflib v1.0.0 /go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4 =
5
+ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg =
6
+ github.com/stretchr/testify v1.9.0 /go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY =
7
+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 /go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0 =
8
+ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA =
9
+ gopkg.in/yaml.v3 v3.0.1 /go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM =
You can’t perform that action at this time.
0 commit comments