Giter Site home page Giter Site logo

graffiti's Introduction

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 <tags> [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:

package foo

type foo struct {
	ID   string
	Name string
	mu   sync.Mutex
}

Will produce the following output:

package foo

type 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 <file>

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

graffiti's People

Contributors

natefinch avatar liilac avatar mattatcha avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.