本文整理匯總了Golang中github.com/mholt/custombuild.Builder.Build方法的典型用法代碼示例。如果您正苦於以下問題:Golang Builder.Build方法的具體用法?Golang Builder.Build怎麽用?Golang Builder.Build使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mholt/custombuild.Builder
的用法示例。
在下文中一共展示了Builder.Build方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: saveCaddy
func saveCaddy(builder custombuild.Builder, file string, buildArgs []string) error {
goos := os.Getenv("GOOS")
goarch := os.Getenv("GOARCH")
goarm, _ := strconv.Atoi(os.Getenv("GOARM"))
if goarch == "arm" {
return builder.BuildARM(goos, goarm, file, buildArgs...)
}
return builder.Build(goos, goarch, file, buildArgs...)
}
示例2: main
func main() {
// parse cli arguments.
args, err := parseArgs()
exitIfErr(err)
// read config file.
config, err := readConfig(args)
exitIfErr(err)
fetched := false
// if caddy source does not exits, pull source.
if !isLocalPkg(caddybuild.CaddyPackage) {
fmt.Print("Caddy source not found. Fetching...")
err := fetchCaddy()
exitIfErr(err)
fmt.Println(" done.")
fetched = true
}
// if update flag is set, pull source.
if args.update && !fetched {
fmt.Print("Updating caddy source...")
err := fetchCaddy()
exitIfErr(err)
fmt.Println(" done.")
}
caddybuild.SetConfig(config)
var builder custombuild.Builder
var f *os.File
var caddyProcess *os.Process
// remove temp files.
addCleanUpFunc(func() {
if caddyProcess != nil {
caddyProcess.Kill()
}
builder.Teardown()
if f != nil {
os.Remove(f.Name())
}
})
builder, err = caddybuild.PrepareBuild(features.Middlewares{config.Middleware})
exitIfErr(err)
// if output is set, generate binary only.
if args.output != "" {
err := saveCaddy(builder, args.output, args.goArgs)
exitIfErr(err)
return
}
// create temporary file for binary
f, err = ioutil.TempFile("", "caddydev")
exitIfErr(err)
f.Close()
// perform custom build
err = builder.Build("", "", f.Name(), args.goArgs...)
exitIfErr(err)
fmt.Println("Starting caddy...")
// trap os interrupts to ensure cleaning up temp files.
done := trapInterrupts()
// start custom caddy.
go func() {
cmd, err := startCaddy(f.Name(), args.caddyArgs)
exitIfErr(err)
caddyProcess = cmd.Process
err = cmd.Wait()
cleanUp()
exitIfErr(err)
done <- struct{}{}
}()
// wait for exit signal
<-done
}