Skip to content

Commit

Permalink
bonsai
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Sep 22, 2023
1 parent 6a1581d commit bb0723b
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 174 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestClient(t *testing.T) {
t.Cleanup(func() {
ts.Close()
})
ts.Method("GetFeature").Response(map[string]interface{}{"name": "hello", "location": map[string]interface{}{"latitude": 10, "longitude": 13}})
ts.Method("GetFeature").Response(map[string]any{"name": "hello", "location": map[string]any{"latitude": 10, "longitude": 13}})

client := routeguide.NewRouteGuideClient(ts.Conn())
if _, err := client.GetFeature(ctx, &routeguide.Point{
Expand Down
8 changes: 4 additions & 4 deletions dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (gs generators) matchFunc(name string) (GenerateFunc, bool) {

type GeneratorOption func(generators) generators

type GenerateFunc func(r *Request) interface{}
type GenerateFunc func(r *Request) any

func Generator(pattern string, fn GenerateFunc) GeneratorOption {
return func(gs generators) generators {
Expand Down Expand Up @@ -68,7 +68,7 @@ func (m *matcher) ResponseDynamic(opts ...GeneratorOption) *matcher {
return m
}

func generateDynamicMessage(gs generators, r *Request, m protoreflect.MessageDescriptor, parents []string) map[string]interface{} {
func generateDynamicMessage(gs generators, r *Request, m protoreflect.MessageDescriptor, parents []string) map[string]any {
const (
floatMin = 0
floatMax = 10000
Expand All @@ -77,11 +77,11 @@ func generateDynamicMessage(gs generators, r *Request, m protoreflect.MessageDes
repeatMax = 5
fieldSep = "."
)
message := map[string]interface{}{}
message := map[string]any{}

for i := 0; i < m.Fields().Len(); i++ {
f := m.Fields().Get(i)
values := []interface{}{}
values := []any{}
l := 1
if f.HasOptionalKeyword() {
l = rand.Intn(2)
Expand Down
4 changes: 2 additions & 2 deletions dynamic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestResponseDynamicGenerated(t *testing.T) {
})
want := time.Now()
opts := []GeneratorOption{
Generator("*_time", func(r *Request) interface{} {
Generator("*_time", func(r *Request) any {
return want
}),
}
Expand All @@ -99,7 +99,7 @@ func TestResponseDynamicServer(t *testing.T) {
})
want := time.Now()
opts := []GeneratorOption{
Generator("*_time", func(r *Request) interface{} {
Generator("*_time", func(r *Request) any {
return want
}),
}
Expand Down
Loading

0 comments on commit bb0723b

Please sign in to comment.