@@ -28,10 +28,11 @@ function run(urlStr, body, options) {
28
28
cfg = loadConfig ( url , cliOpts . config )
29
29
path = buildPath ( url , cliOpts . config )
30
30
31
- if ( cfg ?. [ "docs" ] !== undefined ) console . log ( `Docs: ${ cfg ?. [ "docs" ] } ` )
32
- if ( path . path . pathFormat ) console . log ( `Format: ${ path . path . pathFormat } ` )
33
- console . log ( `Request: ${ opts . method } ${ url } ` )
34
- console . log ( `Response: ${ res . status } ${ res . statusText } ` )
31
+ console . log ( `API Info:` )
32
+ if ( cfg ?. [ "docs" ] !== undefined ) console . log ( ` Docs: ${ cfg ?. [ "docs" ] } ` )
33
+ if ( path . path . pathFormat ) console . log ( ` Format: ${ path . path . pathFormat } ` )
34
+ console . log ( ` Request: ${ opts . method } ${ url } ` )
35
+ console . log ( ` Response: ${ res . status } ${ res . statusText } ` )
35
36
36
37
comment = buildComment ( url , path , opts . method , res )
37
38
return res . json ( )
@@ -56,7 +57,7 @@ function write(json, path, content) {
56
57
if ( err ) throw err ;
57
58
} ) ;
58
59
console . log ( )
59
- console . log ( "Saved :" )
60
+ console . log ( "Generated Files :" )
60
61
console . log ( ` Struct: ${ path . goFilePath } ` )
61
62
console . log ( ` Payload: ${ path . jsonFilePath } ` )
62
63
}
@@ -92,30 +93,35 @@ function buildOpts(body, cliOpts) {
92
93
}
93
94
94
95
function buildContent ( go , path , comment ) {
95
- let content = `// Code generated by api-to-go (https://github.com/nkmr-jp/api-to-go).\n\n`
96
+ let content = `// Generated Code But Editable.
97
+ // Format The Code with \`go fmt\` or something and edit it manually to use it.
98
+ //
99
+ // Generated by: api-to-go (https://github.com/nkmr-jp/api-to-go).
100
+
101
+ `
96
102
content += `package ${ path . pkg } \n\n`
97
103
if ( go . indexOf ( 'time.' ) !== - 1 ) {
98
104
content += `${ content } import "time"\n\n`
99
105
}
100
-
101
- content += `// ${ go . split ( " " ) [ 1 ] } is the go struct of api's payload.\n//`
106
+ content += `// ${ go . split ( " " ) [ 1 ] } represents the response body from an HTTP request.\n//`
102
107
content += comment
103
108
content += go
104
109
return content
105
110
}
106
111
107
112
function buildComment ( url , path , method , res ) {
108
113
let comment = ""
114
+ comment += `\n//\tStatus: ${ res . status } ${ res . statusText } `
115
+ comment += `\n//\tRequest: ${ method } ${ url . href } `
116
+
109
117
const cfg = loadConfig ( url , cliOpts . config )
110
- if ( cfg ?. [ "docs" ] !== undefined ) {
111
- comment += `\n// Docs: ${ cfg ?. [ "docs" ] } `
112
- }
113
118
if ( path . path . pathFormat ) {
114
- comment += `\n// Format: ${ path . path . pathFormat } `
119
+ comment += `\n//\tFormat: ${ path . path . pathFormat } `
120
+ }
121
+ if ( cfg ?. [ "docs" ] !== undefined ) {
122
+ comment += `\n//\tDocs: ${ cfg ?. [ "docs" ] } `
115
123
}
116
- comment += `\n// Request: ${ method } ${ url . href } `
117
- comment += `\n// Response: ${ res . status } ${ res . statusText } `
118
- return `${ comment } \n//\n`
124
+ return `${ comment } \n`
119
125
}
120
126
121
127
module . exports = run ;
0 commit comments