Skip to content

Commit 62d79ee

Browse files
committed
💄 Update Go struct comment.
1 parent 8121db0 commit 62d79ee

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/run.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ function run(urlStr, body, options) {
2828
cfg = loadConfig(url, cliOpts.config)
2929
path = buildPath(url, cliOpts.config)
3030

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}`)
3536

3637
comment = buildComment(url, path, opts.method, res)
3738
return res.json()
@@ -56,7 +57,7 @@ function write(json, path, content) {
5657
if (err) throw err;
5758
});
5859
console.log()
59-
console.log("Saved:")
60+
console.log("Generated Files:")
6061
console.log(` Struct: ${path.goFilePath}`)
6162
console.log(` Payload: ${path.jsonFilePath}`)
6263
}
@@ -92,30 +93,35 @@ function buildOpts(body, cliOpts) {
9293
}
9394

9495
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+
`
96102
content += `package ${path.pkg}\n\n`
97103
if (go.indexOf('time.') !== -1) {
98104
content += `${content}import "time"\n\n`
99105
}
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//`
102107
content += comment
103108
content += go
104109
return content
105110
}
106111

107112
function buildComment(url, path, method, res) {
108113
let comment = ""
114+
comment += `\n//\tStatus: ${res.status} ${res.statusText}`
115+
comment += `\n//\tRequest: ${method} ${url.href}`
116+
109117
const cfg = loadConfig(url, cliOpts.config)
110-
if (cfg?.["docs"] !== undefined) {
111-
comment += `\n// Docs: ${cfg?.["docs"]}`
112-
}
113118
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"]}`
115123
}
116-
comment += `\n// Request: ${method} ${url.href}`
117-
comment += `\n// Response: ${res.status} ${res.statusText}`
118-
return `${comment}\n//\n`
124+
return `${comment}\n`
119125
}
120126

121127
module.exports = run;

0 commit comments

Comments
 (0)