diff --git a/tools/goctl/api/format/format.go b/tools/goctl/api/format/format.go index ad9f91e4..afa7ee6a 100644 --- a/tools/goctl/api/format/format.go +++ b/tools/goctl/api/format/format.go @@ -171,7 +171,9 @@ func apiFormat(data string, skipCheckDeclare bool, filename ...string) (string, tapCount++ } } - util.WriteIndent(&builder, tapCount) + if line != "" { + util.WriteIndent(&builder, tapCount) + } builder.WriteString(line + pathx.NL) if strings.HasSuffix(noCommentLine, leftParenthesis) || strings.HasSuffix(noCommentLine, leftBrace) { tapCount++ diff --git a/tools/goctl/api/format/format_test.go b/tools/goctl/api/format/format_test.go index 076b25a8..786ac42b 100644 --- a/tools/goctl/api/format/format_test.go +++ b/tools/goctl/api/format/format_test.go @@ -26,6 +26,11 @@ service A-api { handler: GreetHandler ) get /greet/from/:name(Request) returns (Response) + +@server( +handler: GreetHandler2 + ) + get /greet/from2/:name(Request) returns (Response) } ` @@ -41,6 +46,11 @@ service A-api { handler: GreetHandler ) get /greet/from/:name(Request) returns (Response) + + @server( + handler: GreetHandler2 + ) + get /greet/from2/:name(Request) returns (Response) }` )