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


Golang log.Exit函数代码示例

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


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

示例1: main

func main() {
	var straddr string
	flag.StringVar(&straddr, "a", "", "Address of the exporter")
	flag.Parse()
	if straddr == "" {
		flag.Usage()
		log.Exit("No address given")
	}
	bstdin := bufio.NewReader(os.Stdin)
	var err os.Error
	done := make(chan os.Error)
	imp, err := netchan.NewImporter("tcp", straddr)
	if err != nil {
		log.Exit("Error creating importer: ", err)
	}
	go func() {
		for line, err := bstdin.ReadString('\n'); err == nil; line, err = bstdin.ReadString('\n') {
			go importChan(imp, strings.TrimSpace(line), done)
			go func() {
				err := <-done
				log.Println(err)
			}()
		}
		log.Exit("Error reading stdin: ", err)
	}()
	<-done
}
开发者ID:soul9,项目名称:experiments.go,代码行数:27,代码来源:importer.go

示例2: main

func main() {
	addr, err := net.ResolveTCPAddr("127.0.0.1:4009")
	if err != nil {
		log.Exit("error:", err)
	}
	listener, err := net.ListenTCP("tcp", addr)
	if err != nil {
		log.Exit("error", err)
	}

	//1 channel for incoming connections, another for client communication
	connections := make(chan *net.TCPConn)
	clients := make(chan TClient)
	cMap := make(map[string]*net.TCPConn)
	fMap := make(map[string]string)

	go ListenConnections(listener, connections, clients)
	log.Stdout("Waiting for connections\n")
	for {
		select {
		case conn := <-connections:
			cMap[conn.RemoteAddr().String()] = conn
		case client := <-clients:
			if regexp.MustCompile("^have ").MatchString(client.msg) {
				fMap[string(client.msg[5:len(client.msg)])] = client.local
			}
			if regexp.MustCompile("^list").MatchString(client.msg) {
				for key, value := range fMap {
					cMap[client.forserver].Write(strings.Bytes(key + "->" + value))
				}
				cMap[client.forserver].Write(strings.Bytes("\n"))
			}
		}
	}
}
开发者ID:WalterShe,项目名称:gop2p,代码行数:35,代码来源:server.go

示例3: audioServer

