Skip to content

Commit

Permalink
style changes to ./exchanges.go
Browse files Browse the repository at this point in the history
  • Loading branch information
vetcher committed Mar 12, 2018
1 parent ae05fa5 commit 6ca0d00
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
45 changes: 22 additions & 23 deletions example/generated/exchanges.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
)
16 changes: 11 additions & 5 deletions generator/template/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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(&param))
}
}).Line()
}) //.Line()
}

0 comments on commit 6ca0d00

Please sign in to comment.