Skip to content

Commit 67534b1

Browse files
committed
🚧 Add api-to-go
1 parent 64188a3 commit 67534b1

File tree

5 files changed

+103
-0
lines changed

5 files changed

+103
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea
2+
vendor
3+
node_modules
4+
.gitignore
5+
*.go

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
11
# api-to-go
2+
3+
# Install
4+
```sh
5+
npm install -g api-to-go
6+
```
7+
8+
```sh
9+
api-to-go https://api.github.com/users/github
10+
```
11+
12+
# Development
13+
14+
```sh
15+
# Make the command available
16+
npm link
17+
18+
# Commands
19+
api-to-go
20+
21+
# Publish
22+
npm publish --access=public
23+
```

bin/api-to-go.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /usr/bin/env node
2+
const fetch = require('node-fetch');
3+
const fs = require('fs');
4+
5+
6+
const jsonToGo = require('../vendor/json-to-go/json-to-go.js');
7+
8+
if (process.argv.length !== 3) {
9+
console.log("parameter is wrong.")
10+
return
11+
}
12+
13+
fetch(process.argv[2])
14+
.then(res =>res.json())
15+
.then(json => {
16+
let res = jsonToGo(JSON.stringify(json), 'AutoGenerated');
17+
fs.writeFile("hoge.go", res.go, (err) => {
18+
if (err) throw err;
19+
console.log('generated.');
20+
});
21+
return console.log( res.go );
22+
}
23+
);
24+
25+

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "api-to-go",
3+
"version": "0.0.1",
4+
"repository": "[email protected]:nkmr-jp/api-to-go.git",
5+
"author": "nkmr-jp <[email protected]>",
6+
"license": "MIT",
7+
"bugs": {
8+
"url": "https://github.com/nkmr-jp/api-to-go/issues"
9+
},
10+
"homepage": "https://github.com/nkmr-jp/api-to-go#readme",
11+
"scripts": {
12+
"patch-release": "npm version patch && npm publish --access=public && git push --follow-tags",
13+
"clone": "mkdir -p vendor && cd vendor && git clone https://github.com/mholt/json-to-go.git",
14+
"build": "..."
15+
},
16+
"description": "Convert Rest API's JSON payload to Golang struct.",
17+
"bin": {
18+
"api-to-go": "bin/api-to-go.js"
19+
},
20+
"dependencies": {
21+
"node-fetch": "2"
22+
}
23+
}

yarn.lock

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
node-fetch@2:
6+
version "2.6.7"
7+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
8+
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
9+
dependencies:
10+
whatwg-url "^5.0.0"
11+
12+
tr46@~0.0.3:
13+
version "0.0.3"
14+
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
15+
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
16+
17+
webidl-conversions@^3.0.0:
18+
version "3.0.1"
19+
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
20+
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==
21+
22+
whatwg-url@^5.0.0:
23+
version "5.0.0"
24+
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
25+
integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==
26+
dependencies:
27+
tr46 "~0.0.3"
28+
webidl-conversions "^3.0.0"

0 commit comments

Comments
 (0)