本文整理匯總了Golang中github.com/mholt/custombuild.Builder類的典型用法代碼示例。如果您正苦於以下問題:Golang Builder類的具體用法?Golang Builder怎麽用?Golang Builder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Builder類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: prepareBuild
func prepareBuild(args cliArgs, config caddybuild.Config) (App, error) {
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(config.Plugins, false)
exitIfErr(err)
// if output is set, generate binary only.
if args.output != "" {
err := saveCaddy(builder, args.output, args.goArgs)
exitIfErr(err)
os.Exit(0)
}
// create temporary file for binary
f, err = ioutil.TempFile("", "caddydev")
exitIfErr(err)
f.Close()
// fix for windows exe
fName := f.Name()
if runtime.GOOS == "windows" {
fName += ".exe"
}
return &caddyApp{
file: fName,
goArgs: args.goArgs,
caddyArgs: args.caddyArgs,
builder: builder,
}, nil
}
示例3: 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
}