当前位置: 首页>>代码示例>>Golang>>正文


Golang os.Exit函数代码示例

本文整理汇总了Golang中os.Exit函数的典型用法代码示例。如果您正苦于以下问题:Golang Exit函数的具体用法?Golang Exit怎么用?Golang Exit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Exit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: work

func work(c *replicant.Client, C <-chan time.Time, stop chan bool, done chan bool, dl *ygor.DataLogger) {
	defer func() {
		done <- true
	}()
	for {
		select {
		case <-C:
			break
		case <-stop:
			return
		}
		start := time.Now()
		_, err := c.Call("echo", "echo", []byte("hello world"), 0)
		end := time.Now()
		if err.Status == replicant.SUCCESS {
			when := uint64(end.UnixNano())
			data := uint64(end.Sub(start).Nanoseconds())
			er := dl.Record(1, when, data)
			if er != nil {
				fmt.Printf("error: %s\n", er)
				os.Exit(1)
			}
		} else {
			fmt.Printf("error: %s\n", err)
			os.Exit(1)
		}
	}
}
开发者ID:rescrv,项目名称:Replicant,代码行数:28,代码来源:main.go

示例2: NewCmdBuildLogs

// NewCmdBuildLogs implements the OpenShift cli build-logs command
func NewCmdBuildLogs(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
	opts := api.BuildLogOptions{}
	cmd := &cobra.Command{
		Use:        "build-logs BUILD",
		Short:      "Show logs from a build",
		Long:       buildLogsLong,
		Example:    fmt.Sprintf(buildLogsExample, fullName),
		Deprecated: fmt.Sprintf("use \"oc %v build/<build-name>\" instead.", LogsRecommendedCommandName),
		Run: func(cmd *cobra.Command, args []string) {
			err := RunBuildLogs(fullName, f, out, cmd, opts, args)

			if err, ok := err.(errors.APIStatus); ok {
				if msg := err.Status().Message; strings.HasSuffix(msg, buildutil.NoBuildLogsMessage) {
					fmt.Fprintf(out, msg)
					os.Exit(1)
				}
				if err.Status().Code == http.StatusNotFound {
					switch err.Status().Details.Kind {
					case "build":
						fmt.Fprintf(out, "The build %s could not be found.  Therefore build logs cannot be retrieved.\n", err.Status().Details.Name)
					case "pod":
						fmt.Fprintf(out, "The pod %s for build %s could not be found.  Therefore build logs cannot be retrieved.\n", err.Status().Details.Name, args[0])
					}
					os.Exit(1)
				}
			}
			kcmdutil.CheckErr(err)
		},
	}
	cmd.Flags().BoolVarP(&opts.Follow, "follow", "f", true, "Specify whether logs should be followed; default is true.")
	cmd.Flags().BoolVarP(&opts.NoWait, "nowait", "w", false, "Specify whether to return immediately without waiting for logs to be available; default is false.")
	return cmd
}
开发者ID:LalatenduMohanty,项目名称:origin,代码行数:34,代码来源:buildlogs.go

示例3: Build

// Build creates a new Route using the specification details collected by the RouteBuilder
func (b *RouteBuilder) Build() Route {
	pathExpr, err := newPathExpression(b.currentPath)
	if err != nil {
		log.Printf("[restful] Invalid path:%s because:%v", b.currentPath, err)
		os.Exit(1)
	}
	if b.function == nil {
		log.Printf("[restful] No function specified for route:" + b.currentPath)
		os.Exit(1)
	}
	operationName := b.operation
	if len(operationName) == 0 && b.function != nil {
		// extract from definition
		operationName = nameOfFunction(b.function)
	}
	route := Route{
		Method:         b.httpMethod,
		PathPrefix:     b.rootPathPrefix,
		Path:           concatPath(b.rootPath, b.currentPath),
		Produces:       b.produces,
		Consumes:       b.consumes,
		Function:       b.function,
		Filters:        b.filters,
		relativePath:   b.currentPath,
		pathExpr:       pathExpr,
		Doc:            b.doc,
		Notes:          b.notes,
		Operation:      operationName,
		ParameterDocs:  b.parameters,
		ResponseErrors: b.errorMap,
		ReadSample:     b.readSample,
		WriteSample:    b.writeSample}
	route.postBuild()
	return route
}
开发者ID:jaytula,项目名称:go-restful,代码行数:36,代码来源:route_builder.go

示例4: TestLinuxSendfileChild

