github.com/jasonish/buffalo@v0.8.2-0.20170413145823-bacbdd415f1b/generators/goth/goth.go (about) 1 package goth 2 3 import ( 4 "path/filepath" 5 6 "github.com/gobuffalo/buffalo/generators" 7 "github.com/gobuffalo/makr" 8 ) 9 10 // New actions/auth.go file configured to the specified providers. 11 func New() (*makr.Generator, error) { 12 g := makr.New() 13 files, err := generators.Find("goth") 14 if err != nil { 15 return nil, err 16 } 17 for _, f := range files { 18 g.Add(makr.NewFile(f.WritePath, f.Body)) 19 } 20 g.Add(&makr.Func{ 21 Should: func(data makr.Data) bool { return true }, 22 Runner: func(root string, data makr.Data) error { 23 err := generators.AddInsideAppBlock("auth := app.Group(\"/auth\")", 24 "auth.GET(\"/{provider}\", buffalo.WrapHandlerFunc(gothic.BeginAuthHandler))", 25 "auth.GET(\"/{provider}/callback\", AuthCallback)") 26 if err != nil { 27 return err 28 } 29 return generators.AddImport(filepath.Join("actions", "app.go"), "github.com/markbates/goth/gothic") 30 }, 31 }) 32 g.Add(makr.NewCommand(makr.GoGet("github.com/markbates/goth/..."))) 33 g.Add(makr.NewCommand(makr.GoFmt())) 34 return g, nil 35 }