@@ -107,6 +107,7 @@ func GetService(scanner *bufio.Scanner) []*Service {
107107 if CheckPrefix (line , "@doc" ) {
108108 var s Service
109109 var d Doc
110+ d = make (map [string ][]string )
110111 for {
111112 scanner .Scan ()
112113 line = scanner .Text ()
@@ -116,9 +117,9 @@ func GetService(scanner *bufio.Scanner) []*Service {
116117 }
117118 before = strings .TrimSpace (before )
118119 after = strings .Trim (strings .TrimSpace (after ), "\" " )
119- addDoc ( & d , before , after )
120+ d [ before ] = append ( d [ before ] , after )
120121 }
121- s .Doc = & d
122+ s .Doc = d
122123 scanner .Scan ()
123124 line = strings .TrimSpace (scanner .Text ())
124125 s .Handler = strings .TrimSpace (line [len ("@handler:" ):])
@@ -154,64 +155,25 @@ func parseMethod(s string) *Method {
154155 }
155156}
156157
157- // 有点丑,看看之后怎么改
158158func addDefaultDoc (api * Api ) {
159159 for _ , s := range api .Service {
160- if s . Doc . Tag == "" {
161- s .Doc . Tag = api .ServiceName
160+ if _ , ok := s . Doc [ "tag" ]; ! ok {
161+ s .Doc [ "tag" ] = [] string { api .ServiceName }
162162 }
163- if s . Doc . Success == "" {
164- s .Doc . Success = fmt .Sprintf ("200 {object} %s" , s .Method .Resp )
163+ if _ , ok := s . Doc [ "success" ]; ! ok {
164+ s .Doc [ "success" ] = [] string { fmt .Sprintf ("200 {object} %s" , s .Method .Resp )}
165165 }
166- if s . Doc . Router == "" {
167- s .Doc . Router = fmt .Sprintf ("%s/%s%s [%s]" , api .Server .Prefix , api .Server .Group , s .Method .Route , s .Method .Method )
166+ if _ , ok := s . Doc [ "router" ]; ! ok {
167+ s .Doc [ "router" ] = [] string { fmt .Sprintf ("%s/%s%s [%s]" , api .Server .Prefix , api .Server .Group , s .Method .Route , s .Method .Method )}
168168 }
169- if s . Doc . Produce == "" {
170- s .Doc . Produce = "json"
169+ if _ , ok := s . Doc [ "produce" ]; ! ok {
170+ s .Doc [ "produce" ] = [] string { "json" }
171171 }
172- if s . Doc . Accept == "" {
173- s .Doc . Accept = "json"
172+ if _ , ok := s . Doc [ "accept" ]; ! ok {
173+ s .Doc [ "accept" ] = [] string { "json" }
174174 }
175- if len ( s .Doc . Param ) == 0 && s .Method .Req != "" {
176- s .Doc . Param = append ( s . Doc . Param , fmt .Sprintf ("request body %s true \" %s参数\" " , s .Method .Req , s .Method .Req ))
175+ if _ , ok := s .Doc [ "param" ]; ! ok && s .Method .Req != "" {
176+ s .Doc [ "param" ] = [] string { fmt .Sprintf ("request body %s true \" %s参数\" " , s .Method .Req , s .Method .Req )}
177177 }
178178 }
179179}
180-
181- func addDoc (d * Doc , before string , after string ) {
182- if before == "summary" {
183- d .Summary = after
184- }
185-
186- if before == "description" {
187- d .Description = after
188- }
189-
190- if before == "tag" {
191- d .Tag = after
192- }
193-
194- if before == "produce" {
195- d .Produce = after
196- }
197-
198- if before == "accept" {
199- d .Accept = after
200- }
201-
202- if before == "success" {
203- d .Success = after
204- }
205-
206- if before == "failure" {
207- d .Failure = after
208- }
209-
210- if before == "param" {
211- d .Param = append (d .Param , after )
212- }
213-
214- if before == "router" {
215- d .Router = after
216- }
217- }
0 commit comments