Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/natefinch/graffiti
graffiti is a tool to automatically add struct tags to fields in your go code
https://github.com/natefinch/graffiti
Last synced: 11 days ago
JSON representation
graffiti is a tool to automatically add struct tags to fields in your go code
- Host: GitHub
- URL: https://github.com/natefinch/graffiti
- Owner: natefinch
- License: mit
- Created: 2014-12-06T11:40:56.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-07-05T17:30:50.000Z (4 months ago)
- Last Synced: 2024-10-12T06:43:56.123Z (27 days ago)
- Language: Go
- Size: 262 KB
- Stars: 39
- Watchers: 4
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
graffiti
========Graffiti is a tool to automatically add struct tags to fields in your go code.
### Gen Command
Generates struct tags for a specific target (file or directory).```
Usage:
graffiti gen [target] [flags]Available Flags:
-d, --dryrun If set, changes are written to stdout instead of to the files.
-f, --format If set, tags is a go template (see help templates).
-m, --map="" Map field names to alternate tag names (see help mappings).
-t, --types="" Generate tags only for these types (comma separated list).
```If no target is given, all go files in the current directory are processed. By
default tags is a comma-separated list of schema names like json or yaml. The
value for a field's tag is the lowercase of the field name. Only exported fields
have tags generated.For example,
`graffiti gen json,yaml foo.go`
where foo.go looks like this:
```go
package footype foo struct {
ID string
Name string
mu sync.Mutex
}
```Will produce the following output:
```go
package footype foo struct {
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"yaml"`
mu sync.Mutex
}
```### Run Command
Reads graffiti commands from a go file and executes them.
```
Usage:
graffiti run
```The run command parses go files, looking for comments with the prefix `graffiti:
`. All text following this prefix is used as the command line for graffiti.The commands are always passed to the graffiti gen command, and the current file
is assumed to be the target if no target is given. If there are multiple
graffiti commands in the file, all will be run in sequence. Flags can be used
as usual, and the embedded CLI supports single and double quotes for arguments
similar to how /bin/sh works.For example this command embedded in the foo.go file:
// graffiti: -t MyStruct json,yaml
is equivalent to this command line invocation:
graffiti gen -t MyStruct json,yaml foo.go