Skip to content

Commit 6427c9a

Browse files
authored
Add callerNamespace to go client (#36)
1 parent 639809e commit 6427c9a

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

golang/go_client.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package golang
22

33
import (
44
"bytes"
5+
"fmt"
56
"go/format"
67
"strings"
78
"text/template"
@@ -12,12 +13,13 @@ import (
1213
)
1314

1415
const (
15-
version = "1.1.0"
16+
version = "1.1.1"
1617
lang = "golang"
1718
)
1819

1920
type Settings struct {
20-
Package string
21+
Package string
22+
CallerNamespace string
2123
}
2224

2325
// Generator main package structure
@@ -38,6 +40,10 @@ func NewClient(schema smd.Schema, settings Settings) *Generator {
3840
func (g *Generator) Generate() ([]byte, error) {
3941
g.schema.GeneratorData = gen.DefaultGeneratorData().AddLangAndLocalVersion(version, lang)
4042
g.schema.Package = g.settings.Package
43+
g.schema.CallerName = g.settings.Package
44+
if g.settings.CallerNamespace != "" {
45+
g.schema.CallerName = fmt.Sprintf("%s-%s", g.settings.CallerNamespace, g.settings.Package)
46+
}
4147

4248
tmpl, err := template.New("golang client").Funcs(templateFuncs).Parse(goTpl)
4349
if err != nil {

golang/go_template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/vmkteam/zenrpc/v2"
2121
)
2222
23-
const name = "{{ .Package }}"
23+
const name = "{{ .CallerName }}"
2424
2525
var (
2626
// Always import time package. Generated models can contain time.Time fields.

golang/schema.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func NewSchema(schema smd.Schema) Schema {
3131
type Schema struct {
3232
gen.GeneratorData
3333
Package string
34+
CallerName string
3435
Namespaces []Namespace
3536
}
3637

0 commit comments

Comments
 (0)