// TestLinuxSendfileChild isn't a real test. It's used as a helper process
// for TestLinuxSendfile.
func TestLinuxSendfileChild(*testing.T) {
	if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
		return
	}
	defer os.Exit(0)
	fd3 := os.NewFile(3, "ephemeral-port-listener")
	ln, err := net.FileListener(fd3)
	if err != nil {
		panic(err)
	}
	mux := http.NewServeMux()

	fs := &FileServer{
		http.Dir("testdata"),
		inject.CopyInject{},
		ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
	}

	mux.Handle("/", fs)
	mux.HandleFunc("/quit", func(http.ResponseWriter, *http.Request) {
		os.Exit(0)
	})
	s := &http.Server{Handler: mux}
	err = s.Serve(ln)
	if err != nil {
		panic(err)
	}
}
开发者ID:homburg,项目名称:devd,代码行数:30,代码来源:fileserver_test.go

示例5: getAppGuid

func getAppGuid(cliConnection plugin.CliConnection, appName string) string {
	repo := core_config.NewRepositoryFromFilepath(config_helpers.DefaultFilePath(), func(err error) {
		if err != nil {
			fmt.Println("\nERROR:", err)
			os.Exit(1)
		}
	})
	spaceGuid := repo.SpaceFields().Guid

	cmd := []string{"curl", fmt.Sprintf("/v2/spaces/%v/apps?q=name:%v&inline-relations-depth=1", spaceGuid, appName)}
	output, err := cliConnection.CliCommandWithoutTerminalOutput(cmd...)
	if err != nil {
		for _, e := range output {
			fmt.Println(e)
		}
		os.Exit(1)
	}

	search := &Search{}
	if err := json.Unmarshal([]byte(strings.Join(output, "")), &search); err != nil {
		fmt.Println("\nERROR:", err)
		os.Exit(1)
	}

	return search.Resources[0].Metadata.Guid
}
开发者ID:swisscom,项目名称:cf-statistics-plugin,代码行数:26,代码来源:plugin_hook.go

示例6: setBash

func setBash() {
	findcmd := "which"
	if runtime.GOOS == "windows" {
		// Can't use paths returned from which even if it's on PATH in Windows
		// Because our Go binary is a separate Windows app & not MinGW, it
		// can't understand paths like '/usr/bin/bash', needs Windows version
		findcmd = "where"
	}
	out, err := exec.Command(findcmd, "bash").Output()
	if err != nil {
		fmt.Println("Unable to find bash:", err)
		os.Exit(1)
	}

	bashPath = strings.TrimSpace(string(out))
	if debugging {
		fmt.Println("Using", bashPath)
	}

	// Test
	_, err = exec.Command(bashPath, "--version").CombinedOutput()
	if err != nil {
		fmt.Println("Error calling bash:", err)
		os.Exit(1)
	}
}
开发者ID:2012781508623add,项目名称:git-lfs,代码行数:26,代码来源:integration.go

示例7: main

func main() {

	importer, err := New()
	if err != nil {
		fmt.Println(err)
		fmt.Println("Exiting.")
		os.Exit(1)
	}
	if err := importer.CreateIndex(); err != nil {
		fmt.Println(err)
		fmt.Println("Exiting.")
		os.Exit(1)
	}

	if importer.cl.opt.Dir != "" {
		if err = importer.ImportKibana(importer.cl.opt.Dir); err != nil {
			fmt.Println(err)
		}
	} else {
		if importer.cl.opt.URL != "" || importer.cl.opt.File != "" {
			if err = importer.ImportArchive(); err != nil {
				fmt.Println(err)
			}
		}
	}
}
开发者ID:urso,项目名称:beats,代码行数:26,代码来源:import_dashboards.go

示例8: actionUserPasswd

func actionUserPasswd(c *cli.Context) {
	api, user := mustUserAPIAndName(c)
	ctx, cancel := context.WithTimeout(context.Background(), client.DefaultRequestTimeout)
	currentUser, err := api.GetUser(ctx, user)
	cancel()
	if currentUser == nil {
		fmt.Fprintln(os.Stderr, err.Error())
		os.Exit(1)
	}
	pass, err := speakeasy.Ask("New password: ")
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error reading password:", err)
		os.Exit(1)
	}

	ctx, cancel = context.WithTimeout(context.Background(), client.DefaultRequestTimeout)
	_, err = api.ChangePassword(ctx, user, pass)
	cancel()
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		os.Exit(1)
	}

	fmt.Printf("Password updated\n")
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:25,代码来源:user_commands.go

示例9: main

func main() {
	// 以下读取网卡信息
	Interface, err := net.Interfaces()
	if err != nil {
		panic("未发现网卡地址")
		os.Exit(1)
	}

	handwareAddrs = make(map[string]string, len(Interface))
	for _, inter := range Interface {
		inMAC := strings.ToUpper(inter.HardwareAddr.String())
		handwareAddrs[inMAC] = inMAC
	}

	if len(os.Args) != 2 {
		fmt.Println("为保障安全:请先绑定本机上的网卡地址")
		os.Exit(0)
	}

	addr := os.Args[1]
	h, e := net.ParseMAC(addr)
	if e != nil {
		fmt.Println("为保障安全:请先绑定本机上的网卡地址")
		fmt.Println("方法:client.exe 90-4C-E5-58-7E-FE")
		os.Exit(2)
	}
	inputMAC := strings.ToUpper(h.String())
	if inputMAC != handwareAddrs[inputMAC] {
		fmt.Println("网卡地址不匹配")
		os.Exit(0)
	}
}
开发者ID:nemowen,项目名称:golang,代码行数:32,代码来源:mac.go