func audioServer() {
	// Native Client requires that all audio calls
	// original from a single OS thread.
	runtime.LockOSThread()

	n, err := av.AudioStream(nil)
	if err != nil {
		log.Exit(err)
	}
	for {
		b := <-sndc
		for len(b)*2 >= n {
			var a []uint16
			a, b = b[0:n/2], b[n/2:]
			n, err = av.AudioStream(a)
			if err != nil {
				log.Exit(err)
			}
			println(n, len(b)*2)
		}
		a := make([]uint16, n/2)
		for i := range b {
			a[i] = b[i]
		}
		n, err = av.AudioStream(a)
	}
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:27,代码来源:4s.go

示例4: newIRC

func newIRC(c net.Conn) (irc *IRC) {
	irc = &IRC{Reader: make(chan string, 10), Writer: make(chan string, 10)}

	// start reader
	go func(r *bufio.Reader) {
		for {
			line, err := r.ReadString('\n')
			if err != nil {
				log.Exit("Unable to read from channel", err)
			}
			log.Stdoutf("Read: %#v", line)
			irc.Reader <- line
		}
	}(bufio.NewReader(c))

	// start writer
	go func(w *bufio.Writer) {
		for {
			line := <-irc.Writer
			_, err := w.WriteString(line)
			if err != nil {
				log.Exit("Unable to write to channel", err)
			}
			err = w.Flush()
			if err != nil {
				log.Exit("Unable to write to channel", err)
			}
			log.Stdoutf("Wrote: %#v", line)
		}
	}(bufio.NewWriter(c))

	return irc
}
开发者ID:davecheney,项目名称:gobot,代码行数:33,代码来源:irc.go

示例5: main

func main() {
	// Read the string
	inputReader := bufio.NewReader(os.Stdin)

	var info = Metadata{"", uint32(0), nil}
	var cmd = Command{"", nil, nil, nil, ""}

	infoJson, err := inputReader.ReadString('\n')
	if err != nil {
		log.Exit(err)
	} else {
		json.Unmarshal(infoJson, &info)
	}

	bpt, bperr := bptree.NewBpTree(info.Filename, info.Keysize, info.Fieldsizes)
	if !bperr {
		log.Exit("Failed B+ tree creation")
	} else {
		fmt.Println("ok")
	}

	alive := true

	for alive {
		cmdJson, err := inputReader.ReadString('\n')
		if err != nil {
			alive = false
			break
		}
		if cmdJson == "q\n" {
			alive = false
		} else {
			json.Unmarshal(cmdJson, &cmd)
			if cmd.Op == "insert" {
				result := bpt.Insert(cmd.LeftKey, cmd.Fields)
				fmt.Println(result)
			} else if cmd.Op == "find" {
				records, ack := bpt.Find(cmd.LeftKey, cmd.RightKey)
				for record := range records {
					json.Marshal(os.Stdout, map[string]interface{}{
						"key":   record.GetKey(),
						"value": record.AllFields()})
					fmt.Println()
					ack <- true
				}
				fmt.Println("end")
			} else if cmd.Op == "visualize" {
				bptree.Dotty(cmd.FileName, bpt)
			} else if cmd.Op == "prettyprint" {
				s := fmt.Sprintln(bpt)
				f, _ := os.Open(cmd.FileName, os.O_RDWR|os.O_CREAT, 0666)
				f.Write([]byte(s))
				f.Close()
			}
		}
	}
	fmt.Println("exited")
}
开发者ID:andradeandrey,项目名称:Go-Filestructures,代码行数:58,代码来源:b+bot.go

示例6: allocate

// Allocates a new key block. This isn't quite as convient as the method
// for BTrees as we have to tell it if we are allocating an internal or an
// external block.
func (self *BpTree) allocate(dim *BlockDimensions) *KeyBlock {
	if dim != self.external && dim != self.internal {
		log.Exit("Cannot allocate a block that has dimensions that are niether the dimensions of internal or external nodes.")
	}
	block, ok := NewKeyBlock(self.bf, dim)
	if !ok {
		log.Exit("Could not allocate block PANIC")
	}
	return block
}
开发者ID:andradeandrey,项目名称:Go-Filestructures,代码行数:13,代码来源:util.go

示例7: main

func main() {
	if len(os.Args) != 2 {
		log.Exit("Usage: " + os.Args[0] + " n")
	}
	i, err := strconv.Atoi(os.Args[1])
	if err != nil {
		log.Exit(err)
	}
	res := fib(i)
	println(res)
}
开发者ID:tokuhirom,项目名称:go-examples,代码行数:11,代码来源:fib.go

示例8: InitTables

func InitTables(dbh *sqlite3.Handle) {
	st, err := dbh.Prepare("CREATE TABLE IF NOT EXISTS entry (id INTEGER PRIMARY KEY, body VARCHAR(255));")
	if err != "" {
		log.Exit(err)
	}
	if st.Step() != sqlite3.SQLITE_DONE {
		log.Exit(dbh.ErrMsg())
	}
	if st.Finalize() != sqlite3.SQLITE_OK {
		log.Exit(dbh.ErrMsg())
	}
}
开发者ID:tokuhirom,项目名称:go-examples,代码行数:12,代码来源:bbs.go

示例9: main

func main() {
	// Dial freenode
	log.Stdout("Dialing server")
	server, err := IRCDial("tcp", "", "irc.freenode.net:6667") // TODO: make this not hardcoded
	if err != nil {
		log.Exit("Dialing error:", err)
	}
	// Login to the server
	log.Stdout("Logging in to server")
	server.Login("goo_bot", FlagInvisible)
	// Send a PM to NickServ to identify
	log.Stdout("Identifying to Nickserv")
	server.PrivMsg("NickServ", "identify go_bot turing")
	// Join a chat
	log.Stdout("Joining #bottest")
	bottest, _ := server.Join("#bottest") // TODO: log the errors
	// Send the chat a message
	log.Stdout("Greeting #bottest")
	bottest.Write("hi guys!")

	// We're done with the connection, close it
	log.Stdout("Sleeping before closing")
	time.Sleep(1e10)
	log.Stdout("Closing")
	server.Close()
	// Talk to server (loop forever)
	connReader := bufio.NewReader(server.Conn)
	for i := 0; i < 100; i++ {
		response, err := connReader.ReadString('\n')
		if err != nil {
			log.Exit("Error reading from connection:", err)
		}
		log.Stdoutf("RECEIVED: %s", strings.TrimSpace(response))
		if response[0] != ':' { //not a private message
			wd := strings.Split(response, " ", 2)
			log.Stdout("Got Message ", wd[0])
			switch wd[0] { // Message Type
			case "PING":
				// TODO: find a better way to remove leading character in string
				pongServer := string(strings.Bytes(wd[1])[1:len(wd[1])])
				pong := "PONG " + pongServer + "\r\n"
				log.Stdout("SENT: ", pong)
				server.Conn.Write(strings.Bytes(pong))
			}
		}
	}

	// We're done with the connection, close it
	log.Stdout("Sleeping before closing")
	time.Sleep(1e10)
	log.Stdout("Closing")
	server.Close()
}
开发者ID:machinaut,项目名称:go-play,代码行数:53,代码来源:go_bot.go

示例10: main

func main() {
	t := template.New(nil)
	t.SetDelims("«", "»")
	err := t.Parse(templateStr)
	if err != nil {
		log.Exit(err)
	}
	err = t.Execute(data, os.Stdout)
	if err != nil {
		log.Exit(err)
	}
}
开发者ID:ivanwyc,项目名称:google-go,代码行数:12,代码来源:gen.go

示例11: main

func main() {
	client, err := rpc.DialHTTP("tcp", "localhost:1234")
	if err != nil {
		log.Exit("dialing:", err)
	}
	args := &arith.Args{7, 8}
	reply := new(arith.Reply)
	err = client.Call("Arith.Add", args, reply)
	if err != nil {
		log.Exit("arith error:", err)
	}
	fmt.Printf("Arith: %d+%d=%d\n", args.A, args.B, reply.C)
}
开发者ID:tokuhirom,项目名称:go-examples,代码行数:13,代码来源:client.go

示例12: main

func main() {
	r, err := jsonrpc.Dial("tcp", "localhost:6666")
	if err != nil {
		log.Exit("Error dialing host: ", err)
	}
	remote := &TestRPCSrv{r}
	a := "foo"
	var b string
	err = remote.Call("testApp.PrintStuff", &a, &b)
	if err != nil {
		log.Exit("Error calling function: ", err)
	}
	log.Exit(b)
}
开发者ID:soul9,项目名称:experiments.go,代码行数:14,代码来源:rpccl.go

示例13: client

func client(host string, port int) {
	client, err := rpc.DialHTTP("tcp", host+":"+fmt.Sprintf("%d", port))
	if err != nil {
		log.Exit("dialing:", err)
	}

	var reply string
	err = client.Call("ProcessStarter.Start", processMap["server"], &reply)
	if err != nil {
		log.Exit("error:", err)
	}
	//    fmt.Printf("Arith: %d*%d=%d", args.A, args.B, *reply)

}
开发者ID:psychobob666,项目名称:MediaEncodingCluster,代码行数:14,代码来源:mainrpc.go

示例14: main

func main() {
	// This works
	r, _, err := http.Get("https://www.google.com")
	if err != nil {
		log.Exit(err)
	}
	log.Println(r)

	// This doesn't
	r, _, err = http.Get("https://streaming.campfirenow.com")
	if err != nil {
		log.Exit(err)
	}
	log.Println(r)
}
开发者ID:wjlroe,项目名称:experiments,代码行数:15,代码来源:https-testing.go

示例15: git_from_net

func git_from_net(url string) string {
	var args [3]string
	args[0] = "git"
	args[1] = "clone"
	args[2] = url
	var fds []*os.File = new([3]*os.File)
	fds[0] = os.Stdin
	fds[1] = os.Stdout
	fds[2] = os.Stderr

	_, str := path.Split(url)
	name := strings.Split(str, ".", -1)[0]
	var git_path string

	switch os.Getenv("GOOS") {
	case "darwin":
		git_path = "/usr/local/git/bin/git"
		break
	case "linux":
		git_path = "/opt/local/bin/git"
		break
	}

	/* Replace this with git's full path, or use a shell, and then call git in the args */
	pid, err := os.ForkExec(git_path, &args, os.Envs, os.Getenv("GOROOT")+"/src/pkg/", fds)
	if err != nil {
		log.Exit(err)
	}

	os.Wait(pid, 0)

	return string(os.Getenv("GOROOT") + "/src/pkg/" + name)
}
开发者ID:ox,项目名称:GoStones,代码行数:33,代码来源:main.go


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