From a608c996866d220eaf4338d4dd417af5c26beb3e Mon Sep 17 00:00:00 2001 From: sleygin Date: Mon, 26 Feb 2024 00:06:29 +0300 Subject: [PATCH 1/2] ParamPtrsStruct method to Method added --- generator/types.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/generator/types.go b/generator/types.go index 654f6ac..1fa0eee 100644 --- a/generator/types.go +++ b/generator/types.go @@ -279,6 +279,20 @@ func (m Method) ParamsStruct() string { return "struct{\n" + strings.Join(ss, "\n ") + "}" } +// ParamPtrsStruct returns a struct type with pointer fields corresponding +// to the method params +func (m Method) ParamPtrsStruct() string { + ss := []string{} + for _, p := range m.Params { + if p.Variadic { + ss = append(ss, p.Name+" *"+strings.Replace(p.Type, "...", "[]", 1)) + } else { + ss = append(ss, p.Name+" *"+p.Type) + } + } + return "struct{\n" + strings.Join(ss, "\n ") + "}" +} + // ResultsStruct returns a struct type with fields corresponding // to the method results func (m Method) ResultsStruct() string { From bfc6a4ab998722e0006530e28e32b32186a182b8 Mon Sep 17 00:00:00 2001 From: sleygin Date: Mon, 26 Feb 2024 00:08:46 +0300 Subject: [PATCH 2/2] ParamPtrsStruct tests added --- generator/types_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/generator/types_test.go b/generator/types_test.go index 8e5bfbd..bd2c62c 100644 --- a/generator/types_test.go +++ b/generator/types_test.go @@ -79,6 +79,14 @@ func TestMethod_ParamsStruct(t *testing.T) { assert.Equal(t, "struct{\ns []string}", m.ParamsStruct()) } +func TestMethod_ParamPtrsStruct(t *testing.T) { + m := Method{ + Name: "method", + Params: []Param{{Name: "s", Type: "...string", Variadic: true}}, + } + assert.Equal(t, "struct{\ns *[]string}", m.ParamPtrsStruct()) +} + func TestMethod_ResultsStruct(t *testing.T) { m := Method{ Name: "method",