https://github.com/switchupcb/xstruct
xstruct extracts any package's structs, functions, or global variables to a single file.
https://github.com/switchupcb/xstruct
code-generation code-generator extract generator go golang
Last synced: about 1 year ago
JSON representation
xstruct extracts any package's structs, functions, or global variables to a single file.
- Host: GitHub
- URL: https://github.com/switchupcb/xstruct
- Owner: switchupcb
- License: agpl-3.0
- Created: 2025-03-07T16:08:52.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-11T15:36:26.000Z (over 1 year ago)
- Last Synced: 2025-04-11T00:13:23.508Z (about 1 year ago)
- Topics: code-generation, code-generator, extract, generator, go, golang
- Language: Go
- Homepage: https://switchupcb.com/xstruct-license-exception/
- Size: 28.3 KB
- Stars: 13
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Extract a package's structs, functions, or global variables.
[](https://pkg.go.dev/github.com/switchupcb/xstruct)
[](https://github.com/switchupcb/xstruct/blob/main/LICENSE)
Use `xstruct` to stop wasting time refactoring and debugging projects.
## What is xstruct?
`xstruct` helps you extract any package's structs, functions, or global variables to a single file.
## Table of Contents
| Topic |
| :------------------------------------------------------ |
| [Using `xstruct`](#how-do-you-use-xstruct) |
| [Usecases](#when-do-you-use-xstruct) |
| [License](#what-is-the-license) |
| [License Exception](#what-can-you-do-with-this-license) |
## How do you use xstruct?
Install the command line tool: `xstruct`.
```
go install github.com/switchupcb/xstruct@latest
```
Run the executable with the following flags.
```bash
xstruct -d relative/path/to/dir
```
| Flag | Description | Usage |
| :--- | :-------------------------------------- | :--------------------------------------------------- |
| `-d` | Directory to extract. | `-d relative/path/to/dir` (`/...` for nested search) |
| `-p` | Set the output file's package. | `-p xstruct` (`xstruct` by default) |
| `-g` | Extract global variables and constants. | `-g` |
| `-f` | Extract function declarations. | `-f` |
| `-s` | Sort the extracted objects. | `-s` |
| `>` | Pipe standard output to a file. | `> file.go` |
_Note: Using `-g` and `-f` extracts additional declarations **in addition** to structs._
## When do you use xstruct?
You can use `xstruct` to stop wasting time refactoring and debugging projects.
**Here is Open Source Software using `xstruct`.**
| Software | Description | `xstruct` Use |
| :--------------------------------------------- | :---------------------------------- | :-------------------------------------------------------------------------------------------------------------------- |
| [`disgo`](https://github.com/switchupcb/disgo) | API Wrapper (SDK Client) | Disgo uses `xstruct` to combine a Go type library into a single file, which code is generated from. |
| [`dbgo`](https://github.com/switchupcb/dbgo) | Database Consumer Package Generator | `dbgo` uses `xstruct` to combine generated database models into a single file, which can be used with an interpreter. |
## What is the license?
`xstruct` uses an [AGPLv3 License](https://www.gnu.org/licenses/agpl-3.0.en.html).
## What can you do with this license?
**Code generated by `xstruct` can be used without restriction (including proprietary and commercial usage) since generated code is not considered a derivative work.** However, modifications to the `xstruct` Software Source Code or implementing `xstruct` in a larger work programmatically requires you to adhere to the AGPLv3 License.
_Read the [GPL FAQ](https://www.gnu.org/licenses/gpl-faq.html) for more information._
## What is a license exception?
A license exception lets you modify and use `xstruct` programmatically without restriction.
You can receive a license exception for `xstruct` by contacting SwitchUpCB using the [`xstruct` License Exception Inquiry Form](https://switchupcb.com/xstruct-license-exception/).