Skip to content

Commit

Permalink
Merge d57430b into 20dbc79
Browse files Browse the repository at this point in the history
  • Loading branch information
roblillack committed Mar 22, 2021
2 parents 20dbc79 + d57430b commit 45509b1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
## [Unreleased](https://github.com/roblillack/mars/compare/v1.0.4...master)

- Add unit test for `cert`.
- Improve code generation to not write redundant type information. #20

## [v1.0.4](https://github.com/roblillack/mars/compare/v1.0.3...v1.0.4)

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build: off

stack: go 1.14
stack: go 1.16

before_test:
- go vet ./...
Expand Down
12 changes: 9 additions & 3 deletions cmd/mars-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"go/format"
"os"
"path"
"text/template"
Expand Down Expand Up @@ -121,7 +122,12 @@ func generateSources(tpl, filename string, templateArgs map[string]interface{})
}
defer file.Close()

if _, err := file.WriteString(sourceCode); err != nil {
formatted, err := format.Source([]byte(sourceCode))
if err != nil {
fatalf("Failed to format file: %v", err)
}

if _, err := file.Write(formatted); err != nil {
fatalf("Failed to write to file: %v", err)
}
}
Expand All @@ -144,10 +150,10 @@ func {{.functionName}}() {
{{range $i, $c := .controllers}}
mars.RegisterController((*{{.StructName}})(nil),
[]*mars.MethodType{
{{range .MethodSpecs}}&mars.MethodType{
{{range .MethodSpecs}}{
Name: "{{.Name}}",
Args: []*mars.MethodArg{ {{range .Args}}
&mars.MethodArg{Name: "{{.Name}}", Type: reflect.TypeOf((*{{index $.ImportPaths .ImportPath | .TypeExpr.TypeName}})(nil)) },{{end}}
{Name: "{{.Name}}", Type: reflect.TypeOf((*{{index $.ImportPaths .ImportPath | .TypeExpr.TypeName}})(nil)) },{{end}}
},
},
{{end}}
Expand Down

0 comments on commit 45509b1

Please sign in to comment.