github.com/fedir/buffalo@v0.11.1/generators/action/generator.go (about) 1 package action 2 3 import ( 4 "errors" 5 6 "github.com/gobuffalo/buffalo/meta" 7 "github.com/markbates/inflect" 8 ) 9 10 // Generator for generating new actions 11 type Generator struct { 12 App meta.App `json:"app"` 13 Name inflect.Name `json:"name"` 14 Method string `json:"method"` 15 SkipTemplate bool `json:"skip_template"` 16 Actions []inflect.Name `json:"actions"` 17 Args []string `json:"args"` 18 } 19 20 // New returns a well formed set of Options 21 // for generating new actions 22 func New(args ...string) (Generator, error) { 23 o := Generator{ 24 App: meta.New("."), 25 Actions: []inflect.Name{}, 26 Args: args, 27 Method: "GET", 28 } 29 if len(args) < 2 { 30 return o, errors.New("you need to provide at least an action name and handler name") 31 } 32 o.Name = inflect.Name(args[0]) 33 for _, a := range args[1:] { 34 o.Actions = append(o.Actions, inflect.Name(a)) 35 } 36 37 return o, nil 38 }