From 6ca0d007b7c35e851644f90db0d939f48eeab090 Mon Sep 17 00:00:00 2001 From: Artyom Blagov Date: Mon, 12 Mar 2018 12:00:18 +0300 Subject: [PATCH] style changes to ./exchanges.go --- example/generated/exchanges.go | 45 +++++++++++++++++----------------- generator/template/exchange.go | 16 ++++++++---- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/example/generated/exchanges.go b/example/generated/exchanges.go index 27a7166..1e864d6 100644 --- a/example/generated/exchanges.go +++ b/example/generated/exchanges.go @@ -4,28 +4,27 @@ package stringsvc import entity "github.com/devimteam/microgen/example/svc/entity" -type UppercaseRequest struct { - StringsMap map[string]string `json:"strings_map"` -} +type ( + UppercaseRequest struct { + StringsMap map[string]string `json:"strings_map"` + } + UppercaseResponse struct { + Ans string `json:"ans"` + } -type UppercaseResponse struct { - Ans string `json:"ans"` -} + CountRequest struct { + Text string `json:"text"` + Symbol string `json:"symbol"` + } + CountResponse struct { + Count int `json:"count"` + Positions []int `json:"positions"` + } -type CountRequest struct { - Text string `json:"text"` - Symbol string `json:"symbol"` -} - -type CountResponse struct { - Count int `json:"count"` - Positions []int `json:"positions"` -} - -type TestCaseRequest struct { - Comments []*entity.Comment `json:"comments"` -} - -type TestCaseResponse struct { - Tree map[string]int `json:"tree"` -} + TestCaseRequest struct { + Comments []*entity.Comment `json:"comments"` + } + TestCaseResponse struct { + Tree map[string]int `json:"tree"` + } +) diff --git a/generator/template/exchange.go b/generator/template/exchange.go index 45aaec9..32845f5 100644 --- a/generator/template/exchange.go +++ b/generator/template/exchange.go @@ -46,10 +46,16 @@ func (t *exchangeTemplate) Render() write_strategy.Renderer { f.PackageComment(t.Info.FileHeader) f.PackageComment(`Please, do not edit.`) + if len(t.Info.Iface.Methods) > 0 { + f.Type().Op("(") + } for _, signature := range t.Info.Iface.Methods { - f.Add(exchange(requestStructName(signature), RemoveContextIfFirst(signature.Args))).Line() + f.Add(exchange(requestStructName(signature), RemoveContextIfFirst(signature.Args))) //.Line() f.Add(exchange(responseStructName(signature), removeErrorIfLast(signature.Results))).Line() } + if len(t.Info.Iface.Methods) > 0 { + f.Op(")") + } return f } @@ -75,12 +81,12 @@ func (t *exchangeTemplate) ChooseStrategy() (write_strategy.Strategy, error) { func exchange(name string, params []types.Variable) Code { if len(params) == 0 { return Comment("Formal exchange type, please do not delete.").Line(). - Type().Id(name).Struct(). - Line() + Id(name).Struct() + //Line() } - return Type().Id(name).StructFunc(func(g *Group) { + return Id(name).StructFunc(func(g *Group) { for _, param := range params { g.Add(structField(¶m)) } - }).Line() + }) //.Line() }