@@ -9,9 +9,10 @@ function run(url) {
9
9
fetch ( apiUrl )
10
10
. then ( res => res . json ( ) )
11
11
. then ( json => {
12
- const path = buildPath ( apiUrl )
12
+ const url = new URL ( apiUrl ) ;
13
+ const path = buildPath ( url )
13
14
const res = jsonToGo ( JSON . stringify ( json ) , path . struct ) ;
14
- const content = _buildContent ( res . go , path , apiUrl )
15
+ const content = _buildContent ( res . go , path , url )
15
16
fs . mkdirSync ( path . dir , { recursive : true } )
16
17
fs . writeFile ( path . jsonFilePath , JSON . stringify ( json , null , "\t" ) , ( err ) => {
17
18
if ( err ) throw err ;
@@ -25,13 +26,18 @@ function run(url) {
25
26
) ;
26
27
}
27
28
28
- function _buildContent ( struct , path , apiUrl ) {
29
+ function _buildContent ( struct , path , url ) {
29
30
let content = `package ${ path . pkg } \n\n`
30
31
if ( struct . indexOf ( 'time.' ) !== - 1 ) {
31
32
content = `${ content } import "time"\n\n`
32
33
}
33
- let comment = `// ${ path . struct } ${ apiUrl } `
34
- if ( path . path . pathFormat ) comment += ` (${ path . path . pathFormat } )`
34
+ let comment = `// ${ path . struct } is the go struct of api's payload.`
35
+ if ( path . path . pathFormat ) {
36
+ comment += `\n// url ${ url . origin } ${ path . path . pathFormat } `
37
+ comment += `\n// example ${ url . href } `
38
+ } else {
39
+ comment += `\n// url ${ url . href } `
40
+ }
35
41
content = `${ content } ${ comment } \n${ struct } `
36
42
return content
37
43
}
0 commit comments