Skip to content

Commit ea7f788

Browse files
committed
chore(go-client): rename package name
1 parent 37a286c commit ea7f788

10 files changed

+81
-77
lines changed

clients/go/README.md

+41-41
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,36 @@
1-
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
2-
3-
# stencilclient
1+
# stencil
42

53
```go
64
import "github.com/odpf/stencil/clients/go"
75
```
86

7+
Package stencil helps to download and refresh protobuf descriptors from remote server and provides helper functions to get protobuf schema descriptors and can parse the messages dynamically\.
8+
99
## Index
1010

1111
- [Variables](<#variables>)
12+
- [type Client](<#type-client>)
13+
- [func NewClient(url string, options Options) (Client, error)](<#func-newclient>)
14+
- [func NewMultiURLClient(urls []string, options Options) (Client, error)](<#func-newmultiurlclient>)
1215
- [type HTTPOptions](<#type-httpoptions>)
1316
- [type Options](<#type-options>)
14-
- [type StencilClient](<#type-stencilclient>)
15-
- [func NewClient(url string, options Options) (StencilClient, error)](<#func-newclient>)
16-
- [func NewMultiURLClient(urls []string, options Options) (StencilClient, error)](<#func-newmultiurlclient>)
1717

1818

1919
## Variables
2020

2121
```go
2222
var (
23+
//ErrNotFound default sentinel error if proto not found
2324
ErrNotFound = errors.New("not found")
2425
)
2526
```
2627

27-
## type [HTTPOptions](<https://github.com/odpf/stencil/blob/master/clients/go/client.go#L31-L36>)
28-
29-
HTTPOptions options for http client
30-
31-
```go
32-
type HTTPOptions struct {
33-
// Timeout specifies a time limit for requests made by this client
34-
Timeout time.Duration
35-
// Headers provide extra headers to be added in requests made by this client
36-
Headers map[string]string
37-
}
38-
```
39-
40-
## type [Options](<https://github.com/odpf/stencil/blob/master/clients/go/client.go#L39-L46>)
28+
## type [Client](<https://github.com/odpf/stencil/blob/master/clients/go/client.go#L24-L32>)
4129

42-
Options options for stencil client
30+
Client provides utility functions to parse protobuf messages at runtime\. protobuf messages can be identified by specifying fully qualified generated proto java class name\.
4331

4432
```go
45-
type Options struct {
46-
// AutoRefresh boolean to enable or disable autorefresh. Default to false
47-
AutoRefresh bool
48-
// RefreshInterval refresh interval to fetch descriptor file from server.
49-
RefreshInterval time.Duration
50-
// HTTPOptions options for http client
51-
HTTPOptions
52-
}
53-
```
54-
55-
## type [StencilClient](<https://github.com/odpf/stencil/blob/master/clients/go/client.go#L20-L28>)
56-
57-
StencilClient provides utility functions to parse protobuf messages at runtime\. protobuf messages can be identified by specifying fully qualified generated proto java class name\.
58-
59-
```go
60-
type StencilClient interface {
33+
type Client interface {
6134
// Parse parses protobuf message from wire format to protoreflect.Message given fully qualified name of proto message.
6235
// Returns ErrNotFound error if given class name is not found
6336
Parse(string, []byte) (protoreflect.ProtoMessage, error)
@@ -68,19 +41,46 @@ type StencilClient interface {
6841
}
6942
```
7043

71-
### func [NewClient](<https://github.com/odpf/stencil/blob/master/clients/go/client.go#L95>)
44+
### func [NewClient](<https://github.com/odpf/stencil/blob/master/clients/go/client.go#L99>)
7245

7346
```go
74-
func NewClient(url string, options Options) (StencilClient, error)
47+
func NewClient(url string, options Options) (Client, error)
7548
```
7649

7750
NewClient creates stencil client
7851

79-
### func [NewMultiURLClient](<https://github.com/odpf/stencil/blob/master/clients/go/client.go#L102>)
52+
### func [NewMultiURLClient](<https://github.com/odpf/stencil/blob/master/clients/go/client.go#L106>)
8053

8154
```go
82-
func NewMultiURLClient(urls []string, options Options) (StencilClient, error)
55+
func NewMultiURLClient(urls []string, options Options) (Client, error)
8356
```
8457

8558
NewMultiURLClient creates stencil client with multiple urls
8659

60+
## type [HTTPOptions](<https://github.com/odpf/stencil/blob/master/clients/go/client.go#L35-L40>)
61+
62+
HTTPOptions options for http client
63+
64+
```go
65+
type HTTPOptions struct {
66+
// Timeout specifies a time limit for requests made by this client.
67+
Timeout time.Duration
68+
// Headers provide extra headers to be added in requests made by this client
69+
Headers map[string]string
70+
}
71+
```
72+
73+
## type [Options](<https://github.com/odpf/stencil/blob/master/clients/go/client.go#L43-L50>)
74+
75+
Options options for stencil client
76+
77+
```go
78+
type Options struct {
79+
// AutoRefresh boolean to enable or disable autorefresh. Default to false
80+
AutoRefresh bool
81+
// RefreshInterval refresh interval to fetch descriptor file from server.
82+
RefreshInterval time.Duration
83+
// HTTPOptions options for http client
84+
HTTPOptions
85+
}
86+
```

clients/go/client.go

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
package stencilclient
1+
// Package stencil helps to download and refresh protobuf descriptors from remote server
2+
// and provides helper functions to get protobuf schema descriptors and can parse the messages
3+
// dynamically.
4+
package stencil
25

36
import (
47
"errors"
@@ -12,12 +15,13 @@ import (
1215
)
1316

1417
var (
18+
//ErrNotFound default sentinel error if proto not found
1519
ErrNotFound = errors.New("not found")
1620
)
1721

18-
// StencilClient provides utility functions to parse protobuf messages at runtime.
22+
// Client provides utility functions to parse protobuf messages at runtime.
1923
// protobuf messages can be identified by specifying fully qualified generated proto java class name.
20-
type StencilClient interface {
24+
type Client interface {
2125
// Parse parses protobuf message from wire format to protoreflect.Message given fully qualified name of proto message.
2226
// Returns ErrNotFound error if given class name is not found
2327
Parse(string, []byte) (protoreflect.ProtoMessage, error)
@@ -29,7 +33,7 @@ type StencilClient interface {
2933

3034
// HTTPOptions options for http client
3135
type HTTPOptions struct {
32-
// Timeout specifies a time limit for requests made by this client
36+
// Timeout specifies a time limit for requests made by this client.
3337
Timeout time.Duration
3438
// Headers provide extra headers to be added in requests made by this client
3539
Headers map[string]string
@@ -45,13 +49,13 @@ type Options struct {
4549
HTTPOptions
4650
}
4751

48-
type stencilclient struct {
52+
type stencilClient struct {
4953
timer io.Closer
5054
urls []string
5155
store *descriptorStore
5256
}
5357

54-
func (s *stencilclient) Parse(className string, data []byte) (protoreflect.ProtoMessage, error) {
58+
func (s *stencilClient) Parse(className string, data []byte) (protoreflect.ProtoMessage, error) {
5559
desc, ok := s.store.get(className)
5660
if !ok {
5761
return nil, ErrNotFound
@@ -61,29 +65,29 @@ func (s *stencilclient) Parse(className string, data []byte) (protoreflect.Proto
6165
return m, err
6266
}
6367

64-
func (s *stencilclient) GetDescriptor(className string) (protoreflect.MessageDescriptor, error) {
68+
func (s *stencilClient) GetDescriptor(className string) (protoreflect.MessageDescriptor, error) {
6569
desc, ok := s.store.get(className)
6670
if !ok {
6771
return nil, ErrNotFound
6872
}
6973
return desc, nil
7074
}
7175

72-
func (s *stencilclient) Close() {
76+
func (s *stencilClient) Close() {
7377
if s.timer != nil {
7478
s.timer.Close()
7579
}
7680
}
7781

78-
func (s *stencilclient) refresh(opts Options) error {
82+
func (s *stencilClient) refresh(opts Options) error {
7983
var err error
8084
for _, url := range s.urls {
8185
err = multierr.Combine(err, s.store.loadFromURI(url, opts))
8286
}
8387
return err
8488
}
8589

86-
func (s *stencilclient) load(opts Options) error {
90+
func (s *stencilClient) load(opts Options) error {
8791
if opts.AutoRefresh {
8892
s.timer = setInterval(opts.RefreshInterval, func() { s.refresh(opts) })
8993
}
@@ -92,15 +96,15 @@ func (s *stencilclient) load(opts Options) error {
9296
}
9397

9498
// NewClient creates stencil client
95-
func NewClient(url string, options Options) (StencilClient, error) {
96-
s := &stencilclient{store: newStore(), urls: []string{url}}
99+
func NewClient(url string, options Options) (Client, error) {
100+
s := &stencilClient{store: newStore(), urls: []string{url}}
97101
err := s.load(options)
98102
return s, err
99103
}
100104

101105
// NewMultiURLClient creates stencil client with multiple urls
102-
func NewMultiURLClient(urls []string, options Options) (StencilClient, error) {
103-
s := &stencilclient{store: newStore(), urls: urls}
106+
func NewMultiURLClient(urls []string, options Options) (Client, error) {
107+
s := &stencilClient{store: newStore(), urls: urls}
104108
err := s.load(options)
105109
return s, err
106110
}

clients/go/client_test.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package stencilclient_test
1+
package stencil_test
22

33
import (
44
"bytes"
@@ -11,7 +11,7 @@ import (
1111
"testing"
1212
"time"
1313

14-
stencilclient "github.com/odpf/stencil/clients/go"
14+
stencil "github.com/odpf/stencil/clients/go"
1515
"github.com/stretchr/testify/assert"
1616
"google.golang.org/protobuf/proto"
1717
"google.golang.org/protobuf/reflect/protoreflect"
@@ -70,13 +70,13 @@ func getDescriptorData(t *testing.T, includeImports bool) ([]byte, error) {
7070
func TestNewClient(t *testing.T) {
7171
t.Run("should return error if url is not valid", func(t *testing.T) {
7272
url := "h_ttp://invalidurl"
73-
_, err := stencilclient.NewClient(url, stencilclient.Options{})
73+
_, err := stencil.NewClient(url, stencil.Options{})
7474
assert.Contains(t, err.Error(), "invalid request")
7575
})
7676

7777
t.Run("should return error if request fails", func(t *testing.T) {
7878
url := "ithttp://localhost"
79-
_, err := stencilclient.NewClient(url, stencilclient.Options{})
79+
_, err := stencil.NewClient(url, stencil.Options{})
8080
assert.Contains(t, err.Error(), "request failed")
8181
})
8282

@@ -86,7 +86,7 @@ func TestNewClient(t *testing.T) {
8686
}))
8787
defer ts.Close()
8888
url := ts.URL
89-
_, err := stencilclient.NewClient(url, stencilclient.Options{})
89+
_, err := stencil.NewClient(url, stencil.Options{})
9090
assert.Contains(t, err.Error(), "request failed.")
9191
})
9292

@@ -97,7 +97,7 @@ func TestNewClient(t *testing.T) {
9797
}))
9898
defer ts.Close()
9999
url := ts.URL
100-
_, err := stencilclient.NewClient(url, stencilclient.Options{})
100+
_, err := stencil.NewClient(url, stencil.Options{})
101101
assert.Contains(t, err.Error(), "invalid file descriptorset file.")
102102
})
103103

@@ -109,7 +109,7 @@ func TestNewClient(t *testing.T) {
109109
}))
110110
defer ts.Close()
111111
url := ts.URL
112-
_, err = stencilclient.NewClient(url, stencilclient.Options{})
112+
_, err = stencil.NewClient(url, stencil.Options{})
113113
if assert.NotNil(t, err) {
114114
assert.Contains(t, err.Error(), "file is not fully contained descriptor file.")
115115
}
@@ -123,7 +123,7 @@ func TestNewClient(t *testing.T) {
123123
}))
124124
defer ts.Close()
125125
url := ts.URL
126-
client, err := stencilclient.NewClient(url, stencilclient.Options{})
126+
client, err := stencil.NewClient(url, stencil.Options{})
127127
assert.Nil(t, err)
128128
assert.NotNil(t, client)
129129
})
@@ -139,7 +139,7 @@ func TestNewClient(t *testing.T) {
139139
}
140140
w.Write(data)
141141
}))
142-
client, err := stencilclient.NewClient(ts.URL, stencilclient.Options{HTTPOptions: stencilclient.HTTPOptions{Headers: headers}})
142+
client, err := stencil.NewClient(ts.URL, stencil.Options{HTTPOptions: stencil.HTTPOptions{Headers: headers}})
143143
assert.Nil(t, err)
144144
assert.NotNil(t, client)
145145
})
@@ -151,7 +151,7 @@ func TestNewClient(t *testing.T) {
151151
callCount++
152152
w.Write(data)
153153
}))
154-
client, _ := stencilclient.NewClient(ts.URL, stencilclient.Options{AutoRefresh: true, RefreshInterval: 5 * time.Millisecond})
154+
client, _ := stencil.NewClient(ts.URL, stencil.Options{AutoRefresh: true, RefreshInterval: 5 * time.Millisecond})
155155
time.Sleep(6 * time.Millisecond)
156156
client.Close()
157157
assert.Equal(t, 2, callCount)
@@ -171,7 +171,7 @@ func TestNewMultiURLClient(t *testing.T) {
171171
}))
172172
defer ts2.Close()
173173
url2 := ts2.URL
174-
_, err = stencilclient.NewMultiURLClient([]string{url, url2}, stencilclient.Options{})
174+
_, err = stencil.NewMultiURLClient([]string{url, url2}, stencil.Options{})
175175
assert.NotNil(t, err)
176176
assert.Contains(t, err.Error(), "request failed.")
177177
}
@@ -185,14 +185,14 @@ func TestClient(t *testing.T) {
185185
}))
186186
defer ts.Close()
187187
url := ts.URL
188-
client, err := stencilclient.NewClient(url, stencilclient.Options{})
188+
client, err := stencil.NewClient(url, stencil.Options{})
189189
assert.Nil(t, err)
190190
assert.NotNil(t, client)
191191
t.Run("should return notFoundErr if not found", func(t *testing.T) {
192192
msg, err := client.GetDescriptor("test.stencil.Two.Unknown")
193193
assert.Nil(t, msg)
194194
assert.NotNil(t, err)
195-
assert.Equal(t, stencilclient.ErrNotFound, err)
195+
assert.Equal(t, stencil.ErrNotFound, err)
196196
})
197197
t.Run("should get nested message descriptor from fully qualified java classname", func(t *testing.T) {
198198
msg, err := client.GetDescriptor("test.stencil.Two.Four")
@@ -215,14 +215,14 @@ func TestClient(t *testing.T) {
215215
}))
216216
defer ts.Close()
217217
url := ts.URL
218-
client, err := stencilclient.NewClient(url, stencilclient.Options{})
218+
client, err := stencil.NewClient(url, stencil.Options{})
219219
assert.Nil(t, err)
220220
assert.NotNil(t, client)
221221
t.Run("should return notFoundErr if not found", func(t *testing.T) {
222222
msg, err := client.Parse("test.stencil.Two.Unknown", []byte(""))
223223
assert.Nil(t, msg)
224224
assert.NotNil(t, err)
225-
assert.Equal(t, stencilclient.ErrNotFound, err)
225+
assert.Equal(t, stencil.ErrNotFound, err)
226226
})
227227

228228
t.Run("should parse wire format data given className", func(t *testing.T) {

clients/go/downloader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package stencilclient
1+
package stencil
22

33
import (
44
"fmt"

clients/go/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/odpf/stencil/clients/go
33
go 1.16
44

55
require (
6-
github.com/stretchr/testify v1.7.0 // indirect
6+
github.com/stretchr/testify v1.7.0
77
go.uber.org/multierr v1.6.0
88
google.golang.org/protobuf v1.26.0
99
)

clients/go/go.sum

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
66
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
77
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
88
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
9-
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
109
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1110
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
1211
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
@@ -20,6 +19,7 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
2019
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
2120
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
2221
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
22+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2323
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2424
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
2525
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

clients/go/protoutils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package stencilclient
1+
package stencil
22

33
import (
44
"strings"

clients/go/resolver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package stencilclient
1+
package stencil
22

33
import (
44
"google.golang.org/protobuf/reflect/protoreflect"

0 commit comments

Comments
 (0)