示例10: TestMain

func TestMain(m *testing.M) {
	if reexec.Init() {
		return
	}

	if err := createController(); err != nil {
		os.Exit(1)
	}
	option := options.Generic{
		"EnableIPForwarding": true,
	}

	genericOption := make(map[string]interface{})
	genericOption[netlabel.GenericData] = option

	err := controller.ConfigureNetworkDriver(bridgeNetType, genericOption)
	if err != nil {
		//m.Fatal(err)
		os.Exit(1)
	}

	libnetwork.SetTestDataStore(controller, datastore.NewCustomDataStore(datastore.NewMockStore()))

	os.Exit(m.Run())
}
开发者ID:hurrygeek,项目名称:libnetwork,代码行数:25,代码来源:libnetwork_test.go

示例11: Parse

func (f *flags_t) Parse(args []string) (err error) {
	for i, arg := range args {
		for _, f := range CommandLine.flags {
			if arg == f.Name {
				CommandLine.Cmd = f
				if err = flag.CommandLine.Parse(args[0:i]); err != nil {
					return
				}
				if err = f.Flag.Parse(args[i+1:]); err != nil {
					return
				}
				if f.h {
					f.Usage()
					os.Exit(0)
				}
			}
		}
	}
	err = flag.CommandLine.Parse(args)
	if CommandLine.h {
		flag.Usage()
		os.Exit(0)
	}
	return
}
开发者ID:yubo,项目名称:falcon,代码行数:25,代码来源:flags.go

示例12: main

func main() {
	input := flag.Arg(0)

	if len(input) == 0 {
		fmt.Fprintln(os.Stderr, "Please provide an input file. (amberc input.amber)")
		os.Exit(1)
	}

	cmp := amber.New()
	cmp.PrettyPrint = prettyPrint
	cmp.LineNumbers = lineNumbers

	err := cmp.ParseFile(input)

	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	err = cmp.CompileWriter(os.Stdout)

	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
开发者ID:fclairamb,项目名称:drone,代码行数:26,代码来源:cli.go

示例13: DFT

func DFT(dirname string, depth int, str string) string {
	d, err := os.Open(dirname)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	defer d.Close()
	fi, err := d.Readdir(-1)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	for _, fi := range fi {
		if fi.Mode().IsRegular() {
			str = str + fi.Name()
		}
		if fi.IsDir() {
			str = str + fi.Name()
			str = DFT(dirname+fi.Name()+string(filepath.Separator), depth+1, str)
		} else {
			data, _ := ioutil.ReadFile(dirname + fi.Name())
			str = str + string(data)
		}
	}
	return str
}
开发者ID:jnhnum1,项目名称:fss,代码行数:26,代码来源:main_v5.go

示例14: main

func main(){
	buf, err := ioutil.ReadFile("test.txt") //Reading the file completely
	if err != nil {                          //error check
		fmt.Println(err)
		os.Exit(1)
	}
	data := string(buf) //bytes to string
	if data[0] == '['{
		result,_ :=arrayParser(data)
		final := result.Array
		for _,k := range final {
			fmt.Println(k)

		}
	}else if data[0] =='{' {
		result,_ :=objParser(data)
		fmt.Println(result)
		k := result.getElement()
		fmt.Println(k)
		/*m := k.(map[string]json)
		for a,b := range m{
			fmt.Println("Key:",a,",Value:",b.getElement())

		}

	}*/
	os.Exit(0)
}
开发者ID:starVader,项目名称:Garbage,代码行数:28,代码来源:newtest.go

示例15: main

func main() {

	if len(os.Args) < 2 {
		fmt.Println("please provide an argument for finding the square root")
		os.Exit(1)
	}

	fval, err := strconv.ParseFloat(os.Args[1], 64)

	if err != nil {
		log.Fatal(err)
	}

	if fval < 0.0 {
		fmt.Println("please provide a positive number")
		os.Exit(1)
	}

	fsqrtval := square_root(fval)
	fmt.Printf("iterative square root of %0.8f is %0.8f\n", fval, fsqrtval)

	fsqrtval_recurse := square_root_r(fval, 0, 0)
	fmt.Printf("recursive square root of %0.8f is %0.8f\n", fval, fsqrtval_recurse)

}
开发者ID:jeffyoungmongodb,项目名称:bootstrapper,代码行数:25,代码来源:sqrt.go


注:本文中的os.Exit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。