From b696a027b2d0d0a790db003b6c81e302ff794269 Mon Sep 17 00:00:00 2001 From: Igor Derkach Date: Sun, 22 Dec 2024 17:17:06 +0400 Subject: [PATCH] Intermediate commit --- .../content/code-structure/channel.md | 2 +- .../content/code-structure/message.md | 8 +- internal/asyncapi/amqp/channel.go | 6 +- internal/asyncapi/amqp/server.go | 1 - internal/asyncapi/asyncapi.go | 8 -- internal/asyncapi/bindings.go | 2 +- internal/asyncapi/channel.go | 16 +-- internal/asyncapi/correlationid.go | 2 +- internal/asyncapi/http/channel.go | 6 +- internal/asyncapi/http/server.go | 1 - internal/asyncapi/ip/channel.go | 6 +- internal/asyncapi/ip/server.go | 1 - internal/asyncapi/kafka/channel.go | 6 +- internal/asyncapi/kafka/server.go | 1 - internal/asyncapi/message.go | 20 ++-- internal/asyncapi/mqtt/channel.go | 6 +- internal/asyncapi/mqtt/server.go | 1 - internal/asyncapi/object.go | 14 +-- internal/asyncapi/parameter.go | 4 +- internal/asyncapi/redis/channel.go | 6 +- internal/asyncapi/redis/server.go | 1 - internal/asyncapi/server.go | 6 +- internal/asyncapi/servervariable.go | 2 +- internal/asyncapi/tcp/channel.go | 6 +- internal/asyncapi/tcp/server.go | 1 - internal/asyncapi/udp/channel.go | 6 +- internal/asyncapi/udp/server.go | 1 - internal/asyncapi/ws/channel.go | 6 +- internal/asyncapi/ws/server.go | 1 - internal/common/promise.go | 6 +- internal/render/amqp/channel.go | 22 ++-- internal/render/amqp/server.go | 10 +- internal/render/asyncapi.go | 2 - internal/render/channel.go | 14 +-- internal/render/http/channel.go | 20 ++-- internal/render/http/server.go | 10 +- internal/render/ip/channel.go | 20 ++-- internal/render/ip/server.go | 10 +- internal/render/kafka/channel.go | 22 ++-- internal/render/kafka/server.go | 10 +- internal/render/lang/promise.go | 113 ++++++------------ internal/render/lang/ref.go | 50 ++++++++ internal/render/message.go | 12 +- internal/render/mqtt/channel.go | 22 ++-- internal/render/mqtt/server.go | 10 +- internal/render/proto/channel.go | 42 +++---- internal/render/proto/server.go | 20 ++-- internal/render/redis/channel.go | 20 ++-- internal/render/redis/server.go | 10 +- internal/render/server.go | 8 +- internal/render/tcp/channel.go | 24 ++-- internal/render/tcp/server.go | 10 +- internal/render/udp/channel.go | 20 ++-- internal/render/udp/server.go | 10 +- internal/render/ws/channel.go | 22 ++-- internal/render/ws/server.go | 10 +- templates/amqp/amqp_channel.tmpl | 24 ++-- templates/amqp/amqp_message.tmpl | 4 +- templates/amqp/amqp_server.tmpl | 10 +- templates/common/proto.tmpl | 48 ++++---- templates/http/http_channel.tmpl | 4 +- templates/http/http_message.tmpl | 4 +- templates/http/http_server.tmpl | 10 +- templates/ip/ip_channel.tmpl | 4 +- templates/ip/ip_message.tmpl | 4 +- templates/ip/ip_server.tmpl | 10 +- templates/kafka/kafka_channel.tmpl | 20 ++-- templates/kafka/kafka_message.tmpl | 4 +- templates/kafka/kafka_server.tmpl | 10 +- templates/main.tmpl | 6 +- templates/mqtt/mqtt_channel.tmpl | 18 +-- templates/mqtt/mqtt_message.tmpl | 4 +- templates/mqtt/mqtt_server.tmpl | 10 +- templates/redis/redis_channel.tmpl | 4 +- templates/redis/redis_message.tmpl | 4 +- templates/redis/redis_server.tmpl | 10 +- templates/tcp/tcp_channel.tmpl | 4 +- templates/tcp/tcp_message.tmpl | 4 +- templates/tcp/tcp_server.tmpl | 10 +- templates/udp/udp_channel.tmpl | 4 +- templates/udp/udp_message.tmpl | 4 +- templates/udp/udp_server.tmpl | 10 +- templates/ws/ws_channel.tmpl | 4 +- templates/ws/ws_message.tmpl | 4 +- templates/ws/ws_server.tmpl | 10 +- 85 files changed, 478 insertions(+), 484 deletions(-) create mode 100644 internal/render/lang/ref.go diff --git a/docs/go-asyncapi/content/code-structure/channel.md b/docs/go-asyncapi/content/code-structure/channel.md index 1e715f5..50f4add 100644 --- a/docs/go-asyncapi/content/code-structure/channel.md +++ b/docs/go-asyncapi/content/code-structure/channel.md @@ -125,7 +125,7 @@ func (m MyChannelKafka) Publish(ctx context.Context, envelopes ...kafka.Envelope func (m MyChannelKafka) SealEnvelope(envelope kafka.EnvelopeWriter, message *MyChannelMessageOut) error { envelope.ResetPayload() - if err := message.MarshalKafkaEnvelope(envelope); err != nil { + if err := message.MarshalEnvelopeKafka(envelope); err != nil { return err } envelope.SetTopic(m.topic) diff --git a/docs/go-asyncapi/content/code-structure/message.md b/docs/go-asyncapi/content/code-structure/message.md index 97ddd86..630a8d7 100644 --- a/docs/go-asyncapi/content/code-structure/message.md +++ b/docs/go-asyncapi/content/code-structure/message.md @@ -70,7 +70,7 @@ type MyMessageOut struct { Headers map[string]any } -func (m *MyMessageOut) MarshalKafkaEnvelope(envelope kafka.EnvelopeWriter) error { +func (m *MyMessageOut) MarshalEnvelopeKafka(envelope kafka.EnvelopeWriter) error { enc := encoding.NewEncoder("application/json", envelope) if err := enc.Encode(m.Payload); err != nil { @@ -100,7 +100,7 @@ type MyMessageIn struct { Headers map[string]any } -func (m *MyMessageIn) UnmarshalKafkaEnvelope(envelope kafka.EnvelopeReader) error { +func (m *MyMessageIn) UnmarshalEnvelopeKafka(envelope kafka.EnvelopeReader) error { dec := encoding.NewDecoder("application/json", envelope) if err := dec.Decode(&m.Payload); err != nil { @@ -317,7 +317,7 @@ func NewDecoder(contentType string, r io.Reader) Decoder { {{< tab "Generated message code" >}} ```go // ... -func (m *MyMessageOut) MarshalKafkaEnvelope(envelope kafka.EnvelopeWriter) error { +func (m *MyMessageOut) MarshalEnvelopeKafka(envelope kafka.EnvelopeWriter) error { enc := encoding.NewEncoder("application/json", envelope) if err := enc.Encode(m.Payload); err != nil { @@ -330,7 +330,7 @@ func (m *MyMessageOut) MarshalKafkaEnvelope(envelope kafka.EnvelopeWriter) error // ... -func (m *MyMessageIn) UnmarshalKafkaEnvelope(envelope kafka.EnvelopeReader) error { +func (m *MyMessageIn) UnmarshalEnvelopeKafka(envelope kafka.EnvelopeReader) error { dec := encoding.NewDecoder("application/json", envelope) if err := dec.Decode(&m.Payload); err != nil { diff --git a/internal/asyncapi/amqp/channel.go b/internal/asyncapi/amqp/channel.go index ac27c86..11d5d82 100644 --- a/internal/asyncapi/amqp/channel.go +++ b/internal/asyncapi/amqp/channel.go @@ -64,9 +64,9 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap ) return &render.ProtoChannel{ - Channel: parent, - Type: chanStruct, - ProtoName: pb.ProtoName, + Channel: parent, + Type: chanStruct, + Protocol: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/amqp/server.go b/internal/asyncapi/amqp/server.go index ce815e5..514717e 100644 --- a/internal/asyncapi/amqp/server.go +++ b/internal/asyncapi/amqp/server.go @@ -19,7 +19,6 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi. return &render.ProtoServer{ Server: parent, Type: baseServer, - ProtoName: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/asyncapi.go b/internal/asyncapi/asyncapi.go index 94f0eec..cf2d656 100644 --- a/internal/asyncapi/asyncapi.go +++ b/internal/asyncapi/asyncapi.go @@ -3,7 +3,6 @@ package asyncapi import ( "github.com/bdragon300/go-asyncapi/internal/common" "github.com/bdragon300/go-asyncapi/internal/render" - "github.com/bdragon300/go-asyncapi/internal/render/lang" "github.com/bdragon300/go-asyncapi/internal/types" ) @@ -28,14 +27,7 @@ func (a AsyncAPI) Compile(ctx *common.CompileContext) error { } func (a AsyncAPI) build(ctx *common.CompileContext) *render.AsyncAPI { - allMessagesPrm := lang.NewListCbPromise[*render.Message](func(item common.CompileObject, _ []string) bool { - _, ok := item.Renderable.(*render.Message) - return ok - }) - ctx.PutListPromise(allMessagesPrm) - res := &render.AsyncAPI{ - AllMessages: allMessagesPrm, DefaultContentType: a.DefaultContentType, } return res diff --git a/internal/asyncapi/bindings.go b/internal/asyncapi/bindings.go index 4b94f8b..c4a691c 100644 --- a/internal/asyncapi/bindings.go +++ b/internal/asyncapi/bindings.go @@ -34,7 +34,7 @@ func (b *Bindings) build( ) (common.Renderable, error) { if b.Ref != "" { ctx.Logger.Trace("Ref", "$ref", b.Ref) - res := lang.NewUserPromise(b.Ref, bindingsKey, nil) + res := lang.NewRef(b.Ref, bindingsKey, nil) ctx.PutPromise(res) return res, nil } diff --git a/internal/asyncapi/channel.go b/internal/asyncapi/channel.go index 25a573a..c104ab3 100644 --- a/internal/asyncapi/channel.go +++ b/internal/asyncapi/channel.go @@ -53,7 +53,7 @@ func (c Channel) build(ctx *common.CompileContext, channelKey string, flags map[ if c.Ref != "" { ctx.Logger.Trace("Ref", "$ref", c.Ref) // Make a promise selectable if it defined in `channels` section - prm := lang.NewUserPromise(c.Ref, channelKey, lo.Ternary(isComponent, nil, lo.ToPtr(true))) + prm := lang.NewRef(c.Ref, channelKey, lo.Ternary(isComponent, nil, lo.ToPtr(true))) ctx.PutPromise(prm) return prm, nil } @@ -77,7 +77,7 @@ func (c Channel) build(ctx *common.CompileContext, channelKey string, flags map[ for _, paramName := range c.Parameters.Keys() { ctx.Logger.Trace("Channel parameter", "name", paramName) ref := ctx.PathStackRef("parameters", paramName) - prm := lang.NewInternalGolangTypeAssignCbPromise(ref, func(obj any) common.GolangType { + prm := lang.NewGolangTypeAssignCbPromise(ref, nil, func(obj any) common.GolangType { return obj.(*render.Parameter).Type }) ctx.PutPromise(prm) @@ -93,7 +93,7 @@ func (c Channel) build(ctx *common.CompileContext, channelKey string, flags map[ // Empty servers field means "no servers", omitted servers field means "all servers" if c.Servers != nil { ctx.Logger.Trace("Channel servers", "names", *c.Servers) - res.SpecServerNames = *c.Servers + res.BoundServerNames = *c.Servers prm := lang.NewListCbPromise[*render.Server](func(item common.CompileObject, path []string) bool { srv, ok := item.Renderable.(*render.Server) if !ok { @@ -120,7 +120,7 @@ func (c Channel) build(ctx *common.CompileContext, channelKey string, flags map[ hasBindings = true ref := ctx.PathStackRef("bindings") - res.BindingsChannelPromise = lang.NewInternalPromise[*render.Bindings](ref) + res.BindingsChannelPromise = lang.NewPromise[*render.Bindings](ref) ctx.PutPromise(res.BindingsChannelPromise) } @@ -133,13 +133,13 @@ func (c Channel) build(ctx *common.CompileContext, channelKey string, flags map[ hasBindings = true ref := ctx.PathStackRef("publish", "bindings") - res.BindingsPublishPromise = lang.NewInternalPromise[*render.Bindings](ref) + res.BindingsPublishPromise = lang.NewPromise[*render.Bindings](ref) ctx.PutPromise(res.BindingsPublishPromise) } if c.Publish.Message != nil { ctx.Logger.Trace("Found publish operation message") ref := ctx.PathStackRef("publish", "message") - res.PublisherMessageTypePromise = lang.NewInternalPromise[*render.Message](ref) + res.PublisherMessageTypePromise = lang.NewPromise[*render.Message](ref) ctx.PutPromise(res.PublisherMessageTypePromise) } } @@ -150,13 +150,13 @@ func (c Channel) build(ctx *common.CompileContext, channelKey string, flags map[ hasBindings = true ref := ctx.PathStackRef("subscribe", "bindings") - res.BindingsSubscribePromise = lang.NewInternalPromise[*render.Bindings](ref) + res.BindingsSubscribePromise = lang.NewPromise[*render.Bindings](ref) ctx.PutPromise(res.BindingsSubscribePromise) } if c.Subscribe.Message != nil { ctx.Logger.Trace("Channel subscribe operation message") ref := ctx.PathStackRef("subscribe", "message") - res.SubscriberMessageTypePromise = lang.NewInternalPromise[*render.Message](ref) + res.SubscriberMessageTypePromise = lang.NewPromise[*render.Message](ref) ctx.PutPromise(res.SubscriberMessageTypePromise) } } diff --git a/internal/asyncapi/correlationid.go b/internal/asyncapi/correlationid.go index ffaad4b..1c646a0 100644 --- a/internal/asyncapi/correlationid.go +++ b/internal/asyncapi/correlationid.go @@ -41,7 +41,7 @@ func (c CorrelationID) build(ctx *common.CompileContext, correlationIDKey string // TODO: move this ref code from everywhere to single place? if c.Ref != "" { ctx.Logger.Trace("Ref", "$ref", c.Ref) - res := lang.NewUserPromise(c.Ref, correlationIDKey, nil) + res := lang.NewRef(c.Ref, correlationIDKey, nil) ctx.PutPromise(res) return res, nil } diff --git a/internal/asyncapi/http/channel.go b/internal/asyncapi/http/channel.go index 29353a7..d2f6551 100644 --- a/internal/asyncapi/http/channel.go +++ b/internal/asyncapi/http/channel.go @@ -27,9 +27,9 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap } return &render.ProtoChannel{ - Channel: parent, - Type: chanStruct, - ProtoName: pb.ProtoName, + Channel: parent, + Type: chanStruct, + Protocol: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/http/server.go b/internal/asyncapi/http/server.go index 125016e..c24bb5c 100644 --- a/internal/asyncapi/http/server.go +++ b/internal/asyncapi/http/server.go @@ -19,7 +19,6 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi. return &render.ProtoServer{ Server: parent, Type: baseServer, - ProtoName: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/ip/channel.go b/internal/asyncapi/ip/channel.go index 0e78303..7a9e82a 100644 --- a/internal/asyncapi/ip/channel.go +++ b/internal/asyncapi/ip/channel.go @@ -21,9 +21,9 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap } return &render.ProtoChannel{ - Channel: parent, - Type: chanStruct, - ProtoName: pb.ProtoName, + Channel: parent, + Type: chanStruct, + Protocol: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/ip/server.go b/internal/asyncapi/ip/server.go index 8000e9a..6b42dcc 100644 --- a/internal/asyncapi/ip/server.go +++ b/internal/asyncapi/ip/server.go @@ -19,7 +19,6 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi. return &render.ProtoServer{ Server: parent, Type: baseServer, - ProtoName: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/kafka/channel.go b/internal/asyncapi/kafka/channel.go index 7db95a6..e1743b1 100644 --- a/internal/asyncapi/kafka/channel.go +++ b/internal/asyncapi/kafka/channel.go @@ -44,9 +44,9 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap chanStruct.Fields = append(chanStruct.Fields, lang.GoStructField{Name: "topic", Type: &lang.GoSimple{TypeName: "string"}}) return &render.ProtoChannel{ - Channel: parent, - Type: chanStruct, - ProtoName: pb.ProtoName, + Channel: parent, + Type: chanStruct, + Protocol: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/kafka/server.go b/internal/asyncapi/kafka/server.go index 17e8719..38c376c 100644 --- a/internal/asyncapi/kafka/server.go +++ b/internal/asyncapi/kafka/server.go @@ -24,7 +24,6 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi. return &render.ProtoServer{ Server: parent, Type: baseServer, - ProtoName: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/message.go b/internal/asyncapi/message.go index 59054f9..920f135 100644 --- a/internal/asyncapi/message.go +++ b/internal/asyncapi/message.go @@ -81,7 +81,7 @@ func (m Message) build(ctx *common.CompileContext, messageKey string) (common.Re ctx.Logger.Trace("Ref", "$ref", m.Ref) // Always draw the promises that are located in the `messages` section - prm := lang.NewUserPromise(m.Ref, refName, lo.Ternary(makeSelectable, lo.ToPtr(true), nil)) + prm := lang.NewRef(m.Ref, refName, lo.Ternary(makeSelectable, lo.ToPtr(true), nil)) ctx.PutPromise(prm) return prm, nil } @@ -118,10 +118,10 @@ func (m Message) build(ctx *common.CompileContext, messageKey string) (common.Re res.AllServersPromise = prm ctx.PutListPromise(prm) - prm2 := lang.NewInternalCbPromise[*render.AsyncAPI](func(item common.CompileObject, path []string) bool { + prm2 := lang.NewCbPromise[*render.AsyncAPI](func(item common.CompileObject, path []string) bool { _, ok := item.Renderable.(*render.AsyncAPI) return ok - }) + }, nil) res.AsyncAPIPromise = prm2 ctx.PutPromise(prm2) @@ -129,7 +129,7 @@ func (m Message) build(ctx *common.CompileContext, messageKey string) (common.Re if m.Headers != nil { ctx.Logger.Trace("Message headers") ref := ctx.PathStackRef("headers") - res.HeadersTypePromise = lang.NewInternalPromise[*lang.GoStruct](ref) + res.HeadersTypePromise = lang.NewPromise[*lang.GoStruct](ref) res.HeadersTypePromise.AssignErrorNote = "Probably the headers schema has type other than of 'object'?" ctx.PutPromise(res.HeadersTypePromise) } @@ -146,7 +146,7 @@ func (m Message) build(ctx *common.CompileContext, messageKey string) (common.Re } ref := ctx.PathStackRef("bindings") - res.BindingsPromise = lang.NewInternalPromise[*render.Bindings](ref) + res.BindingsPromise = lang.NewPromise[*render.Bindings](ref) ctx.PutPromise(res.BindingsPromise) } @@ -154,7 +154,7 @@ func (m Message) build(ctx *common.CompileContext, messageKey string) (common.Re if m.CorrelationID != nil { ctx.Logger.Trace("Message correlationId") ref := ctx.PathStackRef("correlationId") - res.CorrelationIDPromise = lang.NewInternalPromise[*render.CorrelationID](ref) + res.CorrelationIDPromise = lang.NewPromise[*render.CorrelationID](ref) ctx.PutPromise(res.CorrelationIDPromise) } @@ -165,8 +165,8 @@ func (m Message) build(ctx *common.CompileContext, messageKey string) (common.Re for proto := range ProtocolBuilders { ctx.Logger.Trace("Message", "proto", proto) protoMessages = append(protoMessages, &render.ProtoMessage{ - Message: &res, - ProtoName: proto, + Message: &res, + Protocol: proto, }) } res.ProtoMessages = protoMessages @@ -180,7 +180,7 @@ func (m Message) setStructFields(ctx *common.CompileContext, langMessage *render } if langMessage.HeadersTypePromise != nil { ctx.Logger.Trace("Message headers has a concrete type") - prm := lang.NewInternalGolangTypePromise(langMessage.HeadersTypePromise.Ref()) + prm := lang.NewGolangTypePromise(langMessage.HeadersTypePromise.Ref()) ctx.PutPromise(prm) fields = append(fields, lang.GoStructField{Name: "Headers", Type: prm}) } else { @@ -196,7 +196,7 @@ func (m Message) getPayloadType(ctx *common.CompileContext) common.GolangType { if m.Payload != nil { ctx.Logger.Trace("Message payload has a concrete type") ref := ctx.PathStackRef("payload") - prm := lang.NewInternalGolangTypePromise(ref) + prm := lang.NewGolangTypePromise(ref) ctx.PutPromise(prm) return prm } diff --git a/internal/asyncapi/mqtt/channel.go b/internal/asyncapi/mqtt/channel.go index d6b2b6e..95e449f 100644 --- a/internal/asyncapi/mqtt/channel.go +++ b/internal/asyncapi/mqtt/channel.go @@ -28,9 +28,9 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap chanStruct.Fields = append(chanStruct.Fields, lang.GoStructField{Name: "topic", Type: &lang.GoSimple{TypeName: "string"}}) return &render.ProtoChannel{ - Channel: parent, - Type: chanStruct, - ProtoName: pb.ProtoName, + Channel: parent, + Type: chanStruct, + Protocol: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/mqtt/server.go b/internal/asyncapi/mqtt/server.go index fbbc4db..2278d3a 100644 --- a/internal/asyncapi/mqtt/server.go +++ b/internal/asyncapi/mqtt/server.go @@ -33,7 +33,6 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi. return &render.ProtoServer{ Server: parent, Type: baseServer, - ProtoName: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/object.go b/internal/asyncapi/object.go index 19409d3..32d204e 100644 --- a/internal/asyncapi/object.go +++ b/internal/asyncapi/object.go @@ -97,7 +97,7 @@ func (o Object) build(ctx *common.CompileContext, flags map[common.SchemaTag]str } ctx.Logger.Trace("Ref", "$ref", o.Ref) - res := lang.NewUserPromise(o.Ref, refName, lo.ToPtr(false)) + res := lang.NewRef(o.Ref, refName, lo.ToPtr(false)) ctx.PutPromise(res) return res, nil } @@ -287,7 +287,7 @@ func (o Object) buildLangStruct(ctx *common.CompileContext, flags map[common.Sch for _, entry := range o.Properties.Entries() { ctx.Logger.Trace("Object property", "name", entry.Key) ref := ctx.PathStackRef("properties", entry.Key) - prm := lang.NewInternalGolangTypePromise(ref) + prm := lang.NewGolangTypePromise(ref) ctx.PutPromise(prm) var langObj common.GolangType = prm @@ -318,7 +318,7 @@ func (o Object) buildLangStruct(ctx *common.CompileContext, flags map[common.Sch case 0: // "additionalProperties:" is an object ctx.Logger.Trace("Object additional properties as an object") ref := ctx.PathStackRef("additionalProperties") - prm := lang.NewInternalGolangTypePromise(ref) + prm := lang.NewGolangTypePromise(ref) ctx.PutPromise(prm) xTags, xTagNames, xTagVals := o.AdditionalProperties.V0.xGoTagsInfo(ctx) f := lang.GoStructField{ @@ -388,7 +388,7 @@ func (o Object) buildLangArray(ctx *common.CompileContext, flags map[common.Sche case o.Items != nil && o.Items.Selector == 0: // Only one "type:" of items ctx.Logger.Trace("Object items (single type)") ref := ctx.PathStackRef("items") - prm := lang.NewInternalGolangTypePromise(ref) + prm := lang.NewGolangTypePromise(ref) ctx.PutPromise(prm) res.ItemsType = prm case o.Items == nil || o.Items.Selector == 1: // No items or Several types for each item sequentially @@ -439,19 +439,19 @@ func (o Object) buildUnionStruct(ctx *common.CompileContext, flags map[common.Sc res.Fields = lo.Times(len(o.OneOf), func(index int) lang.GoStructField { ref := ctx.PathStackRef("oneOf", strconv.Itoa(index)) - prm := lang.NewInternalGolangTypePromise(ref) + prm := lang.NewGolangTypePromise(ref) ctx.PutPromise(prm) return lang.GoStructField{Type: &lang.GoPointer{Type: prm}} }) res.Fields = append(res.Fields, lo.Times(len(o.AnyOf), func(index int) lang.GoStructField { ref := ctx.PathStackRef("anyOf", strconv.Itoa(index)) - prm := lang.NewInternalGolangTypePromise(ref) + prm := lang.NewGolangTypePromise(ref) ctx.PutPromise(prm) return lang.GoStructField{Type: &lang.GoPointer{Type: prm}} })...) res.Fields = append(res.Fields, lo.Times(len(o.AllOf), func(index int) lang.GoStructField { ref := ctx.PathStackRef("allOf", strconv.Itoa(index)) - prm := lang.NewInternalGolangTypePromise(ref) + prm := lang.NewGolangTypePromise(ref) ctx.PutPromise(prm) return lang.GoStructField{Type: prm} })...) diff --git a/internal/asyncapi/parameter.go b/internal/asyncapi/parameter.go index b24e732..12feb7b 100644 --- a/internal/asyncapi/parameter.go +++ b/internal/asyncapi/parameter.go @@ -36,7 +36,7 @@ func (p Parameter) build(ctx *common.CompileContext, parameterKey string) (commo //} if p.Ref != "" { ctx.Logger.Trace("Ref", "$ref", p.Ref) - res := lang.NewUserPromise(p.Ref, parameterKey, nil) + res := lang.NewRef(p.Ref, parameterKey, nil) ctx.PutPromise(res) return res, nil } @@ -46,7 +46,7 @@ func (p Parameter) build(ctx *common.CompileContext, parameterKey string) (commo if p.Schema != nil { ctx.Logger.Trace("Parameter schema") - prm := lang.NewInternalGolangTypePromise(ctx.PathStackRef("schema")) + prm := lang.NewGolangTypePromise(ctx.PathStackRef("schema")) ctx.PutPromise(prm) res.Type = &lang.GoStruct{ BaseType: lang.BaseType{ diff --git a/internal/asyncapi/redis/channel.go b/internal/asyncapi/redis/channel.go index e769a35..a20eeb9 100644 --- a/internal/asyncapi/redis/channel.go +++ b/internal/asyncapi/redis/channel.go @@ -21,9 +21,9 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap } return &render.ProtoChannel{ - Channel: parent, - Type: chanStruct, - ProtoName: pb.ProtoName, + Channel: parent, + Type: chanStruct, + Protocol: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/redis/server.go b/internal/asyncapi/redis/server.go index 79ea355..cd9019f 100644 --- a/internal/asyncapi/redis/server.go +++ b/internal/asyncapi/redis/server.go @@ -19,7 +19,6 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi. return &render.ProtoServer{ Server: parent, Type: baseServer, - ProtoName: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/server.go b/internal/asyncapi/server.go index 192685d..b9089cb 100644 --- a/internal/asyncapi/server.go +++ b/internal/asyncapi/server.go @@ -49,7 +49,7 @@ func (s Server) build(ctx *common.CompileContext, serverKey string) (common.Rend if s.Ref != "" { ctx.Logger.Trace("Ref", "$ref", s.Ref) // Make a promise selectable if it defined in `servers` section - prm := lang.NewUserPromise(s.Ref, serverKey, lo.Ternary(isComponent, nil, lo.ToPtr(true))) + prm := lang.NewRef(s.Ref, serverKey, lo.Ternary(isComponent, nil, lo.ToPtr(true))) ctx.PutPromise(prm) return prm, nil } @@ -84,7 +84,7 @@ func (s Server) build(ctx *common.CompileContext, serverKey string) (common.Rend } ref := ctx.PathStackRef("bindings") - res.BindingsPromise = lang.NewInternalPromise[*render.Bindings](ref) + res.BindingsPromise = lang.NewPromise[*render.Bindings](ref) ctx.PutPromise(res.BindingsPromise) } @@ -92,7 +92,7 @@ func (s Server) build(ctx *common.CompileContext, serverKey string) (common.Rend for _, v := range s.Variables.Entries() { ctx.Logger.Trace("Server variable", "name", v.Key) ref := ctx.PathStackRef("variables", v.Key) - prm := lang.NewInternalPromise[*render.ServerVariable](ref) + prm := lang.NewPromise[*render.ServerVariable](ref) ctx.PutPromise(prm) res.VariablesPromises.Set(v.Key, prm) } diff --git a/internal/asyncapi/servervariable.go b/internal/asyncapi/servervariable.go index 5ed7839..231a248 100644 --- a/internal/asyncapi/servervariable.go +++ b/internal/asyncapi/servervariable.go @@ -28,7 +28,7 @@ func (sv ServerVariable) Compile(ctx *common.CompileContext) error { func (sv ServerVariable) build(ctx *common.CompileContext, serverVariableKey string) (common.Renderable, error) { if sv.Ref != "" { ctx.Logger.Trace("Ref", "$ref", sv.Ref) - res := lang.NewUserPromise(sv.Ref, serverVariableKey, nil) + res := lang.NewRef(sv.Ref, serverVariableKey, nil) ctx.PutPromise(res) return res, nil } diff --git a/internal/asyncapi/tcp/channel.go b/internal/asyncapi/tcp/channel.go index 904aef7..0ca3272 100644 --- a/internal/asyncapi/tcp/channel.go +++ b/internal/asyncapi/tcp/channel.go @@ -21,9 +21,9 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap } return &render.ProtoChannel{ - Channel: parent, - Type: chanStruct, - ProtoName: pb.ProtoName, + Channel: parent, + Type: chanStruct, + Protocol: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/tcp/server.go b/internal/asyncapi/tcp/server.go index 6f20654..4088d3b 100644 --- a/internal/asyncapi/tcp/server.go +++ b/internal/asyncapi/tcp/server.go @@ -19,7 +19,6 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi. return &render.ProtoServer{ Server: parent, Type: baseServer, - ProtoName: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/udp/channel.go b/internal/asyncapi/udp/channel.go index 8e62eaf..b5414ea 100644 --- a/internal/asyncapi/udp/channel.go +++ b/internal/asyncapi/udp/channel.go @@ -21,9 +21,9 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap } return &render.ProtoChannel{ - Channel: parent, - Type: chanStruct, - ProtoName: pb.ProtoName, + Channel: parent, + Type: chanStruct, + Protocol: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/udp/server.go b/internal/asyncapi/udp/server.go index 06489e6..ff00cd8 100644 --- a/internal/asyncapi/udp/server.go +++ b/internal/asyncapi/udp/server.go @@ -19,7 +19,6 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi. return &render.ProtoServer{ Server: parent, Type: baseServer, - ProtoName: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/ws/channel.go b/internal/asyncapi/ws/channel.go index 99f6137..5ec640c 100644 --- a/internal/asyncapi/ws/channel.go +++ b/internal/asyncapi/ws/channel.go @@ -29,9 +29,9 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap chanStruct.Fields = append(chanStruct.Fields, lang.GoStructField{Name: "topic", Type: &lang.GoSimple{TypeName: "string"}}) return &render.ProtoChannel{ - Channel: parent, - Type: chanStruct, - ProtoName: pb.ProtoName, + Channel: parent, + Type: chanStruct, + Protocol: pb.ProtoName, }, nil } diff --git a/internal/asyncapi/ws/server.go b/internal/asyncapi/ws/server.go index f5644a7..798e5b2 100644 --- a/internal/asyncapi/ws/server.go +++ b/internal/asyncapi/ws/server.go @@ -19,7 +19,6 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi. return &render.ProtoServer{ Server: parent, Type: baseServer, - ProtoName: pb.ProtoName, }, nil } diff --git a/internal/common/promise.go b/internal/common/promise.go index 2d14711..5930e77 100644 --- a/internal/common/promise.go +++ b/internal/common/promise.go @@ -12,12 +12,14 @@ type ObjectPromise interface { Assigned() bool Ref() string Origin() PromiseOrigin - FindCallback() func(item CompileObject, path []string) bool + FindCallback() PromiseFindCbFunc } type ObjectListPromise interface { AssignList(objs []any) Assigned() bool - FindCallback() func(item CompileObject, path []string) bool + FindCallback() PromiseFindCbFunc Ref() string } + +type PromiseFindCbFunc func(item CompileObject, path []string) bool diff --git a/internal/render/amqp/channel.go b/internal/render/amqp/channel.go index d2fe437..68188f2 100644 --- a/internal/render/amqp/channel.go +++ b/internal/render/amqp/channel.go @@ -5,7 +5,7 @@ package amqp //} //func (pc ProtoChannel) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // // var res []*j.Statement @@ -26,7 +26,7 @@ package amqp //} //func (pc ProtoChannel) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // return pc.Type.U(ctx) //} @@ -40,7 +40,7 @@ package amqp //} //func (pc ProtoChannel) renderNewFunc(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderNewFunc", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderNewFunc", "proto", pc.Protocol) // return []*j.Statement{ // // NewChannel1Proto(params Channel1Parameters, publisher proto.Publisher, subscriber proto.Subscriber) *Channel1Proto // j.Func().Id(pc.Type.NewFuncName()). @@ -49,10 +49,10 @@ package amqp // g.Id("params").Add(utils.ToCode(pc.Parent.ParametersType.U(ctx))...) // } // if pc.Parent.Publisher { -// g.Id("publisher").Qual(ctx.RuntimeModule(pc.ProtoName), "Publisher") +// g.Id("publisher").Qual(ctx.RuntimeModule(pc.Protocol), "Publisher") // } // if pc.Parent.Subscriber { -// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.ProtoName), "Subscriber") +// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.Protocol), "Subscriber") // } // }). // Op("*").Add(utils.ToCode(pc.Type.U(ctx))...). @@ -76,7 +76,7 @@ package amqp // utils.ToCode(pc.Parent.BindingsType.U(ctx))..., // ).Values().Dot(pc.ProtoTitle).Call() // bg.Switch(j.Id("bindings.ChannelType")).BlockFunc(func(bg2 *j.Group) { -// bg2.Case(j.Qual(ctx.RuntimeModule(pc.ProtoName), "ChannelTypeQueue")).Block( +// bg2.Case(j.Qual(ctx.RuntimeModule(pc.Protocol), "ChannelTypeQueue")).Block( // j.Id("res.queue").Op("=").Op("res.name.String()"), // ) // bg2.Default().Block( @@ -97,7 +97,7 @@ package amqp //} //func (pc ProtoChannel) renderProtoMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderProtoMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderProtoMethods", "proto", pc.Protocol) // rn := pc.Type.ReceiverName() // receiver := j.Id(rn).Id(pc.Type.GetOriginalName) // @@ -129,7 +129,7 @@ package amqp //} //func (pc ProtoChannel) renderProtoPublisherMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.Protocol) // rn := pc.Type.ReceiverName() // receiver := j.Id(rn).Id(pc.Type.GetOriginalName) // @@ -142,7 +142,7 @@ package amqp // // Method SealEnvelope(envelope proto.EnvelopeWriter, message *Message1Out) error // j.Func().Params(receiver.Clone()).Id("SealEnvelope"). // ParamsFunc(func(g *j.Group) { -// g.Id("envelope").Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeWriter") +// g.Id("envelope").Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeWriter") // g.Id("message").Add(utils.ToCode(msgTyp.U(ctx))...) // }). // Error(). @@ -156,13 +156,13 @@ package amqp // }`)) // } else { // Message is set for Channel in spec // bg.Op(` -// if err := message.MarshalAMQPEnvelope(envelope); err != nil { +// if err := message.MarshalEnvelopeAMQP(envelope); err != nil { // return err // }`) // } // bg.Id("envelope").Dot("SetRoutingKey").Call(j.Id(rn).Dot("routingKey")) // // Message SetBindings -// if pc.PublisherMessageTypePromise != nil && pc.PublisherMessageTypePromise.Target().HasProtoBindings(pc.ProtoName) { +// if pc.PublisherMessageTypePromise != nil && pc.PublisherMessageTypePromise.Target().HasProtoBindings(pc.Protocol) { // bg.Op("envelope.SetBindings").Call( // j.Add(utils.ToCode(pc.PublisherMessageTypePromise.Target().BindingsType.U(ctx))...).Values().Dot(pc.ProtoTitle).Call(), // ) diff --git a/internal/render/amqp/server.go b/internal/render/amqp/server.go index dea9d86..102cedc 100644 --- a/internal/render/amqp/server.go +++ b/internal/render/amqp/server.go @@ -4,7 +4,7 @@ package amqp // *render.Server // Type *lang.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (ps ProtoServer) Selectable() bool { @@ -12,7 +12,7 @@ package amqp //} //func (ps ProtoServer) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // // var res []*j.Statement @@ -26,7 +26,7 @@ package amqp //} //func (ps ProtoServer) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // return ps.Type.U(ctx) //} @@ -40,12 +40,12 @@ package amqp //} //func (ps ProtoServer) renderChannelMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderChannelMethods", "proto", ps.ProtoName) +// ctx.Logger.Trace("renderChannelMethods", "proto", ps.Protocol) // // var res []*j.Statement // // for _, ch := range ps.Parent.GetRelevantChannels() { -// protoChan := ch.AllProtoChannels[ps.ProtoName].(*ProtoChannel) +// protoChan := ch.AllProtoChannels[ps.Protocol].(*ProtoChannel) // res = append(res, // ps.RenderOpenChannelMethod(ctx, protoChan.Type, protoChan, protoChan.Parent.ParametersType)..., // ) diff --git a/internal/render/asyncapi.go b/internal/render/asyncapi.go index e05a170..4cc3f3f 100644 --- a/internal/render/asyncapi.go +++ b/internal/render/asyncapi.go @@ -2,14 +2,12 @@ package render import ( "github.com/bdragon300/go-asyncapi/internal/common" - "github.com/bdragon300/go-asyncapi/internal/render/lang" "github.com/samber/lo" ) const fallbackContentType = "application/json" // Default content type if it omitted in spec type AsyncAPI struct { - AllMessages *lang.ListPromise[*Message] DefaultContentType string } diff --git a/internal/render/channel.go b/internal/render/channel.go index 54480e4..2123b5d 100644 --- a/internal/render/channel.go +++ b/internal/render/channel.go @@ -8,10 +8,10 @@ import ( ) type Channel struct { - OriginalName string // Channel name, typically equals to Channel key, can get overridden in x-go-name - Dummy bool - SpecServerNames []string // List of servers the channel is linked with. Empty means "all servers" - ServersPromise *lang.ListPromise[*Server] // Servers list this channel is applied to, either explicitly marked or "all servers" + OriginalName string // Channel name, typically equals to Channel key, can get overridden in x-go-name + Dummy bool + BoundServerNames []string // List of servers the channel is linked with. Empty list means "all servers" + ServersPromise *lang.ListPromise[*Server] // Servers list this channel is bound with. Empty list means "no servers bound". IsPublisher bool // true if channel has `publish` operation IsSubscriber bool // true if channel has `subscribe` operation @@ -133,7 +133,7 @@ func (c *Channel) String() string { func (c *Channel) SelectProtoObject(protocol string) common.Renderable { res := lo.Filter(c.ProtoChannels, func(p *ProtoChannel, _ int) bool { - return p.Selectable() && p.ProtoName == protocol + return p.Selectable() && p.Protocol == protocol }) if len(res) > 0 { return res[0] @@ -222,7 +222,7 @@ type ProtoChannel struct { *Channel Type *lang.GoStruct - ProtoName string + Protocol string } func (p *ProtoChannel) Selectable() bool { @@ -238,7 +238,7 @@ func (p *ProtoChannel) isBound() bool { protos := lo.Map(p.ServersPromise.T(), func(s *Server, _ int) string { return s.Protocol }) r := lo.Contains( protos, - p.ProtoName, + p.Protocol, ) return r } diff --git a/internal/render/http/channel.go b/internal/render/http/channel.go index 51d96ed..5712500 100644 --- a/internal/render/http/channel.go +++ b/internal/render/http/channel.go @@ -5,7 +5,7 @@ package http // GolangNameProto string // Channel TypeNamePrefix name concatenated with protocol name, e.g. Channel1Kafka // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} //func (pc ProtoChannel) Selectable() bool { @@ -13,7 +13,7 @@ package http //} //func (pc ProtoChannel) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, pc.ServerIface.D(ctx)...) @@ -33,7 +33,7 @@ package http //} //func (pc ProtoChannel) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // return pc.Type.U(ctx) //} @@ -47,7 +47,7 @@ package http //} //func (pc ProtoChannel) renderNewFunc(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderNewFunc", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderNewFunc", "proto", pc.Protocol) // // return []*j.Statement{ // // NewChannel1Proto(params Channel1Parameters, publisher proto.Publisher, subscriber proto.Subscriber) *Channel1Proto @@ -57,10 +57,10 @@ package http // g.Id("params").Add(utils.ToCode(pc.Parent.ParametersType.U(ctx))...) // } // if pc.Parent.Publisher { -// g.Id("publisher").Qual(ctx.RuntimeModule(pc.ProtoName), "Publisher") +// g.Id("publisher").Qual(ctx.RuntimeModule(pc.Protocol), "Publisher") // } // if pc.Parent.Subscriber { -// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.ProtoName), "Subscriber") +// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.Protocol), "Subscriber") // } // }). // Op("*").Add(utils.ToCode(pc.Type.U(ctx))...). @@ -88,7 +88,7 @@ package http //} //func (pc ProtoChannel) renderProtoPublisherMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.Protocol) // // rn := pc.Type.ReceiverName() // receiver := j.Id(rn).Id(pc.Type.GetOriginalName) @@ -102,7 +102,7 @@ package http // // Method SealEnvelope(envelope http.EnvelopeWriter, message *Message1Out) error // j.Func().Params(receiver.Clone()).Id("SealEnvelope"). // ParamsFunc(func(g *j.Group) { -// g.Id("envelope").Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeWriter") +// g.Id("envelope").Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeWriter") // g.Id("message").Add(utils.ToCode(msgTyp.U(ctx))...) // }). // Error(). @@ -116,12 +116,12 @@ package http // }`)) // } else { // Message is set for Channel in spec // bg.Op(` -// if err := message.MarshalHTTPEnvelope(envelope); err != nil { +// if err := message.MarshalEnvelopeHTTP(envelope); err != nil { // return err // }`) // } // // Message SetBindings -// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.ProtoName) { +// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.Protocol) { // bg.Op("envelope.SetBindings").Call( // j.Add(utils.ToCode(pc.Parent.PublisherMessageTypePromise.Target().BindingsType.U(ctx))...).Values().Dot(pc.ProtoTitle).Call(), // ) diff --git a/internal/render/http/server.go b/internal/render/http/server.go index 3e0cc9b..d84469a 100644 --- a/internal/render/http/server.go +++ b/internal/render/http/server.go @@ -4,7 +4,7 @@ package http // Parent *render.Server // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (ps ProtoServer) Selectable() bool { @@ -12,7 +12,7 @@ package http //} // //func (ps ProtoServer) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, ps.RenderNewFunc(ctx)...) @@ -25,7 +25,7 @@ package http //} // //func (ps ProtoServer) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // return ps.Type.U(ctx) //} @@ -39,12 +39,12 @@ package http //} //func (ps ProtoServer) renderChannelMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderChannelMethods", "proto", ps.ProtoName) +// ctx.Logger.Trace("renderChannelMethods", "proto", ps.Protocol) // // var res []*j.Statement // // for _, ch := range ps.Parent.GetRelevantChannels() { -// protoChan := ch.AllProtoChannels[ps.ProtoName].(*ProtoChannel) +// protoChan := ch.AllProtoChannels[ps.Protocol].(*ProtoChannel) // res = append(res, // ps.RenderOpenChannelMethod(ctx, protoChan.Type, protoChan, protoChan.Parent.ParametersType)..., // ) diff --git a/internal/render/ip/channel.go b/internal/render/ip/channel.go index f6cb3fe..e8c4b0c 100644 --- a/internal/render/ip/channel.go +++ b/internal/render/ip/channel.go @@ -5,7 +5,7 @@ package ip // GolangNameProto string // Channel TypeNamePrefix name concatenated with protocol name, e.g. Channel1Kafka // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (pc ProtoChannel) Selectable() bool { @@ -13,7 +13,7 @@ package ip //} // //func (pc ProtoChannel) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, pc.ServerIface.D(ctx)...) @@ -33,7 +33,7 @@ package ip //} // //func (pc ProtoChannel) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // return pc.Type.U(ctx) //} @@ -47,7 +47,7 @@ package ip //} //func (pc ProtoChannel) renderNewFunc(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderNewFunc", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderNewFunc", "proto", pc.Protocol) // // return []*j.Statement{ // // NewChannel1Proto(params Channel1Parameters, publisher proto.Publisher, subscriber proto.Subscriber) *Channel1Proto @@ -57,10 +57,10 @@ package ip // g.Id("params").Add(utils.ToCode(pc.Parent.ParametersType.U(ctx))...) // } // if pc.Parent.Publisher { -// g.Id("publisher").Qual(ctx.RuntimeModule(pc.ProtoName), "Publisher") +// g.Id("publisher").Qual(ctx.RuntimeModule(pc.Protocol), "Publisher") // } // if pc.Parent.Subscriber { -// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.ProtoName), "Subscriber") +// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.Protocol), "Subscriber") // } // }). // Op("*").Add(utils.ToCode(pc.Type.U(ctx))...). @@ -88,7 +88,7 @@ package ip //} // //func (pc ProtoChannel) renderProtoPublisherMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.Protocol) // // rn := pc.Type.ReceiverName() // receiver := j.Id(rn).Id(pc.Type.GetOriginalName) @@ -102,7 +102,7 @@ package ip // // Method SealEnvelope(envelope proto.EnvelopeWriter, message *Message1Out) error // j.Func().Params(receiver.Clone()).Id("SealEnvelope"). // ParamsFunc(func(g *j.Group) { -// g.Id("envelope").Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeWriter") +// g.Id("envelope").Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeWriter") // g.Id("message").Add(utils.ToCode(msgTyp.U(ctx))...) // }). // Error(). @@ -116,12 +116,12 @@ package ip // }`)) // } else { // Message is set for Channel in spec // bg.Op(` -// if err := message.MarshalIPEnvelope(envelope); err != nil { +// if err := message.MarshalEnvelopeIP(envelope); err != nil { // return err // }`) // } // // Message SetBindings -// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.ProtoName) { +// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.Protocol) { // bg.Op("envelope.SetBindings").Call( // j.Add(utils.ToCode(pc.Parent.PublisherMessageTypePromise.Target().BindingsType.U(ctx))...).Values().Dot(pc.ProtoTitle).Call(), // ) diff --git a/internal/render/ip/server.go b/internal/render/ip/server.go index 93787d1..a699110 100644 --- a/internal/render/ip/server.go +++ b/internal/render/ip/server.go @@ -4,7 +4,7 @@ package ip // Parent *render.Server // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (ps ProtoServer) Selectable() bool { @@ -12,7 +12,7 @@ package ip //} // //func (ps ProtoServer) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, ps.RenderNewFunc(ctx)...) @@ -25,7 +25,7 @@ package ip //} //func (ps ProtoServer) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // return ps.Type.U(ctx) //} @@ -39,12 +39,12 @@ package ip //} // //func (ps ProtoServer) renderChannelMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderChannelMethods", "proto", ps.ProtoName) +// ctx.Logger.Trace("renderChannelMethods", "proto", ps.Protocol) // // var res []*j.Statement // // for _, ch := range ps.Parent.GetRelevantChannels() { -// protoChan := ch.AllProtoChannels[ps.ProtoName].(*ProtoChannel) +// protoChan := ch.AllProtoChannels[ps.Protocol].(*ProtoChannel) // res = append(res, // ps.RenderOpenChannelMethod(ctx, protoChan.Type, protoChan, protoChan.Parent.ParametersType)..., // ) diff --git a/internal/render/kafka/channel.go b/internal/render/kafka/channel.go index f8e42ff..c9a64a3 100644 --- a/internal/render/kafka/channel.go +++ b/internal/render/kafka/channel.go @@ -5,7 +5,7 @@ package kafka // GolangNameProto string // Channel TypeNamePrefix name concatenated with protocol name, e.g. Channel1Kafka // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (pc ProtoChannel) Selectable() bool { @@ -13,7 +13,7 @@ package kafka //} // //func (pc ProtoChannel) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, pc.ServerIface.D(ctx)...) @@ -33,7 +33,7 @@ package kafka //} //func (pc ProtoChannel) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // return pc.Type.U(ctx) //} @@ -47,7 +47,7 @@ package kafka //} //func (pc ProtoChannel) renderNewFunc(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderNewFunc", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderNewFunc", "proto", pc.Protocol) // // return []*j.Statement{ // // NewChannel1Proto(params Channel1Parameters, publisher proto.Publisher, subscriber proto.Subscriber) *Channel1Proto @@ -57,10 +57,10 @@ package kafka // g.Id("params").Add(utils.ToCode(pc.Parent.ParametersType.U(ctx))...) // } // if pc.Parent.Publisher { -// g.Id("publisher").Qual(ctx.RuntimeModule(pc.ProtoName), "Publisher") +// g.Id("publisher").Qual(ctx.RuntimeModule(pc.Protocol), "Publisher") // } // if pc.Parent.Subscriber { -// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.ProtoName), "Subscriber") +// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.Protocol), "Subscriber") // } // }). // Op("*").Add(utils.ToCode(pc.Type.U(ctx))...). @@ -92,7 +92,7 @@ package kafka //} //func (pc ProtoChannel) renderProtoMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderProtoMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderProtoMethods", "proto", pc.Protocol) // // rn := pc.Type.ReceiverName() // receiver := j.Id(rn).Id(pc.Type.GetOriginalName) @@ -109,7 +109,7 @@ package kafka //} //func (pc ProtoChannel) renderProtoPublisherMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.Protocol) // // rn := pc.Type.ReceiverName() // receiver := j.Id(rn).Id(pc.Type.GetOriginalName) @@ -123,7 +123,7 @@ package kafka // // Method SealEnvelope(envelope kafka.EnvelopeWriter, message *Message1Out) error // j.Func().Params(receiver.Clone()).Id("SealEnvelope"). // ParamsFunc(func(g *j.Group) { -// g.Id("envelope").Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeWriter") +// g.Id("envelope").Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeWriter") // g.Id("message").Add(utils.ToCode(msgTyp.U(ctx))...) // }). // Error(). @@ -137,13 +137,13 @@ package kafka // }`)) // } else { // Message is set for Channel in spec // bg.Op(` -// if err := message.MarshalKafkaEnvelope(envelope); err != nil { +// if err := message.MarshalEnvelopeKafka(envelope); err != nil { // return err // }`) // } // bg.Op("envelope.SetTopic").Call(j.Id(rn).Dot("topic")) // // Message SetBindings -// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.ProtoName) { +// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.Protocol) { // bg.Op("envelope.SetBindings").Call( // j.Add(utils.ToCode(pc.Parent.PublisherMessageTypePromise.Target().BindingsType.U(ctx))...).Values().Dot(pc.ProtoTitle).Call(), // ) diff --git a/internal/render/kafka/server.go b/internal/render/kafka/server.go index 8bf7e60..3fe0c96 100644 --- a/internal/render/kafka/server.go +++ b/internal/render/kafka/server.go @@ -4,7 +4,7 @@ package kafka // Parent *render.Server // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (ps ProtoServer) Selectable() bool { @@ -12,7 +12,7 @@ package kafka //} // //func (ps ProtoServer) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, ps.RenderNewFunc(ctx)...) @@ -25,7 +25,7 @@ package kafka //} // //func (ps ProtoServer) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // return ps.Type.U(ctx) //} @@ -39,12 +39,12 @@ package kafka //} // //func (ps ProtoServer) renderChannelMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderChannelMethods", "proto", ps.ProtoName) +// ctx.Logger.Trace("renderChannelMethods", "proto", ps.Protocol) // // var res []*j.Statement // // for _, ch := range ps.Parent.GetRelevantChannels() { -// protoChan := ch.AllProtoChannels[ps.ProtoName].(*ProtoChannel) +// protoChan := ch.AllProtoChannels[ps.Protocol].(*ProtoChannel) // res = append(res, // ps.RenderOpenChannelMethod(ctx, protoChan.Type, protoChan, protoChan.Parent.ParametersType)..., // ) diff --git a/internal/render/lang/promise.go b/internal/render/lang/promise.go index bc80b31..71f5c73 100644 --- a/internal/render/lang/promise.go +++ b/internal/render/lang/promise.go @@ -3,10 +3,19 @@ package lang import ( "fmt" "github.com/bdragon300/go-asyncapi/internal/common" - "github.com/bdragon300/go-asyncapi/internal/utils" "github.com/samber/lo" ) +type promiseAssignCbFunc[T any] func(obj any) T + +func NewPromise[T any](ref string) *Promise[T] { + return newAssignCbPromise(ref, common.PromiseOriginInternal, nil, defaultAssignCb[T]) +} + +func NewCbPromise[T any](findCb common.PromiseFindCbFunc, assignCb promiseAssignCbFunc[T]) *Promise[T] { + return newAssignCbPromise("", common.PromiseOriginInternal, findCb, assignCb) +} + func defaultAssignCb[T any](obj any) T { t, ok := obj.(T) if !ok { @@ -15,28 +24,23 @@ func defaultAssignCb[T any](obj any) T { return t } -func newPromise[T any](ref string, origin common.PromiseOrigin) *Promise[T] { - return &Promise[T]{ref: ref, origin: origin} +func newAssignCbPromise[T any]( + ref string, + origin common.PromiseOrigin, + findCb common.PromiseFindCbFunc, + assignCb promiseAssignCbFunc[T], +) *Promise[T] { + return &Promise[T]{ref: ref, origin: origin, findCb: findCb, assignCb: assignCb} } -func newAssignCbPromise[T any](ref string, origin common.PromiseOrigin, assignCb func(obj any) T) *Promise[T] { - return &Promise[T]{ref: ref, origin: origin, assignCb: assignCb} -} - -func NewInternalPromise[T any](ref string) *Promise[T] { - return &Promise[T]{ref: ref, origin: common.PromiseOriginInternal, assignCb: defaultAssignCb[T]} -} +type Promise[T any] struct{ + // AssignErrorNote is the optional error message additional note to be shown to user when assignment fails + AssignErrorNote string -func NewInternalCbPromise[T any](findCb func(item common.CompileObject, path []string) bool) *Promise[T] { - return &Promise[T]{origin: common.PromiseOriginInternal, findCb: findCb} -} - -type Promise[T any] struct { - AssignErrorNote string // Optional error message additional note to be shown when assignment fails ref string - origin common.PromiseOrigin - findCb func(item common.CompileObject, path []string) bool - assignCb func(obj any) T + origin common.PromiseOrigin + findCb common.PromiseFindCbFunc + assignCb promiseAssignCbFunc[T] target T assigned bool @@ -72,7 +76,7 @@ func (r *Promise[T]) Origin() common.PromiseOrigin { return r.origin } -func (r *Promise[T]) FindCallback() func(item common.CompileObject, path []string) bool { +func (r *Promise[T]) FindCallback() common.PromiseFindCbFunc { return r.findCb } @@ -107,14 +111,16 @@ func (r *Promise[T]) IsStruct() bool { return false } -func NewListCbPromise[T any](findCb func(item common.CompileObject, path []string) bool) *ListPromise[T] { +func NewListCbPromise[T any](findCb common.PromiseFindCbFunc) *ListPromise[T] { return &ListPromise[T]{findCb: findCb} } type ListPromise[T any] struct { - AssignErrorNote string // Optional error message additional note to be shown when assignment fails - ref string - findCb func(item common.CompileObject, path []string) bool + // AssignErrorNote is the optional error message additional note to be shown to user when assignment fails + AssignErrorNote string + + ref string + findCb common.PromiseFindCbFunc targets []T assigned bool @@ -133,7 +139,7 @@ func (r *ListPromise[T]) Assigned() bool { return r.assigned } -func (r *ListPromise[T]) FindCallback() func(item common.CompileObject, path []string) bool { +func (r *ListPromise[T]) FindCallback() common.PromiseFindCbFunc { return r.findCb } @@ -145,57 +151,15 @@ func (r *ListPromise[T]) Ref() string { return r.ref } -func NewUserPromise(ref string, name string, selectable *bool) *RenderablePromise { - return &RenderablePromise{ - Promise: *newPromise[common.Renderable](ref, common.PromiseOriginUser), - selectable: selectable, - name: name, - } -} - -type RenderablePromise struct { - Promise[common.Renderable] - selectable *bool - name string -} - -func (r *RenderablePromise) Kind() common.ObjectKind { - return r.target.Kind() -} - -func (r *RenderablePromise) Selectable() bool { - if r.selectable == nil { - return r.origin == common.PromiseOriginUser && r.target.Selectable() - } - return r.origin == common.PromiseOriginUser && *r.selectable -} - -func (r *RenderablePromise) Visible() bool { - return r.origin == common.PromiseOriginUser && r.target.Visible() -} - -func (r *RenderablePromise) String() string { - return "RenderablePromise -> " + r.ref -} - -func (r *RenderablePromise) Name() string { - n, _ := lo.Coalesce(utils.CapitalizeUnchanged(r.name), r.target.Name()) - return n -} - -func (r *RenderablePromise) UnwrapRenderable() common.Renderable { - return unwrapRenderablePromise(r.target) -} - -func NewInternalGolangTypePromise(ref string) *GolangTypePromise { +func NewGolangTypePromise(ref string) *GolangTypePromise { return &GolangTypePromise{ - Promise: *newPromise[common.GolangType](ref, common.PromiseOriginInternal), + Promise: *newAssignCbPromise[common.GolangType](ref, common.PromiseOriginInternal, nil, nil), } } -func NewInternalGolangTypeAssignCbPromise(ref string, assignCb func(obj any) common.GolangType) *GolangTypePromise { +func NewGolangTypeAssignCbPromise(ref string, findCb common.PromiseFindCbFunc, assignCb promiseAssignCbFunc[common.GolangType]) *GolangTypePromise { return &GolangTypePromise{ - Promise: *newAssignCbPromise[common.GolangType](ref, common.PromiseOriginInternal, assignCb), + Promise: *newAssignCbPromise[common.GolangType](ref, common.PromiseOriginInternal, findCb, assignCb), } } @@ -224,7 +188,7 @@ func (r *GolangTypePromise) UnwrapGolangType() common.GolangType { } func (r *GolangTypePromise) UnwrapRenderable() common.Renderable { - return unwrapRenderablePromise(r.target) + return unwrapRenderablePromiseOrRef(r.target) } func (r *GolangTypePromise) IsPointer() bool { @@ -239,7 +203,7 @@ func (r *GolangTypePromise) String() string { return "GolangTypePromise -> " + r.ref } -func unwrapRenderablePromise(val common.Renderable) common.Renderable { +func unwrapRenderablePromiseOrRef(val common.Renderable) common.Renderable { type renderableUnwrapper interface { UnwrapRenderable() common.Renderable } @@ -250,7 +214,6 @@ func unwrapRenderablePromise(val common.Renderable) common.Renderable { return val } - func unwrapGolangPromise(val common.GolangType) common.GolangType { type golangTypeUnwrapper interface { UnwrapGolangType() common.GolangType @@ -260,4 +223,4 @@ func unwrapGolangPromise(val common.GolangType) common.GolangType { val = o.UnwrapGolangType() } return val -} \ No newline at end of file +} diff --git a/internal/render/lang/ref.go b/internal/render/lang/ref.go new file mode 100644 index 0000000..a0eb6df --- /dev/null +++ b/internal/render/lang/ref.go @@ -0,0 +1,50 @@ +package lang + +import ( + "github.com/bdragon300/go-asyncapi/internal/common" + "github.com/bdragon300/go-asyncapi/internal/utils" + "github.com/samber/lo" +) + +func NewRef(ref string, name string, selectable *bool) *Ref { + return &Ref{ + Promise: *newAssignCbPromise[common.Renderable](ref, common.PromiseOriginUser, nil, nil), + selectable: selectable, + name: name, + } +} + +type Ref struct { + Promise[common.Renderable] + selectable *bool + name string +} + +func (r *Ref) Kind() common.ObjectKind { + return r.target.Kind() +} + +func (r *Ref) Selectable() bool { + if r.selectable == nil { + return r.origin == common.PromiseOriginUser && r.target.Selectable() + } + return r.origin == common.PromiseOriginUser && *r.selectable +} + +func (r *Ref) Visible() bool { + return r.origin == common.PromiseOriginUser && r.target.Visible() +} + +func (r *Ref) String() string { + return "Ref -> " + r.ref +} + +func (r *Ref) Name() string { + n, _ := lo.Coalesce(utils.CapitalizeUnchanged(r.name), r.target.Name()) + return n +} + +func (r *Ref) UnwrapRenderable() common.Renderable { + return unwrapRenderablePromiseOrRef(r.target) +} + diff --git a/internal/render/message.go b/internal/render/message.go index 8123dc7..a8aab57 100644 --- a/internal/render/message.go +++ b/internal/render/message.go @@ -17,7 +17,7 @@ type Message struct { HeadersFallbackType *lang.GoMap HeadersTypePromise *lang.Promise[*lang.GoStruct] - AllServersPromise *lang.ListPromise[*Server] // For extracting all using protocols + AllServersPromise *lang.ListPromise[*Server] // All servers we know about BindingsType *lang.GoStruct // nil if message bindings are not defined for message BindingsPromise *lang.Promise[*Bindings] // nil if message bindings are not defined for message as well @@ -44,7 +44,7 @@ func (m *Message) Visible() bool { func (m *Message) SelectProtoObject(protocol string) common.Renderable { objects := lo.Filter(m.ProtoMessages, func(p *ProtoMessage, _ int) bool { - return p.Selectable() && p.ProtoName == protocol + return p.Selectable() && p.Protocol == protocol }) return lo.FirstOr(objects, nil) } @@ -189,7 +189,7 @@ func (m *Message) ProtoBindingsValue(protoName string) common.Renderable { // receiver := j.Id(rn).Op("*").Id(m.OutType.GetOriginalName) // // return []*j.Statement{ -// // Method MarshalProtoEnvelope(envelope proto.EnvelopeWriter) error +// // Method MarshalEnvelopeProto(envelope proto.EnvelopeWriter) error // j.Func().Params(receiver.Clone()).Id("Marshal" + protoTitle + "Envelope"). // Params(j.Id("envelope").Qual(ctx.RuntimeModule(protoName), "EnvelopeWriter")). // Error(). @@ -280,7 +280,7 @@ func (m *Message) ProtoBindingsValue(protoName string) common.Renderable { // receiver := j.Id(rn).Op("*").Id(m.InType.GetOriginalName) // // return []*j.Statement{ -// // Method UnmarshalProtoEnvelope(envelope proto.EnvelopeReader) error +// // Method UnmarshalEnvelopeProto(envelope proto.EnvelopeReader) error // j.Func().Params(receiver.Clone()).Id("Unmarshal" + protoTitle + "Envelope"). // Params(j.Id("envelope").Qual(ctx.RuntimeModule(protoName), "EnvelopeReader")). // Error(). @@ -327,7 +327,7 @@ func (m *Message) ProtoBindingsValue(protoName string) common.Renderable { type ProtoMessage struct { *Message - ProtoName string + Protocol string } func (p *ProtoMessage) Selectable() bool { @@ -343,6 +343,6 @@ func (p *ProtoMessage) String() string { func (p *ProtoMessage) isBound() bool { return lo.Contains( lo.Map(p.AllServersPromise.T(), func(s *Server, _ int) string { return s.Protocol }), - p.ProtoName, + p.Protocol, ) } \ No newline at end of file diff --git a/internal/render/mqtt/channel.go b/internal/render/mqtt/channel.go index 2402572..16af999 100644 --- a/internal/render/mqtt/channel.go +++ b/internal/render/mqtt/channel.go @@ -5,7 +5,7 @@ package mqtt // GolangNameProto string // Channel TypeNamePrefix name concatenated with protocol name, e.g. Channel1Kafka // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (pc ProtoChannel) Selectable() bool { @@ -13,7 +13,7 @@ package mqtt //} // //func (pc ProtoChannel) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, pc.ServerIface.D(ctx)...) @@ -33,7 +33,7 @@ package mqtt //} // //func (pc ProtoChannel) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // return pc.Type.U(ctx) //} @@ -47,7 +47,7 @@ package mqtt //} //func (pc ProtoChannel) renderNewFunc(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderNewFunc", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderNewFunc", "proto", pc.Protocol) // // return []*j.Statement{ // // NewChannel1Proto(params Channel1Parameters, publisher proto.Publisher, subscriber proto.Subscriber) *Channel1Proto @@ -57,10 +57,10 @@ package mqtt // g.Id("params").Add(utils.ToCode(pc.Parent.ParametersType.U(ctx))...) // } // if pc.Parent.Publisher { -// g.Id("publisher").Qual(ctx.RuntimeModule(pc.ProtoName), "Publisher") +// g.Id("publisher").Qual(ctx.RuntimeModule(pc.Protocol), "Publisher") // } // if pc.Parent.Subscriber { -// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.ProtoName), "Subscriber") +// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.Protocol), "Subscriber") // } // }). // Op("*").Add(utils.ToCode(pc.Type.U(ctx))...). @@ -85,7 +85,7 @@ package mqtt //} //func (pc ProtoChannel) renderProtoMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderProtoMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderProtoMethods", "proto", pc.Protocol) // // rn := pc.Type.ReceiverName() // receiver := j.Id(rn).Id(pc.Type.GetOriginalName) @@ -102,7 +102,7 @@ package mqtt //} //func (pc ProtoChannel) renderProtoPublisherMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.Protocol) // // rn := pc.Type.ReceiverName() // receiver := j.Id(rn).Id(pc.Type.GetOriginalName) @@ -116,7 +116,7 @@ package mqtt // // Method SealEnvelope(envelope proto.EnvelopeWriter, message *Message1Out) error // j.Func().Params(receiver.Clone()).Id("SealEnvelope"). // ParamsFunc(func(g *j.Group) { -// g.Id("envelope").Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeWriter") +// g.Id("envelope").Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeWriter") // g.Id("message").Add(utils.ToCode(msgTyp.U(ctx))...) // }). // Error(). @@ -130,13 +130,13 @@ package mqtt // }`)) // } else { // Message is set for Channel in spec // bg.Op(` -// if err := message.MarshalMQTTEnvelope(envelope); err != nil { +// if err := message.MarshalEnvelopeMQTT(envelope); err != nil { // return err // }`) // } // bg.Op("envelope.SetTopic").Call(j.Id(rn).Dot("topic")) // // Message SetBindings -// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.ProtoName) { +// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.Protocol) { // bg.Op("envelope.SetBindings").Call( // j.Add(utils.ToCode(pc.Parent.PublisherMessageTypePromise.Target().BindingsType.U(ctx))...).Values().Dot(pc.ProtoTitle).Call(), // ) diff --git a/internal/render/mqtt/server.go b/internal/render/mqtt/server.go index 4a8f981..09f8efe 100644 --- a/internal/render/mqtt/server.go +++ b/internal/render/mqtt/server.go @@ -4,7 +4,7 @@ package mqtt // Parent *render.Server // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (ps ProtoServer) Selectable() bool { @@ -12,7 +12,7 @@ package mqtt //} // //func (ps ProtoServer) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, ps.RenderNewFunc(ctx)...) @@ -25,7 +25,7 @@ package mqtt //} // //func (ps ProtoServer) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // return ps.Type.U(ctx) //} @@ -39,12 +39,12 @@ package mqtt //} // //func (ps ProtoServer) renderChannelMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderChannelMethods", "proto", ps.ProtoName) +// ctx.Logger.Trace("renderChannelMethods", "proto", ps.Protocol) // // var res []*j.Statement // // for _, ch := range ps.Parent.GetRelevantChannels() { -// protoChan := ch.AllProtoChannels[ps.ProtoName].(*ProtoChannel) +// protoChan := ch.AllProtoChannels[ps.Protocol].(*ProtoChannel) // res = append(res, // ps.RenderOpenChannelMethod(ctx, protoChan.Type, protoChan, protoChan.Parent.ParametersType)..., // ) diff --git a/internal/render/proto/channel.go b/internal/render/proto/channel.go index cf499d8..38bfa5d 100644 --- a/internal/render/proto/channel.go +++ b/internal/render/proto/channel.go @@ -5,7 +5,7 @@ package proto // GolangNameProto string // Channel TypeNamePrefix name concatenated with protocol name, e.g. Channel1Kafka // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} @@ -16,11 +16,11 @@ package proto // Type *render.GoStruct // //ServerIface *render.GoInterface // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} //func (pc BaseProtoChannel) RenderCommonSubscriberMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("RenderCommonSubscriberMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("RenderCommonSubscriberMethods", "proto", pc.Protocol) // // rn := pc.Type.ReceiverName() // receiver := j.Id(rn).Id(pc.Type.GetOriginalName) @@ -33,7 +33,7 @@ package proto // // Method ExtractEnvelope(envelope proto.EnvelopeReader, message *Message1In) error // j.Func().Params(receiver.Clone()).Id("ExtractEnvelope"). // Params( -// j.Id("envelope").Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeReader"), +// j.Id("envelope").Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeReader"), // j.Id("message").Add(utils.ToCode(msgTyp.U(ctx))...), // ). // Error(). @@ -52,7 +52,7 @@ package proto // // Method Subscriber() proto.Subscriber // j.Func().Params(receiver.Clone()).Id("Subscriber"). // Params(). -// Qual(ctx.RuntimeModule(pc.ProtoName), "Subscriber"). +// Qual(ctx.RuntimeModule(pc.Protocol), "Subscriber"). // Block( // j.Return(j.Id(rn).Dot("subscriber")), // ), @@ -62,7 +62,7 @@ package proto // Params( // j.Id("ctx").Qual("context", "Context"), // // FIXME: *any on fallback variant -// j.Id("cb").Func().Params(j.Id("envelope").Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeReader")), +// j.Id("cb").Func().Params(j.Id("envelope").Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeReader")), // ). // Error(). // Block( @@ -72,7 +72,7 @@ package proto //} //func (pc BaseProtoChannel) RenderCommonPublisherMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("RenderCommonPublisherMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("RenderCommonPublisherMethods", "proto", pc.Protocol) // // rn := pc.Type.ReceiverName() // receiver := j.Id(rn).Id(pc.Type.GetOriginalName) @@ -81,7 +81,7 @@ package proto // // Method Publisher() proto.Publisher // j.Func().Params(receiver.Clone()).Id("Publisher"). // Params(). -// Qual(ctx.RuntimeModule(pc.ProtoName), "Publisher"). +// Qual(ctx.RuntimeModule(pc.Protocol), "Publisher"). // Block( // j.Return(j.Id(rn).Dot("publisher")), // ), @@ -90,7 +90,7 @@ package proto // j.Func().Params(receiver.Clone()).Id("Publish"). // Params( // j.Id("ctx").Qual("context", "Context"), -// j.Id("envelopes").Op("...").Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeWriter"), +// j.Id("envelopes").Op("...").Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeWriter"), // ). // Error(). // Block( @@ -100,7 +100,7 @@ package proto //} //func (pc BaseProtoChannel) RenderCommonMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("RenderCommonMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("RenderCommonMethods", "proto", pc.Protocol) // // rn := pc.Type.ReceiverName() // receiver := j.Id(rn).Id(pc.Type.GetOriginalName) @@ -135,7 +135,7 @@ package proto //} //func (pc BaseProtoChannel) RenderOpenFunc(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("RenderOpenFunc", "proto", pc.ProtoName) +// ctx.Logger.Trace("RenderOpenFunc", "proto", pc.Protocol) // // return []*j.Statement{ // // OpenChannel1Proto(ctx context.Context, params Channel1Parameters, servers ...channel1ProtoServer) (*Channel1Proto, error) @@ -160,10 +160,10 @@ package proto // bg.Id("bindings").Op(":=").Id(pc.Parent.BindingsType.GetOriginalName).Values().Dot(pc.ProtoTitle).Call() // } // if pc.Parent.Publisher { -// bg.Var().Id("prod").Index().Qual(ctx.RuntimeModule(pc.ProtoName), "Producer") +// bg.Var().Id("prod").Index().Qual(ctx.RuntimeModule(pc.Protocol), "Producer") // } // if pc.Parent.Subscriber { -// bg.Var().Id("cons").Index().Qual(ctx.RuntimeModule(pc.ProtoName), "Consumer") +// bg.Var().Id("cons").Index().Qual(ctx.RuntimeModule(pc.Protocol), "Consumer") // } // bg.Op("for _, srv := range servers").BlockFunc(func(g *j.Group) { // if pc.Parent.Publisher { @@ -184,9 +184,9 @@ package proto // bg.Op("pubs, err := "). // Qual(ctx.RuntimeModule(""), "GatherPublishers"). // Types( -// j.Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeWriter"), -// j.Qual(ctx.RuntimeModule(pc.ProtoName), "Publisher"), -// j.Qual(ctx.RuntimeModule(pc.ProtoName), "ChannelBindings"), +// j.Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeWriter"), +// j.Qual(ctx.RuntimeModule(pc.Protocol), "Publisher"), +// j.Qual(ctx.RuntimeModule(pc.Protocol), "ChannelBindings"), // ). // CallFunc(func(g *j.Group) { // g.Id("ctx") @@ -199,16 +199,16 @@ package proto // return nil, err // }`) // bg.Op("pub := ").Qual(ctx.RuntimeModule(""), "PublisherFanOut"). -// Types(j.Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeWriter"), j.Qual(ctx.RuntimeModule(pc.ProtoName), "Publisher")). +// Types(j.Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeWriter"), j.Qual(ctx.RuntimeModule(pc.Protocol), "Publisher")). // Op("{Publishers: pubs}") // } // if pc.Parent.Subscriber { // bg.Op("subs, err := "). // Qual(ctx.RuntimeModule(""), "GatherSubscribers"). // Types( -// j.Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeReader"), -// j.Qual(ctx.RuntimeModule(pc.ProtoName), "Subscriber"), -// j.Qual(ctx.RuntimeModule(pc.ProtoName), "ChannelBindings"), +// j.Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeReader"), +// j.Qual(ctx.RuntimeModule(pc.Protocol), "Subscriber"), +// j.Qual(ctx.RuntimeModule(pc.Protocol), "ChannelBindings"), // ). // CallFunc(func(g *j.Group) { // g.Id("ctx") @@ -223,7 +223,7 @@ package proto // g.Op("return nil, err") // }) // bg.Op("sub := ").Qual(ctx.RuntimeModule(""), "SubscriberFanIn"). -// Types(j.Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeReader"), j.Qual(ctx.RuntimeModule(pc.ProtoName), "Subscriber")). +// Types(j.Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeReader"), j.Qual(ctx.RuntimeModule(pc.Protocol), "Subscriber")). // Op("{Subscribers: subs}") // } // bg.Op("ch := ").Id(pc.Type.NewFuncName()).CallFunc(func(g *j.Group) { diff --git a/internal/render/proto/server.go b/internal/render/proto/server.go index ba9eb3d..ea1822b 100644 --- a/internal/render/proto/server.go +++ b/internal/render/proto/server.go @@ -4,18 +4,18 @@ package proto // Parent *render.Server // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} //func (ps BaseProtoServer) RenderNewFunc(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("RenderNewFunc", "proto", ps.ProtoName) +// ctx.Logger.Trace("RenderNewFunc", "proto", ps.Protocol) // // return []*j.Statement{ // // NewServer1(producer proto.Producer, consumer proto.Consumer) *Server1 // j.Func().Id(ps.Type.NewFuncName()). // ParamsFunc(func(g *j.Group) { -// g.Id("producer").Qual(ctx.RuntimeModule(ps.ProtoName), "Producer") -// g.Id("consumer").Qual(ctx.RuntimeModule(ps.ProtoName), "Consumer") +// g.Id("producer").Qual(ctx.RuntimeModule(ps.Protocol), "Producer") +// g.Id("consumer").Qual(ctx.RuntimeModule(ps.Protocol), "Consumer") // }). // Op("*").Add(utils.ToCode(ps.Type.U(ctx))...). // Block( @@ -28,7 +28,7 @@ package proto //} //func (ps BaseProtoServer) RenderCommonMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("RenderCommonMethods", "proto", ps.ProtoName) +// ctx.Logger.Trace("RenderCommonMethods", "proto", ps.Protocol) // // receiver := j.Id(ps.Type.ReceiverName()).Id(ps.Type.GetOriginalName) // @@ -44,7 +44,7 @@ package proto //} //func (ps BaseProtoServer) RenderOpenChannelMethod(ctx *common.RenderContext, channelStruct *render.GoStruct, channel common.Renderer, channelParametersStructNoRender *render.GoStruct) []*j.Statement { -// ctx.Logger.Trace("RenderOpenChannelMethod", "proto", ps.ProtoName) +// ctx.Logger.Trace("RenderOpenChannelMethod", "proto", ps.Protocol) // // rn := ps.Type.ReceiverName() // receiver := j.Id(rn).Id(ps.Type.GetOriginalName) @@ -72,7 +72,7 @@ package proto //} //func (ps BaseProtoServer) RenderProducerMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("RenderProducerMethods", "proto", ps.ProtoName) +// ctx.Logger.Trace("RenderProducerMethods", "proto", ps.Protocol) // // rn := ps.Type.ReceiverName() // receiver := j.Id(rn).Id(ps.Type.GetOriginalName) @@ -81,7 +81,7 @@ package proto // // Method Producer() proto.Producer // j.Func().Params(receiver.Clone()).Id("Producer"). // Params(). -// Qual(ctx.RuntimeModule(ps.ProtoName), "Producer"). +// Qual(ctx.RuntimeModule(ps.Protocol), "Producer"). // Block( // j.Return(j.Id(rn).Dot("producer")), // ), @@ -89,7 +89,7 @@ package proto //} //func (ps BaseProtoServer) RenderConsumerMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("RenderConsumerMethods", "proto", ps.ProtoName) +// ctx.Logger.Trace("RenderConsumerMethods", "proto", ps.Protocol) // // rn := ps.Type.ReceiverName() // receiver := j.Id(rn).Id(ps.Type.GetOriginalName) @@ -98,7 +98,7 @@ package proto // // Method Consumer() proto.Consumer // j.Func().Params(receiver.Clone()).Id("Consumer"). // Params(). -// Qual(ctx.RuntimeModule(ps.ProtoName), "Consumer"). +// Qual(ctx.RuntimeModule(ps.Protocol), "Consumer"). // Block( // j.Return(j.Id(rn).Dot("consumer")), // ), diff --git a/internal/render/redis/channel.go b/internal/render/redis/channel.go index 9ab98f6..26d7907 100644 --- a/internal/render/redis/channel.go +++ b/internal/render/redis/channel.go @@ -5,7 +5,7 @@ package redis // GolangNameProto string // Channel TypeNamePrefix name concatenated with protocol name, e.g. Channel1Kafka // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (pc ProtoChannel) Selectable() bool { @@ -13,7 +13,7 @@ package redis //} // //func (pc ProtoChannel) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, pc.ServerIface.D(ctx)...) @@ -33,7 +33,7 @@ package redis //} // //func (pc ProtoChannel) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // return pc.Type.U(ctx) //} @@ -47,7 +47,7 @@ package redis //} //func (pc ProtoChannel) renderNewFunc(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderNewFunc", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderNewFunc", "proto", pc.Protocol) // // return []*j.Statement{ // // NewChannel1Proto(params Channel1Parameters, publisher proto.Publisher, subscriber proto.Subscriber) *Channel1Proto @@ -57,10 +57,10 @@ package redis // g.Id("params").Add(utils.ToCode(pc.Parent.ParametersType.U(ctx))...) // } // if pc.Parent.Publisher { -// g.Id("publisher").Qual(ctx.RuntimeModule(pc.ProtoName), "Publisher") +// g.Id("publisher").Qual(ctx.RuntimeModule(pc.Protocol), "Publisher") // } // if pc.Parent.Subscriber { -// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.ProtoName), "Subscriber") +// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.Protocol), "Subscriber") // } // }). // Op("*").Add(utils.ToCode(pc.Type.U(ctx))...). @@ -88,7 +88,7 @@ package redis //} //func (pc ProtoChannel) renderProtoPublisherMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.Protocol) // // rn := pc.Type.ReceiverName() // receiver := j.Id(rn).Id(pc.Type.GetOriginalName) @@ -102,7 +102,7 @@ package redis // // Method SealEnvelope(envelope proto.EnvelopeWriter, message *Message1Out) error // j.Func().Params(receiver.Clone()).Id("SealEnvelope"). // ParamsFunc(func(g *j.Group) { -// g.Id("envelope").Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeWriter") +// g.Id("envelope").Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeWriter") // g.Id("message").Add(utils.ToCode(msgTyp.U(ctx))...) // }). // Error(). @@ -116,12 +116,12 @@ package redis // }`)) // } else { // Message is set for Channel in spec // bg.Op(` -// if err := message.MarshalRedisEnvelope(envelope); err != nil { +// if err := message.MarshalEnvelopeRedis(envelope); err != nil { // return err // }`) // } // // Message SetBindings -// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.ProtoName) { +// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.Protocol) { // bg.Op("envelope.SetBindings").Call( // j.Add(utils.ToCode(pc.Parent.PublisherMessageTypePromise.Target().BindingsType.U(ctx))...).Values().Dot(pc.ProtoTitle).Call(), // ) diff --git a/internal/render/redis/server.go b/internal/render/redis/server.go index ad924d5..b80d28c 100644 --- a/internal/render/redis/server.go +++ b/internal/render/redis/server.go @@ -4,7 +4,7 @@ package redis // Parent *render.Server // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (ps ProtoServer) Selectable() bool { @@ -12,7 +12,7 @@ package redis //} // //func (ps ProtoServer) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, ps.RenderNewFunc(ctx)...) @@ -25,7 +25,7 @@ package redis //} // //func (ps ProtoServer) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // return ps.Type.U(ctx) //} @@ -39,12 +39,12 @@ package redis //} // //func (ps ProtoServer) renderChannelMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderChannelMethods", "proto", ps.ProtoName) +// ctx.Logger.Trace("renderChannelMethods", "proto", ps.Protocol) // // var res []*j.Statement // // for _, ch := range ps.Parent.GetRelevantChannels() { -// protoChan := ch.AllProtoChannels[ps.ProtoName].(*ProtoChannel) +// protoChan := ch.AllProtoChannels[ps.Protocol].(*ProtoChannel) // res = append(res, // ps.RenderOpenChannelMethod(ctx, protoChan.Type, protoChan, protoChan.Parent.ParametersType)..., // ) diff --git a/internal/render/server.go b/internal/render/server.go index b0793f0..ba30f5c 100644 --- a/internal/render/server.go +++ b/internal/render/server.go @@ -40,7 +40,7 @@ func (s *Server) Visible() bool { } func (s *Server) SelectProtoObject(protocol string) common.Renderable { - if s.ProtoServer.Selectable() && s.ProtoServer.ProtoName == protocol { + if s.ProtoServer.Selectable() && s.ProtoServer.Protocol == protocol { return s.ProtoServer } return nil @@ -65,7 +65,7 @@ func (s *Server) GetBoundChannels() []common.Renderable { } if ch, ok := r.(*Channel); ok { // Empty/omitted servers field in channel means "all servers" - return len(ch.SpecServerNames) == 0 || lo.Contains(ch.SpecServerNames, currentName) + return len(ch.BoundServerNames) == 0 || lo.Contains(ch.BoundServerNames, currentName) } return false }) @@ -75,7 +75,7 @@ func (s *Server) GetBoundChannels() []common.Renderable { //func (p *ProtoServer) GetBoundProtoChannels(protoName string) []*ProtoChannel { // channels := p.GetBoundChannels() // res := lo.FlatMap(channels, func(ch common.Renderable, _ int) []*ProtoChannel { -// return lo.Map(ch.SelectProtoObject([]string{p.ProtoName}), func(item common.Renderable, _ int) *ProtoChannel { +// return lo.Map(ch.SelectProtoObject([]string{p.Protocol}), func(item common.Renderable, _ int) *ProtoChannel { // return item.(*ProtoChannel) // }) // }) @@ -196,8 +196,6 @@ func (s *Server) ProtoBindingsValue(protoName string) common.Renderable { type ProtoServer struct { *Server Type *lang.GoStruct // Nil if server is dummy or has unsupported protocol - - ProtoName string // TODO: difference between ProtoName and Protocol? Maybe remove ProtoName? } func (p *ProtoServer) String() string { diff --git a/internal/render/tcp/channel.go b/internal/render/tcp/channel.go index 2a81224..6afeeda 100644 --- a/internal/render/tcp/channel.go +++ b/internal/render/tcp/channel.go @@ -5,7 +5,7 @@ package tcp // GolangNameProto string // Channel TypeNamePrefix name concatenated with protocol name, e.g. Channel1Kafka // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (pc ProtoChannel) Selectable() bool { @@ -13,7 +13,7 @@ package tcp //} // //func (pc ProtoChannel) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, pc.ServerIface.D(ctx)...) @@ -33,7 +33,7 @@ package tcp //} // //func (pc ProtoChannel) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // return pc.Type.U(ctx) //} @@ -43,11 +43,11 @@ package tcp //} // //func (pc ProtoChannel) String() string { -// return "TCP ProtoChannel " + pc.Parent.GetOriginalName // TODO: substitute ProtoName (everywhere) + remove copypaste everywhere +// return "TCP ProtoChannel " + pc.Parent.GetOriginalName // TODO: substitute Protocol (everywhere) + remove copypaste everywhere //} // //func (pc ProtoChannel) renderNewFunc(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderNewFunc", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderNewFunc", "proto", pc.Protocol) // // return []*j.Statement{ // // NewChannel1Proto(params Channel1Parameters, publisher proto.Publisher, subscriber proto.Subscriber) *Channel1Proto @@ -57,10 +57,10 @@ package tcp // g.Id("params").Add(utils.ToCode(pc.Parent.ParametersType.U(ctx))...) // } // if pc.Parent.Publisher { -// g.Id("publisher").Qual(ctx.RuntimeModule(pc.ProtoName), "Publisher") +// g.Id("publisher").Qual(ctx.RuntimeModule(pc.Protocol), "Publisher") // } // if pc.Parent.Subscriber { -// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.ProtoName), "Subscriber") +// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.Protocol), "Subscriber") // } // }). // Op("*").Add(utils.ToCode(pc.Type.U(ctx))...). @@ -88,7 +88,7 @@ package tcp //} // //func (pc ProtoChannel) renderProtoPublisherMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.Protocol) // // rn := pc.Type.ReceiverName() // receiver := j.Id(rn).Id(pc.Type.GetOriginalName) @@ -102,7 +102,7 @@ package tcp // // Method SealEnvelope(envelope proto.EnvelopeWriter, message *Message1Out) error // j.Func().Params(receiver.Clone()).Id("SealEnvelope"). // ParamsFunc(func(g *j.Group) { -// g.Id("envelope").Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeWriter") +// g.Id("envelope").Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeWriter") // g.Id("message").Add(utils.ToCode(msgTyp.U(ctx))...) // }). // Error(). @@ -115,14 +115,14 @@ package tcp // return err // }`)) // } else { // Message is set for Channel in spec -// // TODO: substitute ProtoName below (everywhere) +// // TODO: substitute Protocol below (everywhere) // bg.Op(` -// if err := message.MarshalTCPEnvelope(envelope); err != nil { +// if err := message.MarshalEnvelopeTCP(envelope); err != nil { // return err // }`) // } // // Message SetBindings -// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.ProtoName) { +// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.Protocol) { // bg.Op("envelope.SetBindings").Call( // j.Add(utils.ToCode(pc.Parent.PublisherMessageTypePromise.Target().BindingsType.U(ctx))...).Values().Dot(pc.ProtoTitle).Call(), // ) diff --git a/internal/render/tcp/server.go b/internal/render/tcp/server.go index 11548fd..2002e17 100644 --- a/internal/render/tcp/server.go +++ b/internal/render/tcp/server.go @@ -4,7 +4,7 @@ package tcp // Parent *render.Server // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (ps ProtoServer) Selectable() bool { @@ -12,7 +12,7 @@ package tcp //} // //func (ps ProtoServer) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, ps.RenderNewFunc(ctx)...) @@ -25,7 +25,7 @@ package tcp //} // //func (ps ProtoServer) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // return ps.Type.U(ctx) //} @@ -39,12 +39,12 @@ package tcp //} // //func (ps ProtoServer) renderChannelMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderChannelMethods", "proto", ps.ProtoName) +// ctx.Logger.Trace("renderChannelMethods", "proto", ps.Protocol) // // var res []*j.Statement // // for _, ch := range ps.Parent.GetRelevantChannels() { -// protoChan := ch.AllProtoChannels[ps.ProtoName].(*ProtoChannel) +// protoChan := ch.AllProtoChannels[ps.Protocol].(*ProtoChannel) // res = append(res, // ps.RenderOpenChannelMethod(ctx, protoChan.Type, protoChan, protoChan.Parent.ParametersType)..., // ) diff --git a/internal/render/udp/channel.go b/internal/render/udp/channel.go index 0c91bcb..b387292 100644 --- a/internal/render/udp/channel.go +++ b/internal/render/udp/channel.go @@ -5,7 +5,7 @@ package udp // GolangNameProto string // Channel TypeNamePrefix name concatenated with protocol name, e.g. Channel1Kafka // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (pc ProtoChannel) Selectable() bool { @@ -13,7 +13,7 @@ package udp //} // //func (pc ProtoChannel) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, pc.ServerIface.D(ctx)...) @@ -33,7 +33,7 @@ package udp //} // //func (pc ProtoChannel) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // return pc.Type.U(ctx) //} @@ -47,7 +47,7 @@ package udp //} // //func (pc ProtoChannel) renderNewFunc(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderNewFunc", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderNewFunc", "proto", pc.Protocol) // // return []*j.Statement{ // // NewChannel1Proto(params Channel1Parameters, publisher proto.Publisher, subscriber proto.Subscriber) *Channel1Proto @@ -57,10 +57,10 @@ package udp // g.Id("params").Add(utils.ToCode(pc.Parent.ParametersType.U(ctx))...) // } // if pc.Parent.Publisher { -// g.Id("publisher").Qual(ctx.RuntimeModule(pc.ProtoName), "Publisher") +// g.Id("publisher").Qual(ctx.RuntimeModule(pc.Protocol), "Publisher") // } // if pc.Parent.Subscriber { -// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.ProtoName), "Subscriber") +// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.Protocol), "Subscriber") // } // }). // Op("*").Add(utils.ToCode(pc.Type.U(ctx))...). @@ -88,7 +88,7 @@ package udp //} // //func (pc ProtoChannel) renderProtoPublisherMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.Protocol) // // rn := pc.Type.ReceiverName() // receiver := j.Id(rn).Id(pc.Type.GetOriginalName) @@ -102,7 +102,7 @@ package udp // // Method SealEnvelope(envelope proto.EnvelopeWriter, message *Message1Out) error // j.Func().Params(receiver.Clone()).Id("SealEnvelope"). // ParamsFunc(func(g *j.Group) { -// g.Id("envelope").Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeWriter") +// g.Id("envelope").Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeWriter") // g.Id("message").Add(utils.ToCode(msgTyp.U(ctx))...) // }). // Error(). @@ -116,12 +116,12 @@ package udp // }`)) // } else { // Message is set for Channel in spec // bg.Op(` -// if err := message.MarshalUDPEnvelope(envelope); err != nil { +// if err := message.MarshalEnvelopeUDP(envelope); err != nil { // return err // }`) // } // // Message SetBindings -// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.ProtoName) { +// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.Protocol) { // bg.Op("envelope.SetBindings").Call( // j.Add(utils.ToCode(pc.Parent.PublisherMessageTypePromise.Target().BindingsType.U(ctx))...).Values().Dot(pc.ProtoTitle).Call(), // ) diff --git a/internal/render/udp/server.go b/internal/render/udp/server.go index 6172f2e..d5fdf01 100644 --- a/internal/render/udp/server.go +++ b/internal/render/udp/server.go @@ -4,7 +4,7 @@ package udp // Parent *render.Server // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (ps ProtoServer) Selectable() bool { @@ -12,7 +12,7 @@ package udp //} // //func (ps ProtoServer) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, ps.RenderNewFunc(ctx)...) @@ -25,7 +25,7 @@ package udp //} // //func (ps ProtoServer) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // return ps.Type.U(ctx) //} @@ -39,12 +39,12 @@ package udp //} // //func (ps ProtoServer) renderChannelMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderChannelMethods", "proto", ps.ProtoName) +// ctx.Logger.Trace("renderChannelMethods", "proto", ps.Protocol) // // var res []*j.Statement // // for _, ch := range ps.Parent.GetRelevantChannels() { -// protoChan := ch.AllProtoChannels[ps.ProtoName].(*ProtoChannel) +// protoChan := ch.AllProtoChannels[ps.Protocol].(*ProtoChannel) // res = append(res, // ps.RenderOpenChannelMethod(ctx, protoChan.Type, protoChan, protoChan.Parent.ParametersType)..., // ) diff --git a/internal/render/ws/channel.go b/internal/render/ws/channel.go index 1285a0d..f64b644 100644 --- a/internal/render/ws/channel.go +++ b/internal/render/ws/channel.go @@ -5,7 +5,7 @@ package ws // GolangNameProto string // Channel TypeNamePrefix name concatenated with protocol name, e.g. Channel1Kafka // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (pc ProtoChannel) Selectable() bool { @@ -13,7 +13,7 @@ package ws //} // //func (pc ProtoChannel) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "definition", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, pc.ServerIface.D(ctx)...) @@ -33,7 +33,7 @@ package ws //} // //func (pc ProtoChannel) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.ProtoName) +// ctx.LogStartRender("Channel", "", pc.Parent.GetOriginalName, "usage", pc.Selectable(), "proto", pc.Protocol) // defer ctx.LogFinishRender() // return pc.Type.U(ctx) //} @@ -47,7 +47,7 @@ package ws //} // //func (pc ProtoChannel) renderNewFunc(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderNewFunc", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderNewFunc", "proto", pc.Protocol) // // return []*j.Statement{ // // NewChannel1Proto(params Channel1Parameters, publisher proto.Publisher, subscriber proto.Subscriber) *Channel1Proto @@ -57,10 +57,10 @@ package ws // g.Id("params").Add(utils.ToCode(pc.Parent.ParametersType.U(ctx))...) // } // if pc.Parent.Publisher { -// g.Id("publisher").Qual(ctx.RuntimeModule(pc.ProtoName), "Publisher") +// g.Id("publisher").Qual(ctx.RuntimeModule(pc.Protocol), "Publisher") // } // if pc.Parent.Subscriber { -// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.ProtoName), "Subscriber") +// g.Id("subscriber").Qual(ctx.RuntimeModule(pc.Protocol), "Subscriber") // } // }). // Op("*").Add(utils.ToCode(pc.Type.U(ctx))...). @@ -84,12 +84,12 @@ package ws //} // //func (pc ProtoChannel) renderProtoMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderProtoMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderProtoMethods", "proto", pc.Protocol) // return nil //} // //func (pc ProtoChannel) renderProtoPublisherMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.ProtoName) +// ctx.Logger.Trace("renderProtoPublisherMethods", "proto", pc.Protocol) // // rn := pc.Type.ReceiverName() // receiver := j.Id(rn).Id(pc.Type.GetOriginalName) @@ -103,7 +103,7 @@ package ws // // Method SealEnvelope(envelope proto.EnvelopeWriter, message *Message1Out) error // j.Func().Params(receiver.Clone()).Id("SealEnvelope"). // ParamsFunc(func(g *j.Group) { -// g.Id("envelope").Qual(ctx.RuntimeModule(pc.ProtoName), "EnvelopeWriter") +// g.Id("envelope").Qual(ctx.RuntimeModule(pc.Protocol), "EnvelopeWriter") // g.Id("message").Add(utils.ToCode(msgTyp.U(ctx))...) // }). // Error(). @@ -117,12 +117,12 @@ package ws // }`)) // } else { // Message is set for Channel in spec // bg.Op(` -// if err := message.MarshalWebSocketEnvelope(envelope); err != nil { +// if err := message.MarshalEnvelopeWs(envelope); err != nil { // return err // }`) // } // // Message SetBindings -// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.ProtoName) { +// if pc.Parent.PublisherMessageTypePromise != nil && pc.Parent.PublisherMessageTypePromise.Target().HasProtoBindings(pc.Protocol) { // bg.Op("envelope.SetBindings").Call( // j.Add(utils.ToCode(pc.Parent.PublisherMessageTypePromise.Target().BindingsType.U(ctx))...).Values().Dot("WS()"), // ) diff --git a/internal/render/ws/server.go b/internal/render/ws/server.go index 63a766c..89f3b82 100644 --- a/internal/render/ws/server.go +++ b/internal/render/ws/server.go @@ -4,7 +4,7 @@ package ws // Parent *render.Server // Type *render.GoStruct // -// ProtoName, ProtoTitle string +// Protocol, ProtoTitle string //} // //func (ps ProtoServer) Selectable() bool { @@ -12,7 +12,7 @@ package ws //} // //func (ps ProtoServer) D(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "definition", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // var res []*j.Statement // res = append(res, ps.RenderNewFunc(ctx)...) @@ -25,7 +25,7 @@ package ws //} // //func (ps ProtoServer) U(ctx *common.RenderContext) []*j.Statement { -// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.ProtoName) +// ctx.LogStartRender("Server", "", ps.Parent.GetOriginalName, "usage", ps.Selectable(), "proto", ps.Protocol) // defer ctx.LogFinishRender() // return ps.Type.U(ctx) //} @@ -39,12 +39,12 @@ package ws //} // //func (ps ProtoServer) renderChannelMethods(ctx *common.RenderContext) []*j.Statement { -// ctx.Logger.Trace("renderChannelMethods", "proto", ps.ProtoName) +// ctx.Logger.Trace("renderChannelMethods", "proto", ps.Protocol) // // var res []*j.Statement // // for _, ch := range ps.Parent.GetRelevantChannels() { -// protoChan := ch.AllProtoChannels[ps.ProtoName].(*ProtoChannel) +// protoChan := ch.AllProtoChannels[ps.Protocol].(*ProtoChannel) // res = append(res, // ps.RenderOpenChannelMethod(ctx, protoChan.Type, protoChan, protoChan.Parent.ParametersType)..., // ) diff --git a/templates/amqp/amqp_channel.tmpl b/templates/amqp/amqp_channel.tmpl index 3b0eaf5..06911c0 100644 --- a/templates/amqp/amqp_channel.tmpl +++ b/templates/amqp/amqp_channel.tmpl @@ -1,20 +1,20 @@ {{- localobj .Type}} {{template "proto/channel/openFunction" .}} -func New{{ .Channel | goid }}{{.ProtoName | capitalize | goid}}( +func New{{ .Channel | goid }}{{.Protocol | capitalize | goid}}( {{ if .ParametersType}}params {{ .ParametersType | gousage }},{{end}} - {{ if .IsPublisher}}publisher {{qualrun .ProtoName "Publisher"}},{{end}} - {{ if .IsSubscriber}}subscriber {{qualrun .ProtoName "Subscriber"}},{{end}} + {{ if .IsPublisher}}publisher {{qualrun .Protocol "Publisher"}},{{end}} + {{ if .IsSubscriber}}subscriber {{qualrun .Protocol "Subscriber"}},{{end}} ) *{{ .Type | gousage }} { res := {{ .Type | gousage }}{ name: {{ .Channel | goid }}Name({{if .ParametersType}}params{{end}}), {{if .IsPublisher}}publisher: publisher,{{end}} {{if .IsSubscriber}}subscriber: subscriber,{{end}} } - {{- if and .BindingsType (.BindingsProtocols | has .ProtoName)}} - bindings := {{ .BindingsType | gousage }}{}.{{.ProtoName | capitalize | goid}}() + {{- if and .BindingsType (.BindingsProtocols | has .Protocol)}} + bindings := {{ .BindingsType | gousage }}{}.{{.Protocol | capitalize | goid}}() switch bindings.ChannelType { - case {{qualrun .ProtoName "ChannelTypeQueue"}}: + case {{qualrun .Protocol "ChannelTypeQueue"}}: res.queue = res.name.String() default: res.routingKey = res.name.String() @@ -49,11 +49,11 @@ func (c {{ .Type | gousage }}) RoutingKey() string { {{- if .IsPublisher}} {{template "proto/channel/outputMethods" .}} - func (c {{ .Type | gousage }}) SealEnvelope(envelope {{qualrun .ProtoName "EnvelopeWriter"}}, message {{if .PublisherMessageTypePromise}}{{goptr .PublisherMessageTypePromise.T.OutType}}{{else}}any{{end}}) error { + func (c {{ .Type | gousage }}) SealEnvelope(envelope {{qualrun .Protocol "EnvelopeWriter"}}, message {{if .PublisherMessageTypePromise}}{{goptr .PublisherMessageTypePromise.T.OutType}}{{else}}any{{end}}) error { envelope.ResetPayload() {{- if .PublisherMessageTypePromise}} {{- /* Message is set for Channel in spec */}} - if err := message.Marshal{{.ProtoName | capitalize | goid}}Envelope(envelope); err != nil { + if err := message.MarshalEnvelope{{.Protocol | capitalize | goid}}(envelope); err != nil { return err } {{- else}} @@ -64,8 +64,8 @@ func (c {{ .Type | gousage }}) RoutingKey() string { } {{- end}} envelope.SetRoutingKey(c.RoutingKey()) - {{- if and .PublisherMessageTypePromise (.PublisherMessageTypePromise.T.BindingsProtocols | has .ProtoName)}} - envelope.SetBindings({{ .PublisherMessageTypePromise.T.BindingsType | gousage }}{}.{{.ProtoName | capitalize | goid}}()) + {{- if and .PublisherMessageTypePromise (.PublisherMessageTypePromise.T.BindingsProtocols | has .Protocol)}} + envelope.SetBindings({{ .PublisherMessageTypePromise.T.BindingsType | gousage }}{}.{{.Protocol | capitalize | goid}}()) {{- end}} return nil } @@ -75,7 +75,7 @@ func (c {{ .Type | gousage }}) RoutingKey() string { type {{ .Type | goid }}Server interface { Open{{.Type | goid}}(ctx {{qual "context.Context"}}, {{if .ParametersType}}params {{ .ParametersType | gousage }}{{end}}) (*{{ .Type | gousage }}, error) - {{if .IsPublisher}}Producer() {{qualrun .ProtoName "Producer"}}{{end}} - {{if .IsSubscriber}}Consumer() {{qualrun .ProtoName "Consumer"}}{{end}} + {{if .IsPublisher}}Producer() {{qualrun .Protocol "Producer"}}{{end}} + {{if .IsSubscriber}}Consumer() {{qualrun .Protocol "Consumer"}}{{end}} } {{- end}} diff --git a/templates/amqp/amqp_message.tmpl b/templates/amqp/amqp_message.tmpl index df2fc9e..699357e 100644 --- a/templates/amqp/amqp_message.tmpl +++ b/templates/amqp/amqp_message.tmpl @@ -1,6 +1,6 @@ {{- with deref .}} - {{- if gondefined (print "MessageMethods" .ProtoName (goid .))}} + {{- if gondefined (print "MessageMethods" .Protocol (goid .))}} {{template "proto/message/marshalUnmarshalMethods" deref .}} {{- end}} - {{- print "MessageMethods" .ProtoName (goid .) | def}} + {{- print "MessageMethods" .Protocol (goid .) | def}} {{- end}} \ No newline at end of file diff --git a/templates/amqp/amqp_server.tmpl b/templates/amqp/amqp_server.tmpl index 33c1ca1..eb6ced6 100644 --- a/templates/amqp/amqp_server.tmpl +++ b/templates/amqp/amqp_server.tmpl @@ -1,5 +1,5 @@ {{- localobj .Type }} -func New{{ .Server | goid }}(producer {{qualrun .ProtoName "Producer"}}, consumer {{qualrun .ProtoName "Consumer"}}) *{{ .Type | gousage }} { +func New{{ .Server | goid }}(producer {{qualrun .Protocol "Producer"}}, consumer {{qualrun .Protocol "Consumer"}}) *{{ .Type | gousage }} { return &{{ .Type | gousage }}{ producer: producer, consumer: consumer, @@ -12,22 +12,22 @@ func (s {{ .Type | gousage }}) Name() string { return "{{ . | goid }}" } -func (s {{ .Type | gousage }}) Producer() {{qualrun .ProtoName "Producer"}} { +func (s {{ .Type | gousage }}) Producer() {{qualrun .Protocol "Producer"}} { return s.producer } -func (s {{ .Type | gousage }}) Consumer() {{qualrun .ProtoName "Consumer"}} { +func (s {{ .Type | gousage }}) Consumer() {{qualrun .Protocol "Consumer"}} { return s.consumer } {{- range $ch := .GetBoundChannels}} {{- with deref .}} - {{- with .SelectProtoObject $.ProtoName }} + {{- with .SelectProtoObject $.Protocol }} func (s {{ $.Type | gousage }}) Open{{ $ch | goid }}( ctx {{qual "context.Context"}}, {{- if .ParametersType}}params {{ .ParametersType | gousage }},{{end}} ) (ch *{{ .Type | gousage }}, err error) { - return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.ProtoName | capitalize | goid }}( + return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.Protocol | capitalize | goid }}( ctx, {{- if .ParametersType}}params,{{end}} {{- if .IsPublisher}}s.producer,{{end}} diff --git a/templates/common/proto.tmpl b/templates/common/proto.tmpl index 8c130b1..de12a71 100644 --- a/templates/common/proto.tmpl +++ b/templates/common/proto.tmpl @@ -19,11 +19,11 @@ func (c {{.Type| gousage}}) Close() (err error) { {{- end}} {{define "proto/channel/outputMethods"}} -func (c {{.Type| gousage}}) Publisher() {{qualrun .ProtoName "Publisher"}} { +func (c {{.Type| gousage}}) Publisher() {{qualrun .Protocol "Publisher"}} { return c.publisher } -func (c {{.Type| gousage}}) Publish(ctx {{qual "context.Context"}}, envelopes ...{{qualrun .ProtoName "EnvelopeWriter"}}) error { +func (c {{.Type| gousage}}) Publish(ctx {{qual "context.Context"}}, envelopes ...{{qualrun .Protocol "EnvelopeWriter"}}) error { return c.publisher.Send(ctx, envelopes...) } {{- end}} @@ -31,11 +31,11 @@ func (c {{.Type| gousage}}) Publish(ctx {{qual "context.Context"}}, envelopes .. {{- /* Common template for channel publish methods that doesn't contain protocol-specific bindings manipulations */}} {{define "proto/channel/barePublishMethods"}} {{template "proto/channel/outputMethods" .}} - func (c {{.Type| gousage}}) SealEnvelope(envelope {{qualrun .ProtoName "EnvelopeWriter"}}, message {{if .PublisherMessageTypePromise}}{{goptr .PublisherMessageTypePromise.T.OutType}}{{else}}any{{end}}) error { + func (c {{.Type| gousage}}) SealEnvelope(envelope {{qualrun .Protocol "EnvelopeWriter"}}, message {{if .PublisherMessageTypePromise}}{{goptr .PublisherMessageTypePromise.T.OutType}}{{else}}any{{end}}) error { envelope.ResetPayload() {{- if .PublisherMessageTypePromise}} {{- /*Message is set for Channel in spec*/}} - if err := message.MarshalEnvelope{{.ProtoName | capitalize | goid}}(envelope); err != nil { + if err := message.MarshalEnvelope{{.Protocol | capitalize | goid}}(envelope); err != nil { return err } {{- else}} @@ -46,18 +46,18 @@ func (c {{.Type| gousage}}) Publish(ctx {{qual "context.Context"}}, envelopes .. } {{- end}} - {{- if and .PublisherMessageTypePromise (.PublisherMessageTypePromise.T.BindingsProtocols | has .ProtoName)}} - envelope.SetBindings({{.PublisherMessageTypePromise.T.BindingsType | gousage}}{}.{{.ProtoName | capitalize | goid}}()) + {{- if and .PublisherMessageTypePromise (.PublisherMessageTypePromise.T.BindingsProtocols | has .Protocol)}} + envelope.SetBindings({{.PublisherMessageTypePromise.T.BindingsType | gousage}}{}.{{.Protocol | capitalize | goid}}()) {{- end}} return nil } {{- end}} {{define "proto/channel/subscribeMethods"}} -func (c {{.Type| gousage}}) ExtractEnvelope(envelope {{qualrun .ProtoName "EnvelopeReader"}}, message {{if .SubscriberMessageTypePromise}}{{goptr .SubscriberMessageTypePromise.T.InType}}{{else}}any{{end}}) error { +func (c {{.Type| gousage}}) ExtractEnvelope(envelope {{qualrun .Protocol "EnvelopeReader"}}, message {{if .SubscriberMessageTypePromise}}{{goptr .SubscriberMessageTypePromise.T.InType}}{{else}}any{{end}}) error { {{- if .SubscriberMessageTypePromise}} {{- /* Message set for Channel in spec */ -}} - return message.UnmarshalEnvelope{{.ProtoName | capitalize | goid}}(envelope) + return message.UnmarshalEnvelope{{.Protocol | capitalize | goid}}(envelope) {{- else}} {{- /* No Message set for Channel in spec */ -}} dec := {{qual "encoding/json.NewDecoder"}}(envelope) @@ -65,40 +65,40 @@ func (c {{.Type| gousage}}) ExtractEnvelope(envelope {{qualrun .ProtoName "Envel {{- end}} } -func (c {{.Type| gousage}}) IsSubscriber() {{qualrun .ProtoName "Subscriber"}} { +func (c {{.Type| gousage}}) IsSubscriber() {{qualrun .Protocol "Subscriber"}} { return c.subscriber } -func (c {{.Type| gousage}}) Subscribe(ctx {{qual "context.Context"}}, cb func(envelope {{qualrun .ProtoName "EnvelopeReader"}})) error { +func (c {{.Type| gousage}}) Subscribe(ctx {{qual "context.Context"}}, cb func(envelope {{qualrun .Protocol "EnvelopeReader"}})) error { return c.subscriber.Receive(ctx, cb) } {{- end}} {{- /* Common template for channel OpenChannel function that doesn't contain protocol-specific bindings manipulations */}} {{define "proto/channel/openFunction"}} - func Open{{ .Channel | goid }}{{.ProtoName | capitalize | goid}}( + func Open{{ .Channel | goid }}{{.Protocol | capitalize | goid}}( ctx {{qual "context.Context"}}, {{ if .ParametersType}}params {{.ParametersType | gousage}},{{end}} - {{ if .IsPublisher}}producer {{qualrun .ProtoName "Producer"}},{{end}} - {{ if .IsSubscriber}}consumer {{qualrun .ProtoName "Consumer"}},{{end}} + {{ if .IsPublisher}}producer {{qualrun .Protocol "Producer"}},{{end}} + {{ if .IsSubscriber}}consumer {{qualrun .Protocol "Consumer"}},{{end}} ) (ch *{{.Type | gousage}}, err error) { name := {{.Channel | goid}}Name({{if .ParametersType}}params{{end}}) - {{- if .BindingsProtocols | has .ProtoName}} - bindings := {{.BindingsType | gousage}}{}.{{.ProtoName | capitalize | goid}}() + {{- if .BindingsProtocols | has .Protocol}} + bindings := {{.BindingsType | gousage}}{}.{{.Protocol | capitalize | goid}}() {{- end }} {{- if .IsPublisher}} - var publisher {{qualrun .ProtoName "Publisher"}} + var publisher {{qualrun .Protocol "Publisher"}} if producer != nil { - if publisher, err = producer.Publisher(ctx, name.String(), {{if .BindingsProtocols | has .ProtoName}}&bindings{{else}}nil{{end}}); err != nil { + if publisher, err = producer.Publisher(ctx, name.String(), {{if .BindingsProtocols | has .Protocol}}&bindings{{else}}nil{{end}}); err != nil { return nil, err } } {{- end}} {{- if .IsSubscriber}} - var subscriber {{qualrun .ProtoName "Subscriber"}} + var subscriber {{qualrun .Protocol "Subscriber"}} if consumer != nil { - if subscriber, err = consumer.Subscriber(ctx, name.String(), {{if .BindingsProtocols | has .ProtoName}}&bindings{{else}}nil{{end}}); err != nil { + if subscriber, err = consumer.Subscriber(ctx, name.String(), {{if .BindingsProtocols | has .Protocol}}&bindings{{else}}nil{{end}}); err != nil { return nil, err } } @@ -114,10 +114,10 @@ func (c {{.Type| gousage}}) Subscribe(ctx {{qual "context.Context"}}, cb func(en {{- /* Common template for channel NewChannel function that doesn't contain protocol-specific bindings manipulations */}} {{define "proto/channel/bareNewFunction"}} - func New{{ .Channel | goid }}{{.ProtoName | capitalize | goid}}( + func New{{ .Channel | goid }}{{.Protocol | capitalize | goid}}( {{- if .ParametersType}}params {{.ParametersType| gousage}},{{end}} - {{- if .IsPublisher}}publisher {{qualrun .ProtoName "Publisher"}},{{end}} - {{- if .IsSubscriber}}subscriber {{qualrun .ProtoName "Subscriber"}},{{end}} + {{- if .IsPublisher}}publisher {{qualrun .Protocol "Publisher"}},{{end}} + {{- if .IsSubscriber}}subscriber {{qualrun .Protocol "Subscriber"}},{{end}} ) *{{.Type| gousage}} { res := {{.Type| gousage}}{ name: {{.Channel | goid}}Name({{if .ParametersType}}params{{end}}), @@ -129,7 +129,7 @@ func (c {{.Type| gousage}}) Subscribe(ctx {{qual "context.Context"}}, cb func(en {{- end}} {{define "proto/message/marshalUnmarshalMethods"}} -func (m *{{ .OutType | goid }}) MarshalEnvelope{{ .ProtoName | capitalize | goid }}(envelope {{qualrun .ProtoName "EnvelopeWriter"}}) error { +func (m *{{ .OutType | goid }}) MarshalEnvelope{{ .Protocol | capitalize | goid }}(envelope {{qualrun .Protocol "EnvelopeWriter"}}) error { {{- template "proto/message/encodeExpr" .}} envelope.SetContentType({{.ContentType | golit}}) {{- if .HeadersTypePromise}} @@ -144,7 +144,7 @@ func (m *{{ .OutType | goid }}) MarshalEnvelope{{ .ProtoName | capitalize | goid return nil } -func (m *{{ .InType | goid }}) UnmarshalEnvelope{{ .ProtoName | capitalize | goid }}(envelope {{qualrun .ProtoName "EnvelopeReader"}}) error { +func (m *{{ .InType | goid }}) UnmarshalEnvelope{{ .Protocol | capitalize | goid }}(envelope {{qualrun .Protocol "EnvelopeReader"}}) error { {{- template "proto/message/decodeExpr" .}} {{- if .HeadersTypePromise }} {{- /* Empty headers should not generate code */}} diff --git a/templates/http/http_channel.tmpl b/templates/http/http_channel.tmpl index 40519b4..22cf53c 100644 --- a/templates/http/http_channel.tmpl +++ b/templates/http/http_channel.tmpl @@ -14,8 +14,8 @@ type {{ .Type | goid }}Server interface { Open{{.Type | goid}}(ctx {{qual "context.Context"}}, {{if .ParametersType}}params {{.ParametersType | gousage }}{{end}}) (*{{.Type | gousage }}, error) - {{if .IsPublisher}}Producer() {{qualrun .ProtoName "Producer"}}{{end}} - {{if .IsSubscriber}}Consumer() {{qualrun .ProtoName "Consumer"}}{{end}} + {{if .IsPublisher}}Producer() {{qualrun .Protocol "Producer"}}{{end}} + {{if .IsSubscriber}}Consumer() {{qualrun .Protocol "Consumer"}}{{end}} } {{- end}} diff --git a/templates/http/http_message.tmpl b/templates/http/http_message.tmpl index df2fc9e..699357e 100644 --- a/templates/http/http_message.tmpl +++ b/templates/http/http_message.tmpl @@ -1,6 +1,6 @@ {{- with deref .}} - {{- if gondefined (print "MessageMethods" .ProtoName (goid .))}} + {{- if gondefined (print "MessageMethods" .Protocol (goid .))}} {{template "proto/message/marshalUnmarshalMethods" deref .}} {{- end}} - {{- print "MessageMethods" .ProtoName (goid .) | def}} + {{- print "MessageMethods" .Protocol (goid .) | def}} {{- end}} \ No newline at end of file diff --git a/templates/http/http_server.tmpl b/templates/http/http_server.tmpl index 8ddeec9..28f3820 100644 --- a/templates/http/http_server.tmpl +++ b/templates/http/http_server.tmpl @@ -1,5 +1,5 @@ {{- localobj .Type}} -func New{{ .Server | goid }}(producer {{qualrun .ProtoName "Producer"}}, consumer {{qualrun .ProtoName "Consumer"}}) *{{.Type| gousage}} { +func New{{ .Server | goid }}(producer {{qualrun .Protocol "Producer"}}, consumer {{qualrun .Protocol "Consumer"}}) *{{.Type| gousage}} { return &{{.Type| gousage}}{ producer: producer, consumer: consumer, @@ -13,22 +13,22 @@ func (s {{.Type| gousage}}) Name() string { return "{{ . | goid }}" } -func (s {{.Type| gousage}}) Producer() {{qualrun .ProtoName "Producer"}} { +func (s {{.Type| gousage}}) Producer() {{qualrun .Protocol "Producer"}} { return s.producer } -func (s {{.Type| gousage}}) Consumer() {{qualrun .ProtoName "Consumer"}} { +func (s {{.Type| gousage}}) Consumer() {{qualrun .Protocol "Consumer"}} { return s.consumer } {{- range $ch := .GetBoundChannels}} {{- with deref .}} - {{- with .SelectProtoObject $.ProtoName }} + {{- with .SelectProtoObject $.Protocol }} func (s {{ $.Type | gousage }}) Open{{ $ch | goid }}( ctx {{qual "context.Context"}}, {{- if .ParametersType}}params {{ .ParametersType | gousage }},{{end}} ) (ch *{{ .Type | gousage }}, err error) { - return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.ProtoName | capitalize | goid }}( + return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.Protocol | capitalize | goid }}( ctx, {{- if .ParametersType}}params,{{end}} {{- if .IsPublisher}}s.producer,{{end}} diff --git a/templates/ip/ip_channel.tmpl b/templates/ip/ip_channel.tmpl index b9360d9..2f6d8f5 100644 --- a/templates/ip/ip_channel.tmpl +++ b/templates/ip/ip_channel.tmpl @@ -14,8 +14,8 @@ type {{ .Type | goid }}Server interface { Open{{.Type | goid}}(ctx {{qual "context.Context"}}, {{if .ParametersType}}params {{.ParametersType | gousage}}{{end}}) (*{{.Type| gousage}}, error) - {{if .IsPublisher}}Producer() {{qualrun .ProtoName "Producer"}}{{end}} - {{if .IsSubscriber}}Consumer() {{qualrun .ProtoName "Consumer"}}{{end}} + {{if .IsPublisher}}Producer() {{qualrun .Protocol "Producer"}}{{end}} + {{if .IsSubscriber}}Consumer() {{qualrun .Protocol "Consumer"}}{{end}} } {{- end}} diff --git a/templates/ip/ip_message.tmpl b/templates/ip/ip_message.tmpl index df2fc9e..699357e 100644 --- a/templates/ip/ip_message.tmpl +++ b/templates/ip/ip_message.tmpl @@ -1,6 +1,6 @@ {{- with deref .}} - {{- if gondefined (print "MessageMethods" .ProtoName (goid .))}} + {{- if gondefined (print "MessageMethods" .Protocol (goid .))}} {{template "proto/message/marshalUnmarshalMethods" deref .}} {{- end}} - {{- print "MessageMethods" .ProtoName (goid .) | def}} + {{- print "MessageMethods" .Protocol (goid .) | def}} {{- end}} \ No newline at end of file diff --git a/templates/ip/ip_server.tmpl b/templates/ip/ip_server.tmpl index 8ddeec9..28f3820 100644 --- a/templates/ip/ip_server.tmpl +++ b/templates/ip/ip_server.tmpl @@ -1,5 +1,5 @@ {{- localobj .Type}} -func New{{ .Server | goid }}(producer {{qualrun .ProtoName "Producer"}}, consumer {{qualrun .ProtoName "Consumer"}}) *{{.Type| gousage}} { +func New{{ .Server | goid }}(producer {{qualrun .Protocol "Producer"}}, consumer {{qualrun .Protocol "Consumer"}}) *{{.Type| gousage}} { return &{{.Type| gousage}}{ producer: producer, consumer: consumer, @@ -13,22 +13,22 @@ func (s {{.Type| gousage}}) Name() string { return "{{ . | goid }}" } -func (s {{.Type| gousage}}) Producer() {{qualrun .ProtoName "Producer"}} { +func (s {{.Type| gousage}}) Producer() {{qualrun .Protocol "Producer"}} { return s.producer } -func (s {{.Type| gousage}}) Consumer() {{qualrun .ProtoName "Consumer"}} { +func (s {{.Type| gousage}}) Consumer() {{qualrun .Protocol "Consumer"}} { return s.consumer } {{- range $ch := .GetBoundChannels}} {{- with deref .}} - {{- with .SelectProtoObject $.ProtoName }} + {{- with .SelectProtoObject $.Protocol }} func (s {{ $.Type | gousage }}) Open{{ $ch | goid }}( ctx {{qual "context.Context"}}, {{- if .ParametersType}}params {{ .ParametersType | gousage }},{{end}} ) (ch *{{ .Type | gousage }}, err error) { - return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.ProtoName | capitalize | goid }}( + return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.Protocol | capitalize | goid }}( ctx, {{- if .ParametersType}}params,{{end}} {{- if .IsPublisher}}s.producer,{{end}} diff --git a/templates/kafka/kafka_channel.tmpl b/templates/kafka/kafka_channel.tmpl index 4e60ab6..45afe82 100644 --- a/templates/kafka/kafka_channel.tmpl +++ b/templates/kafka/kafka_channel.tmpl @@ -1,10 +1,10 @@ {{- localobj .Type}} {{template "proto/channel/openFunction" .}} -func New{{ .Channel | goid }}{{.ProtoName | capitalize | goid}}( +func New{{ .Channel | goid }}{{.Protocol | capitalize | goid}}( {{ if .ParametersType}}params {{.ParametersType| gousage}},{{end}} - {{ if .IsPublisher}}publisher {{qualrun .ProtoName "Publisher"}},{{end}} - {{ if .IsSubscriber}}subscriber {{qualrun .ProtoName "Subscriber"}},{{end}} + {{ if .IsPublisher}}publisher {{qualrun .Protocol "Publisher"}},{{end}} + {{ if .IsSubscriber}}subscriber {{qualrun .Protocol "Subscriber"}},{{end}} ) *{{.Type | gousage}} { res := {{.Type | gousage}}{ name: {{.Channel | goid}}Name({{if .ParametersType}}params{{end}}), @@ -13,7 +13,7 @@ func New{{ .Channel | goid }}{{.ProtoName | capitalize | goid}}( } res.topic = res.name.String() {{- if .BindingsType}} - bindings := {{.BindingsType | gousage}}{}.{{.ProtoName | capitalize | goid}}() + bindings := {{.BindingsType | gousage}}{}.{{.Protocol | capitalize | goid}}() if bindings.Topic != "" { res.topic = bindings.Topic } @@ -33,11 +33,11 @@ func (c {{.Type| gousage}}) Topic() string { {{- if .IsPublisher}} {{template "proto/channel/outputMethods" .}} - func (c {{.Type| gousage}}) SealEnvelope(envelope {{qualrun .ProtoName "EnvelopeWriter"}}, message {{if .PublisherMessageTypePromise}}{{goptr .PublisherMessageTypePromise.T.OutType}}{{else}}any{{end}}) error { + func (c {{.Type| gousage}}) SealEnvelope(envelope {{qualrun .Protocol "EnvelopeWriter"}}, message {{if .PublisherMessageTypePromise}}{{goptr .PublisherMessageTypePromise.T.OutType}}{{else}}any{{end}}) error { envelope.ResetPayload() {{- if .PublisherMessageTypePromise}} {{- /* Message is set for Channel in spec */}} - if err := message.Marshal{{.ProtoName | capitalize | goid}}Envelope(envelope); err != nil { + if err := message.MarshalEnvelope{{.Protocol | capitalize | goid}}(envelope); err != nil { return err } {{- else}} @@ -48,8 +48,8 @@ func (c {{.Type| gousage}}) Topic() string { } {{- end}} envelope.SetTopic(c.topic) - {{- if and .PublisherMessageTypePromise (.PublisherMessageTypePromise.T.BindingsProtocols | has .ProtoName)}} - envelope.SetBindings({{.PublisherMessageTypePromise.T.BindingsType | gousage }}{}.{{.ProtoName | capitalize | goid}}()) + {{- if and .PublisherMessageTypePromise (.PublisherMessageTypePromise.T.BindingsProtocols | has .Protocol)}} + envelope.SetBindings({{.PublisherMessageTypePromise.T.BindingsType | gousage }}{}.{{.Protocol | capitalize | goid}}()) {{- end}} return nil } @@ -59,7 +59,7 @@ func (c {{.Type| gousage}}) Topic() string { type {{ .Type | goid }}Server interface { Open{{.Type | goid}}(ctx {{qual "context.Context"}}, {{if .ParametersType}}params {{.ParametersType| gousage}}{{end}}) (*{{.Type| gousage}}, error) - {{if .IsPublisher}}Producer() {{qualrun .ProtoName "Producer"}}{{end}} - {{if .IsSubscriber}}Consumer() {{qualrun .ProtoName "Consumer"}}{{end}} + {{if .IsPublisher}}Producer() {{qualrun .Protocol "Producer"}}{{end}} + {{if .IsSubscriber}}Consumer() {{qualrun .Protocol "Consumer"}}{{end}} } {{- end}} diff --git a/templates/kafka/kafka_message.tmpl b/templates/kafka/kafka_message.tmpl index df2fc9e..699357e 100644 --- a/templates/kafka/kafka_message.tmpl +++ b/templates/kafka/kafka_message.tmpl @@ -1,6 +1,6 @@ {{- with deref .}} - {{- if gondefined (print "MessageMethods" .ProtoName (goid .))}} + {{- if gondefined (print "MessageMethods" .Protocol (goid .))}} {{template "proto/message/marshalUnmarshalMethods" deref .}} {{- end}} - {{- print "MessageMethods" .ProtoName (goid .) | def}} + {{- print "MessageMethods" .Protocol (goid .) | def}} {{- end}} \ No newline at end of file diff --git a/templates/kafka/kafka_server.tmpl b/templates/kafka/kafka_server.tmpl index 8ddeec9..28f3820 100644 --- a/templates/kafka/kafka_server.tmpl +++ b/templates/kafka/kafka_server.tmpl @@ -1,5 +1,5 @@ {{- localobj .Type}} -func New{{ .Server | goid }}(producer {{qualrun .ProtoName "Producer"}}, consumer {{qualrun .ProtoName "Consumer"}}) *{{.Type| gousage}} { +func New{{ .Server | goid }}(producer {{qualrun .Protocol "Producer"}}, consumer {{qualrun .Protocol "Consumer"}}) *{{.Type| gousage}} { return &{{.Type| gousage}}{ producer: producer, consumer: consumer, @@ -13,22 +13,22 @@ func (s {{.Type| gousage}}) Name() string { return "{{ . | goid }}" } -func (s {{.Type| gousage}}) Producer() {{qualrun .ProtoName "Producer"}} { +func (s {{.Type| gousage}}) Producer() {{qualrun .Protocol "Producer"}} { return s.producer } -func (s {{.Type| gousage}}) Consumer() {{qualrun .ProtoName "Consumer"}} { +func (s {{.Type| gousage}}) Consumer() {{qualrun .Protocol "Consumer"}} { return s.consumer } {{- range $ch := .GetBoundChannels}} {{- with deref .}} - {{- with .SelectProtoObject $.ProtoName }} + {{- with .SelectProtoObject $.Protocol }} func (s {{ $.Type | gousage }}) Open{{ $ch | goid }}( ctx {{qual "context.Context"}}, {{- if .ParametersType}}params {{ .ParametersType | gousage }},{{end}} ) (ch *{{ .Type | gousage }}, err error) { - return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.ProtoName | capitalize | goid }}( + return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.Protocol | capitalize | goid }}( ctx, {{- if .ParametersType}}params,{{end}} {{- if .IsPublisher}}s.producer,{{end}} diff --git a/templates/main.tmpl b/templates/main.tmpl index 332319e..935518d 100644 --- a/templates/main.tmpl +++ b/templates/main.tmpl @@ -8,7 +8,7 @@ {{- range .CurrentSelection.Protocols}} {{- with (deref $.Object).SelectProtoObject . }} - {{- tmpl (print .ProtoName "_server.tmpl") . }} + {{- tmpl (print .Protocol "_server.tmpl") . }} {{- end}} {{- end}} @@ -21,7 +21,7 @@ {{- end}} {{- range .CurrentSelection.Protocols}} {{- with (deref $.Object).SelectProtoObject . }} - {{- tmpl (print .ProtoName "_channel.tmpl") . }} + {{- tmpl (print .Protocol "_channel.tmpl") . }} {{- end}} {{- end}} @@ -32,7 +32,7 @@ {{- range .CurrentSelection.Protocols}} {{- with (deref $.Object).SelectProtoObject . }} - {{- tmpl (print .ProtoName "_message.tmpl") . }} + {{- tmpl (print .Protocol "_message.tmpl") . }} {{- end}} {{- end}} {{- end}} diff --git a/templates/mqtt/mqtt_channel.tmpl b/templates/mqtt/mqtt_channel.tmpl index 77cef27..b3dea6a 100644 --- a/templates/mqtt/mqtt_channel.tmpl +++ b/templates/mqtt/mqtt_channel.tmpl @@ -1,10 +1,10 @@ {{- localobj .Type}} {{template "proto/channel/openFunction" .}} -func New{{ .Channel | goid }}{{.ProtoName | capitalize | goid}}( +func New{{ .Channel | goid }}{{.Protocol | capitalize | goid}}( {{ if .ParametersType}}params {{.ParametersType| gousage}},{{end}} - {{ if .IsPublisher}}publisher {{qualrun .ProtoName "Publisher"}},{{end}} - {{ if .IsSubscriber}}subscriber {{qualrun .ProtoName "Subscriber"}},{{end}} + {{ if .IsPublisher}}publisher {{qualrun .Protocol "Publisher"}},{{end}} + {{ if .IsSubscriber}}subscriber {{qualrun .Protocol "Subscriber"}},{{end}} ) *{{.Type | gousage}} { res := {{.Type| gousage}}{ name: {{.Channel | goid}}Name({{if .ParametersType}}params{{end}}), @@ -26,11 +26,11 @@ func (c {{.Type| gousage}}) Topic() string { {{- if .IsPublisher}} {{template "proto/channel/outputMethods" .}} - func (c {{.Type| gousage}}) SealEnvelope(envelope {{qualrun .ProtoName "EnvelopeWriter"}}, message {{if .PublisherMessageTypePromise}}{{goptr .PublisherMessageTypePromise.T.OutType}}{{else}}any{{end}}) error { + func (c {{.Type| gousage}}) SealEnvelope(envelope {{qualrun .Protocol "EnvelopeWriter"}}, message {{if .PublisherMessageTypePromise}}{{goptr .PublisherMessageTypePromise.T.OutType}}{{else}}any{{end}}) error { envelope.ResetPayload() {{- if .PublisherMessageTypePromise }} {{- /*Message is set for Channel in spec*/}} - if err := message.Marshal{{.ProtoName | capitalize | goid}}Envelope(envelope); err != nil { + if err := message.MarshalEnvelope{{.Protocol | capitalize | goid}}(envelope); err != nil { return err } {{- else}} @@ -41,8 +41,8 @@ func (c {{.Type| gousage}}) Topic() string { } {{- end}} envelope.SetTopic(c.topic) - {{- if and .PublisherMessageTypePromise (.PublisherMessageTypePromise.T.BindingsProtocols | has .ProtoName)}} - envelope.SetBindings({{.PublisherMessageTypePromise.T.BindingsType | gousage }}{}.{{.ProtoName | capitalize | goid}}()) + {{- if and .PublisherMessageTypePromise (.PublisherMessageTypePromise.T.BindingsProtocols | has .Protocol)}} + envelope.SetBindings({{.PublisherMessageTypePromise.T.BindingsType | gousage }}{}.{{.Protocol | capitalize | goid}}()) {{- end}} return nil } @@ -52,7 +52,7 @@ func (c {{.Type| gousage}}) Topic() string { type {{ .Type | goid }}Server interface { Open{{.Type | goid}}(ctx {{qual "context.Context"}}, {{if .ParametersType}}params {{.ParametersType| gousage}}{{end}}) (*{{.Type| gousage}}, error) - {{if .IsPublisher}}Producer() {{qualrun .ProtoName "Producer"}}{{end}} - {{if .IsSubscriber}}Consumer() {{qualrun .ProtoName "Consumer"}}{{end}} + {{if .IsPublisher}}Producer() {{qualrun .Protocol "Producer"}}{{end}} + {{if .IsSubscriber}}Consumer() {{qualrun .Protocol "Consumer"}}{{end}} } {{- end}} diff --git a/templates/mqtt/mqtt_message.tmpl b/templates/mqtt/mqtt_message.tmpl index df2fc9e..699357e 100644 --- a/templates/mqtt/mqtt_message.tmpl +++ b/templates/mqtt/mqtt_message.tmpl @@ -1,6 +1,6 @@ {{- with deref .}} - {{- if gondefined (print "MessageMethods" .ProtoName (goid .))}} + {{- if gondefined (print "MessageMethods" .Protocol (goid .))}} {{template "proto/message/marshalUnmarshalMethods" deref .}} {{- end}} - {{- print "MessageMethods" .ProtoName (goid .) | def}} + {{- print "MessageMethods" .Protocol (goid .) | def}} {{- end}} \ No newline at end of file diff --git a/templates/mqtt/mqtt_server.tmpl b/templates/mqtt/mqtt_server.tmpl index 285f7e2..8cccf33 100644 --- a/templates/mqtt/mqtt_server.tmpl +++ b/templates/mqtt/mqtt_server.tmpl @@ -1,5 +1,5 @@ {{- localobj .Type}} -func New{{.Server | goid}}(producer {{qualrun .ProtoName "Producer"}}, consumer {{qualrun .ProtoName "Consumer"}}) *{{.Type| gousage}} { +func New{{.Server | goid}}(producer {{qualrun .Protocol "Producer"}}, consumer {{qualrun .Protocol "Consumer"}}) *{{.Type| gousage}} { return &{{.Type| gousage}}{ producer: producer, consumer: consumer, @@ -13,22 +13,22 @@ func (s {{.Type| gousage}}) Name() string { return "{{ . | goid }}" } -func (s {{.Type| gousage}}) Producer() {{qualrun .ProtoName "Producer"}} { +func (s {{.Type| gousage}}) Producer() {{qualrun .Protocol "Producer"}} { return s.producer } -func (s {{.Type| gousage}}) Consumer() {{qualrun .ProtoName "Consumer"}} { +func (s {{.Type| gousage}}) Consumer() {{qualrun .Protocol "Consumer"}} { return s.consumer } {{- range $ch := .GetBoundChannels}} {{- with deref .}} - {{- with .SelectProtoObject $.ProtoName }} + {{- with .SelectProtoObject $.Protocol }} func (s {{ $.Type | gousage }}) Open{{ $ch | goid }}( ctx {{qual "context.Context"}}, {{- if .ParametersType}}params {{ .ParametersType | gousage }},{{end}} ) (ch *{{ .Type | gousage }}, err error) { - return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.ProtoName | capitalize | goid }}( + return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.Protocol | capitalize | goid }}( ctx, {{- if .ParametersType}}params,{{end}} {{- if .IsPublisher}}s.producer,{{end}} diff --git a/templates/redis/redis_channel.tmpl b/templates/redis/redis_channel.tmpl index b9360d9..2f6d8f5 100644 --- a/templates/redis/redis_channel.tmpl +++ b/templates/redis/redis_channel.tmpl @@ -14,8 +14,8 @@ type {{ .Type | goid }}Server interface { Open{{.Type | goid}}(ctx {{qual "context.Context"}}, {{if .ParametersType}}params {{.ParametersType | gousage}}{{end}}) (*{{.Type| gousage}}, error) - {{if .IsPublisher}}Producer() {{qualrun .ProtoName "Producer"}}{{end}} - {{if .IsSubscriber}}Consumer() {{qualrun .ProtoName "Consumer"}}{{end}} + {{if .IsPublisher}}Producer() {{qualrun .Protocol "Producer"}}{{end}} + {{if .IsSubscriber}}Consumer() {{qualrun .Protocol "Consumer"}}{{end}} } {{- end}} diff --git a/templates/redis/redis_message.tmpl b/templates/redis/redis_message.tmpl index df2fc9e..699357e 100644 --- a/templates/redis/redis_message.tmpl +++ b/templates/redis/redis_message.tmpl @@ -1,6 +1,6 @@ {{- with deref .}} - {{- if gondefined (print "MessageMethods" .ProtoName (goid .))}} + {{- if gondefined (print "MessageMethods" .Protocol (goid .))}} {{template "proto/message/marshalUnmarshalMethods" deref .}} {{- end}} - {{- print "MessageMethods" .ProtoName (goid .) | def}} + {{- print "MessageMethods" .Protocol (goid .) | def}} {{- end}} \ No newline at end of file diff --git a/templates/redis/redis_server.tmpl b/templates/redis/redis_server.tmpl index 8ddeec9..28f3820 100644 --- a/templates/redis/redis_server.tmpl +++ b/templates/redis/redis_server.tmpl @@ -1,5 +1,5 @@ {{- localobj .Type}} -func New{{ .Server | goid }}(producer {{qualrun .ProtoName "Producer"}}, consumer {{qualrun .ProtoName "Consumer"}}) *{{.Type| gousage}} { +func New{{ .Server | goid }}(producer {{qualrun .Protocol "Producer"}}, consumer {{qualrun .Protocol "Consumer"}}) *{{.Type| gousage}} { return &{{.Type| gousage}}{ producer: producer, consumer: consumer, @@ -13,22 +13,22 @@ func (s {{.Type| gousage}}) Name() string { return "{{ . | goid }}" } -func (s {{.Type| gousage}}) Producer() {{qualrun .ProtoName "Producer"}} { +func (s {{.Type| gousage}}) Producer() {{qualrun .Protocol "Producer"}} { return s.producer } -func (s {{.Type| gousage}}) Consumer() {{qualrun .ProtoName "Consumer"}} { +func (s {{.Type| gousage}}) Consumer() {{qualrun .Protocol "Consumer"}} { return s.consumer } {{- range $ch := .GetBoundChannels}} {{- with deref .}} - {{- with .SelectProtoObject $.ProtoName }} + {{- with .SelectProtoObject $.Protocol }} func (s {{ $.Type | gousage }}) Open{{ $ch | goid }}( ctx {{qual "context.Context"}}, {{- if .ParametersType}}params {{ .ParametersType | gousage }},{{end}} ) (ch *{{ .Type | gousage }}, err error) { - return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.ProtoName | capitalize | goid }}( + return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.Protocol | capitalize | goid }}( ctx, {{- if .ParametersType}}params,{{end}} {{- if .IsPublisher}}s.producer,{{end}} diff --git a/templates/tcp/tcp_channel.tmpl b/templates/tcp/tcp_channel.tmpl index b9360d9..2f6d8f5 100644 --- a/templates/tcp/tcp_channel.tmpl +++ b/templates/tcp/tcp_channel.tmpl @@ -14,8 +14,8 @@ type {{ .Type | goid }}Server interface { Open{{.Type | goid}}(ctx {{qual "context.Context"}}, {{if .ParametersType}}params {{.ParametersType | gousage}}{{end}}) (*{{.Type| gousage}}, error) - {{if .IsPublisher}}Producer() {{qualrun .ProtoName "Producer"}}{{end}} - {{if .IsSubscriber}}Consumer() {{qualrun .ProtoName "Consumer"}}{{end}} + {{if .IsPublisher}}Producer() {{qualrun .Protocol "Producer"}}{{end}} + {{if .IsSubscriber}}Consumer() {{qualrun .Protocol "Consumer"}}{{end}} } {{- end}} diff --git a/templates/tcp/tcp_message.tmpl b/templates/tcp/tcp_message.tmpl index df2fc9e..699357e 100644 --- a/templates/tcp/tcp_message.tmpl +++ b/templates/tcp/tcp_message.tmpl @@ -1,6 +1,6 @@ {{- with deref .}} - {{- if gondefined (print "MessageMethods" .ProtoName (goid .))}} + {{- if gondefined (print "MessageMethods" .Protocol (goid .))}} {{template "proto/message/marshalUnmarshalMethods" deref .}} {{- end}} - {{- print "MessageMethods" .ProtoName (goid .) | def}} + {{- print "MessageMethods" .Protocol (goid .) | def}} {{- end}} \ No newline at end of file diff --git a/templates/tcp/tcp_server.tmpl b/templates/tcp/tcp_server.tmpl index 8ddeec9..28f3820 100644 --- a/templates/tcp/tcp_server.tmpl +++ b/templates/tcp/tcp_server.tmpl @@ -1,5 +1,5 @@ {{- localobj .Type}} -func New{{ .Server | goid }}(producer {{qualrun .ProtoName "Producer"}}, consumer {{qualrun .ProtoName "Consumer"}}) *{{.Type| gousage}} { +func New{{ .Server | goid }}(producer {{qualrun .Protocol "Producer"}}, consumer {{qualrun .Protocol "Consumer"}}) *{{.Type| gousage}} { return &{{.Type| gousage}}{ producer: producer, consumer: consumer, @@ -13,22 +13,22 @@ func (s {{.Type| gousage}}) Name() string { return "{{ . | goid }}" } -func (s {{.Type| gousage}}) Producer() {{qualrun .ProtoName "Producer"}} { +func (s {{.Type| gousage}}) Producer() {{qualrun .Protocol "Producer"}} { return s.producer } -func (s {{.Type| gousage}}) Consumer() {{qualrun .ProtoName "Consumer"}} { +func (s {{.Type| gousage}}) Consumer() {{qualrun .Protocol "Consumer"}} { return s.consumer } {{- range $ch := .GetBoundChannels}} {{- with deref .}} - {{- with .SelectProtoObject $.ProtoName }} + {{- with .SelectProtoObject $.Protocol }} func (s {{ $.Type | gousage }}) Open{{ $ch | goid }}( ctx {{qual "context.Context"}}, {{- if .ParametersType}}params {{ .ParametersType | gousage }},{{end}} ) (ch *{{ .Type | gousage }}, err error) { - return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.ProtoName | capitalize | goid }}( + return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.Protocol | capitalize | goid }}( ctx, {{- if .ParametersType}}params,{{end}} {{- if .IsPublisher}}s.producer,{{end}} diff --git a/templates/udp/udp_channel.tmpl b/templates/udp/udp_channel.tmpl index f5fc2e2..bef7518 100644 --- a/templates/udp/udp_channel.tmpl +++ b/templates/udp/udp_channel.tmpl @@ -14,7 +14,7 @@ type {{ .Type | goid }}Server interface { Open{{.Type | goid}}(ctx {{qual "context.Context"}}, {{if .ParametersType}}params {{.ParametersType| gousage}}{{end}}) (*{{.Type| gousage}}, error) - {{if .IsPublisher}}Producer() {{qualrun .ProtoName "Producer"}}{{end}} - {{if .IsSubscriber}}Consumer() {{qualrun .ProtoName "Consumer"}}{{end}} + {{if .IsPublisher}}Producer() {{qualrun .Protocol "Producer"}}{{end}} + {{if .IsSubscriber}}Consumer() {{qualrun .Protocol "Consumer"}}{{end}} } {{- end}} diff --git a/templates/udp/udp_message.tmpl b/templates/udp/udp_message.tmpl index df2fc9e..699357e 100644 --- a/templates/udp/udp_message.tmpl +++ b/templates/udp/udp_message.tmpl @@ -1,6 +1,6 @@ {{- with deref .}} - {{- if gondefined (print "MessageMethods" .ProtoName (goid .))}} + {{- if gondefined (print "MessageMethods" .Protocol (goid .))}} {{template "proto/message/marshalUnmarshalMethods" deref .}} {{- end}} - {{- print "MessageMethods" .ProtoName (goid .) | def}} + {{- print "MessageMethods" .Protocol (goid .) | def}} {{- end}} \ No newline at end of file diff --git a/templates/udp/udp_server.tmpl b/templates/udp/udp_server.tmpl index 8ddeec9..28f3820 100644 --- a/templates/udp/udp_server.tmpl +++ b/templates/udp/udp_server.tmpl @@ -1,5 +1,5 @@ {{- localobj .Type}} -func New{{ .Server | goid }}(producer {{qualrun .ProtoName "Producer"}}, consumer {{qualrun .ProtoName "Consumer"}}) *{{.Type| gousage}} { +func New{{ .Server | goid }}(producer {{qualrun .Protocol "Producer"}}, consumer {{qualrun .Protocol "Consumer"}}) *{{.Type| gousage}} { return &{{.Type| gousage}}{ producer: producer, consumer: consumer, @@ -13,22 +13,22 @@ func (s {{.Type| gousage}}) Name() string { return "{{ . | goid }}" } -func (s {{.Type| gousage}}) Producer() {{qualrun .ProtoName "Producer"}} { +func (s {{.Type| gousage}}) Producer() {{qualrun .Protocol "Producer"}} { return s.producer } -func (s {{.Type| gousage}}) Consumer() {{qualrun .ProtoName "Consumer"}} { +func (s {{.Type| gousage}}) Consumer() {{qualrun .Protocol "Consumer"}} { return s.consumer } {{- range $ch := .GetBoundChannels}} {{- with deref .}} - {{- with .SelectProtoObject $.ProtoName }} + {{- with .SelectProtoObject $.Protocol }} func (s {{ $.Type | gousage }}) Open{{ $ch | goid }}( ctx {{qual "context.Context"}}, {{- if .ParametersType}}params {{ .ParametersType | gousage }},{{end}} ) (ch *{{ .Type | gousage }}, err error) { - return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.ProtoName | capitalize | goid }}( + return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.Protocol | capitalize | goid }}( ctx, {{- if .ParametersType}}params,{{end}} {{- if .IsPublisher}}s.producer,{{end}} diff --git a/templates/ws/ws_channel.tmpl b/templates/ws/ws_channel.tmpl index e4ef5a8..7477e3c 100644 --- a/templates/ws/ws_channel.tmpl +++ b/templates/ws/ws_channel.tmpl @@ -14,8 +14,8 @@ type {{ .Type | goid }}Server interface { Open{{.Type | goid}}(ctx {{qual "context.Context"}}, {{if .ParametersType}}params {{.ParametersType| gousage}}{{end}}) (*{{.Type| gousage}}, error) - {{if .IsPublisher}}Producer() {{qualrun .ProtoName "Producer"}}{{end}} - {{if .IsSubscriber}}Consumer() {{qualrun .ProtoName "Consumer"}}{{end}} + {{if .IsPublisher}}Producer() {{qualrun .Protocol "Producer"}}{{end}} + {{if .IsSubscriber}}Consumer() {{qualrun .Protocol "Consumer"}}{{end}} } {{- end}} diff --git a/templates/ws/ws_message.tmpl b/templates/ws/ws_message.tmpl index df2fc9e..699357e 100644 --- a/templates/ws/ws_message.tmpl +++ b/templates/ws/ws_message.tmpl @@ -1,6 +1,6 @@ {{- with deref .}} - {{- if gondefined (print "MessageMethods" .ProtoName (goid .))}} + {{- if gondefined (print "MessageMethods" .Protocol (goid .))}} {{template "proto/message/marshalUnmarshalMethods" deref .}} {{- end}} - {{- print "MessageMethods" .ProtoName (goid .) | def}} + {{- print "MessageMethods" .Protocol (goid .) | def}} {{- end}} \ No newline at end of file diff --git a/templates/ws/ws_server.tmpl b/templates/ws/ws_server.tmpl index 706a383..29c83c1 100644 --- a/templates/ws/ws_server.tmpl +++ b/templates/ws/ws_server.tmpl @@ -1,5 +1,5 @@ {{- localobj .Type}} -func New{{ .Type | goid }}(producer {{qualrun .ProtoName "Producer"}}, consumer {{qualrun .ProtoName "Consumer"}}) *{{.Type| gousage}} { +func New{{ .Type | goid }}(producer {{qualrun .Protocol "Producer"}}, consumer {{qualrun .Protocol "Consumer"}}) *{{.Type| gousage}} { return &{{.Type| gousage}}{ producer: producer, consumer: consumer, @@ -13,22 +13,22 @@ func (s {{.Type| gousage}}) Name() string { return "{{ . | goid }}" } -func (s {{.Type| gousage}}) Producer() {{qualrun .ProtoName "Producer"}} { +func (s {{.Type| gousage}}) Producer() {{qualrun .Protocol "Producer"}} { return s.producer } -func (s {{.Type| gousage}}) Consumer() {{qualrun .ProtoName "Consumer"}} { +func (s {{.Type| gousage}}) Consumer() {{qualrun .Protocol "Consumer"}} { return s.consumer } {{- range $ch := .GetBoundChannels}} {{- with deref .}} - {{- with .SelectProtoObject $.ProtoName }} + {{- with .SelectProtoObject $.Protocol }} func (s {{ $.Type | gousage }}) Open{{ $ch | goid }}( ctx {{qual "context.Context"}}, {{- if .ParametersType}}params {{ .ParametersType | gousage }},{{end}} ) (ch *{{ .Type | gousage }}, err error) { - return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.ProtoName | capitalize | goid }}( + return {{qualgenpkg .Type}}Open{{ $ch | goid }}{{$.Protocol | capitalize | goid }}( ctx, {{- if .ParametersType}}params,{{end}} {{- if .IsPublisher}}s.producer,{{end}}