feat: json2go (#130)

* feat(json2go): implement

* feat(json2go): support manual input

* chore(readme): add json2go

* chore(docs): add docs
This commit is contained in:
Oleksandr Smirnov 2025-12-08 21:29:34 +02:00 committed by GitHub
parent 4a2384ade8
commit 6a3924cee5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 312 additions and 1 deletions

View file

@ -62,6 +62,7 @@ Requirements:
- [impl](https://github.com/josharian/impl)
- [gotests](https://github.com/cweill/gotests)
- [iferr](https://github.com/koron/iferr)
- [json2go](https://github.com/olexsmir/json2go)
</details>
<details>
@ -185,6 +186,24 @@ Requirements:
```
</details>
<details>
<summary>
<b>Convert json to Go types</b>
</summary>
![Convert JSON to Go types](./vhs/json2go.gif)
`:GoJson` opens a temporary buffer where you can paste or write JSON.
Saving the buffer (`:w` or `:wq`) automatically closes it and inserts the generated Go struct into the original buffer at the cursor position.
Alternatively, you can pass JSON directly as an argument:
```vim
:GoJson {"name": "Alice", "age": 30}
```
Additionally, `gopher.json2go` provides lua api, see `:h gopher.nvim-json2go` for details.
</details>
<details>
<summary>
@ -253,6 +272,15 @@ require("gopher").setup {
-- e.g: `message = 'fmt.Errorf("failed to %w", err)'`
message = nil,
},
json2go = {
-- command used to open interactive input.
-- e.g: `split`, `botright split`, `tabnew`
interactive_cmd = "vsplit",
-- name of autogenerated struct
-- e.g: "MySuperCoolName"
type_name = nil,
},
}
```