@@ -9,28 +9,32 @@ function run(url) {
9
9
fetch ( apiUrl )
10
10
. then ( res => res . json ( ) )
11
11
. then ( json => {
12
- const path = buildPath ( apiUrl )
13
- const res = jsonToGo ( JSON . stringify ( json ) , path . struct ) ;
14
- const content = _buildContent ( res . go , path . pkg )
15
- fs . mkdirSync ( path . dir , { recursive : true } )
16
- fs . writeFile ( path . jsonFilePath , JSON . stringify ( json , null , "\t" ) , ( err ) => {
17
- if ( err ) throw err ;
18
- console . log ( `saved: ${ path . jsonFilePath } ` )
19
- } ) ;
20
- fs . writeFile ( path . goFilePath , content , ( err ) => {
21
- if ( err ) throw err ;
22
- console . log ( `generated: ${ path . goFilePath } ` )
23
- } ) ;
12
+ const path = buildPath ( apiUrl )
13
+ const res = jsonToGo ( JSON . stringify ( json ) , path . struct ) ;
14
+ const content = _buildContent ( res . go , path , apiUrl )
15
+ fs . mkdirSync ( path . dir , { recursive : true } )
16
+ fs . writeFile ( path . jsonFilePath , JSON . stringify ( json , null , "\t" ) , ( err ) => {
17
+ if ( err ) throw err ;
18
+ console . log ( `saved: ${ path . jsonFilePath } ` )
19
+ } ) ;
20
+ fs . writeFile ( path . goFilePath , content , ( err ) => {
21
+ if ( err ) throw err ;
22
+ console . log ( `generated: ${ path . goFilePath } ` )
23
+ } ) ;
24
24
}
25
25
) ;
26
26
}
27
27
28
- function _buildContent ( struct , packageName ) {
29
- let content = `package ${ packageName } \n\n`
28
+ function _buildContent ( struct , path , apiUrl ) {
29
+ let content = `package ${ path . pkg } \n\n`
30
30
if ( struct . indexOf ( 'time.' ) !== - 1 ) {
31
31
content = `${ content } import "time"\n\n`
32
32
}
33
- content = `${ content } ${ struct } `
33
+ let comment = `// ${ path . struct } is struct of API's payload.\n`
34
+ comment += `// url: ${ apiUrl } \n`
35
+ if ( path . path . pathFormat ) comment += `// format: ${ path . path . pathFormat } \n`
36
+ comment += `// example: ${ path . jsonFilePath } \n`
37
+ content = `${ content } ${ comment } ${ struct } `
34
38
return content
35
39
}
36
40
0 commit comments