https://github.com/reflog/struct2interface
CLI Tool to extract an Interface from a Golang struct using AST
https://github.com/reflog/struct2interface
ast go refactoring struct
Last synced: 8 months ago
JSON representation
CLI Tool to extract an Interface from a Golang struct using AST
- Host: GitHub
- URL: https://github.com/reflog/struct2interface
- Owner: reflog
- License: mit
- Created: 2020-02-06T10:36:33.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-08T10:00:06.000Z (almost 6 years ago)
- Last Synced: 2025-05-04T03:34:47.950Z (8 months ago)
- Topics: ast, go, refactoring, struct
- Language: Go
- Size: 20.5 KB
- Stars: 20
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# struct2interface
struct2interface is a CLI utility to extract an interface from a Golang struct
## Installation
```bash
go get github.com/reflog/struct2interface
```
## Usage
```bash
struct2interface --help
Usage:
struct2interface [flags]
Flags:
-f, --folder string Path to the package in which the struct resides
-h, --help help for struct2interface
-i, --interface string Name of the output interface
-o, --output string Path to output file (will be overwritten)
-p, --package string Name of the package in which the struct resides
-s, --struct string Name of the input struct
-t, --template string Path to a Go template file to use for writing the resulting interface
struct2interface -f "/home/reflog/go/src/github.com/mattermost/mattermost-server/app" -o "/home/reflog/go/src/github.com/mattermost/mattermost-server/
app/app_iface.go" -p "app" -s "App" -i "AppIface"
```
## Other tools
Before writing this, I tried the following projects, but encountered issues:
[Interfacer](https://github.com/rjeczalik/interfaces) - incredibly slow, dumps odd messages to stderr and writes fully qualified package name instead of localized one, i.e. `*github.com/mattermost/mattermost-server/v5/model.Config` instead of `*model.Config`
[Ifacemaker](https://github.com/vburenin/ifacemaker) - created duplicate imports (in my case `"html/template"` and `"text/template"`)
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
## License
[MIT](https://choosealicense.com/licenses/mit/)