github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/genny/build/options.go (about) 1 package build 2 3 import ( 4 "os" 5 "sync" 6 "time" 7 8 "github.com/gobuffalo/meta" 9 ) 10 11 // Options for building a Buffalo application 12 type Options struct { 13 meta.App 14 // the "timestamp" of the build. defaults to time.Now() 15 BuildTime time.Time `json:"build_time,omitempty"` 16 // the "version" of the build. defaults to 17 // a) git sha of last commit or 18 // b) to time.RFC3339 of BuildTime 19 BuildVersion string `json:"build_version,omitempty"` 20 // CleanAssets will remove the public/assets folder build compiling 21 CleanAssets bool `json:"clean_assets"` 22 WithAssets bool `json:"with_assets,omitempty"` 23 WithBuildDeps bool `json:"with_build_deps,omitempty"` 24 // places ./public/assets into ./bin/assets.zip. 25 // requires WithAssets = true 26 ExtractAssets bool `json:"extract_assets,omitempty"` 27 // LDFlags to be passed to the final `go build` command 28 LDFlags string `json:"ld_flags,omitempty"` 29 // Tags to be passed to the final `go build` command 30 Tags meta.BuildTags `json:"tags,omitempty"` 31 // BuildFlags to be passed to the final `go build` command 32 BuildFlags []string `json:"build_flags,omitempty"` 33 // Static sets the following flags for the final `go build` command: 34 // -linkmode external 35 // -extldflags "-static" 36 Static bool `json:"static,omitempty"` 37 // Environment the binary is meant for. defaults to "development" 38 Environment string `json:"environment,omitempty"` 39 // TemplateValidators can be used to validate the applications templates. 40 // Empty by default 41 TemplateValidators []TemplateValidator `json:"-"` 42 // Mod is the -mod flag 43 Mod string `json:"mod"` 44 // GoCommand is the `go X` command to be used. Default is "build". 45 GoCommand string `json:"go_command"` 46 rollback *sync.Map 47 keep *sync.Map 48 } 49 50 // Validate that options are usuable 51 func (opts *Options) Validate() error { 52 pwd, _ := os.Getwd() 53 if opts.App.IsZero() { 54 opts.App = meta.New(pwd) 55 } 56 if len(opts.Environment) == 0 { 57 opts.Environment = "development" 58 } 59 if opts.BuildTime.IsZero() { 60 opts.BuildTime = time.Now() 61 } 62 if len(opts.BuildVersion) == 0 { 63 opts.BuildVersion = opts.BuildTime.Format(time.RFC3339) 64 } 65 if opts.rollback == nil { 66 opts.rollback = &sync.Map{} 67 } 68 if opts.keep == nil { 69 opts.keep = &sync.Map{} 70 } 71 if len(opts.GoCommand) == 0 { 72 opts.GoCommand = "build" 73 } 74 return nil 75 }