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


Golang log.Fatal函数代码示例

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


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

示例1: addFrameToDB

// Add a frame to the database
func addFrameToDB(frame *mbus.Frame) {
	stmt, err := db.Prepare("INSERT INTO sniffedFrames (value) VALUES(?)")
	if err != nil {
		log.Fatal(err)
	}
	defer stmt.Close()
	stmt.Exec(frame.Value)

	// Try to update the frame in the muc table
	stmt, err = db.Prepare("UPDATE muc SET `value`=?,`timestamp`=? WHERE address=?")
	if err != nil {
		log.Fatal(err)
	}
	defer stmt.Close()
	stmt.Exec(frame.Value, time.Now(), frame.Identification())

	// Try to insert the frame in the muc table
	// this won't work if there is already one as the column is defined unique
	stmt, err = db.Prepare("INSERT INTO muc (`value`, `address`, `key`) VALUES(?, ?, ?)")
	if err != nil {
		log.Fatal(err)
	}
	var key string
	if frame.Address() == "440000570C37" {
		key = "CAFEBABE123456789ABCDEF0CAFEBABE"
	} else {
		key = ""
	}
	defer stmt.Close()
	stmt.Exec(frame.Value, frame.Identification(), key)
}
开发者ID:CompassSecurity,项目名称:WMBus-Sniffer-MUC,代码行数:32,代码来源:sql.go

示例2: writeInput

func writeInput(conn *net.TCPConn) {
	fmt.Print("Enter username: ")
	// Read from stdin.
	reader := bufio.NewReader(os.Stdin)
	username, err := reader.ReadString('\n')
	username = username[:len(username)-1]
	if err != nil {
		log.Fatal(err)
	}
	str, err := json.Marshal(map[string]interface{}{"username": string(username)})
	if err != nil {
		fmt.Println("It is not property name")
		return
	}
	err = common.WriteMsg(conn, string(str))
	if err != nil {
		log.Println(err)
	}
	fmt.Println("Enter text: ")
	for {
		text, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}
		err = common.WriteMsg(conn, username+": "+text)
		if err != nil {
			log.Println(err)
		}
	}
}
开发者ID:chikilov,项目名称:goserver,代码行数:30,代码来源:main.go

示例3: main

func main() {
	file, err := os.Create("samp.txt")

	if err != nil {
		log.Fatal(err)
	}
	file.WriteString("This is some random text")
	file.Close()

	stream, err := ioutil.ReadFile("samp.txt")

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

	readString := string(stream)

	fmt.Println(readString)

	randInt := 5

	// randFloat := 10.5

	randString := "100"

	// randString2 := "250.5"

	fmt.Println(float64(randInt))
	newInt, _ := strconv.ParseInt(randString, 0, 64)
	newFloat, _ := strconv.ParseFloat(randString, 64)
	fmt.Println(newInt, newFloat)
}
开发者ID:girishpandit88,项目名称:goLangProjects,代码行数:32,代码来源:helloWorld6.go

示例4: pullMessages

func pullMessages(service *pubsub.Service, argv []string) {
	checkArgs(argv, 3)
	subscriptionName := fullSubscriptionName(argv[0], argv[2])
	pullRequest := &pubsub.PullRequest{
		ReturnImmediately: false,
		Subscription:      subscriptionName,
	}
	for {
		pullResponse, err := service.Subscriptions.Pull(pullRequest).Do()
		if err != nil {
			log.Fatal("Got an error while pull a message: %v", err)
		}
		if pullResponse.PubsubEvent.Message != nil {
			data, err := base64.StdEncoding.DecodeString(
				pullResponse.PubsubEvent.Message.Data)
			if err != nil {
				log.Fatal("Got an error while decoding the message: %v", err)
			}
			fmt.Printf("%s\n", data)
			ackRequest := &pubsub.AcknowledgeRequest{
				AckId:        []string{pullResponse.AckId},
				Subscription: subscriptionName,
			}
			service.Subscriptions.Acknowledge(ackRequest).Do()
		}
	}
}
开发者ID:Tecsisa,项目名称:dex,代码行数:27,代码来源:pubsub.go

示例5: main

func main() {
	// Open device
	handle, err = pcap.OpenLive(device, snapshot_len, promiscuous, timeout)
	if err != nil {
		log.Fatal(err)
	}
	defer handle.Close()

	bpfInstructions := []pcap.BPFInstruction{
		{0x20, 0, 0, 0xfffff038}, // ld rand
		{0x54, 0, 0, 0x00000004},
		{0x15, 0, 1, 0x00000004},
		{0x06, 0, 0, 0x0000ffff},
		{0x06, 0, 0, 0000000000},
	}

	err = handle.SetBPFInstructionFilter(bpfInstructions)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Capturing ~4th packet (randomly).")

	packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
	for packet := range packetSource.Packets() {
		// Do something with a packet here.
		fmt.Println(packet)
	}

}
开发者ID:breml,项目名称:mygoplayground,代码行数:29,代码来源:filter.go

示例6: main

func main() {
	if docker.SelfPath() == "/sbin/init" {
		// Running in init mode
		docker.SysInit()
		return
	}
	// FIXME: Switch d and D ? (to be more sshd like)
	flDaemon := flag.Bool("d", false, "Daemon mode")
	flDebug := flag.Bool("D", false, "Debug mode")
	flag.Parse()
	if *flDebug {
		os.Setenv("DEBUG", "1")
	}
	docker.GIT_COMMIT = GIT_COMMIT
	if *flDaemon {
		if flag.NArg() != 0 {
			flag.Usage()
			return
		}
		if err := daemon(); err != nil {
			log.Fatal(err)
		}
	} else {
		if err := runCommand(flag.Args()); err != nil {
			log.Fatal(err)
		}
	}
}
开发者ID:r0b0ticus,项目名称:docker,代码行数:28,代码来源:docker.go

示例7: checkInput

func checkInput() {
	if redisPort == 0 {
		log.Fatal("Please specify the port at which the redis server is running using --port option.")
	} else if zset == "" {
		log.Fatal("Please specify the name of the ZSET to store using the --zset option.")
	}
}
开发者ID:simar7,项目名称:crdt,代码行数:7,代码来源:crdt_redis.go

示例8: GetTokenInfo

func (at *AuthToken) GetTokenInfo(secret string) (*TokenInfo, error) {
	/* If the token is not valid, stop now. */
	if !at.verify(secret) {
		return nil, errors.New("The token is not valid.")
	}

	/* Convert from base64. */
	jsonString, err := base64.StdEncoding.DecodeString(at.Info)
	if err != nil {
		log.Fatal("Failed to decode base64 string: ", err)
	}
	/* Unmarshal json object. */
	var ti TokenInfo
	err = json.Unmarshal(jsonString, &ti)
	if err != nil {
		log.Fatal("Failed to decode TokenInfo: ", err)
	}

	//	/* Check if the token is expired. */
	//	if time.Now().Unix() > ti.ExpirationDate.Unix() {
	//		return nil, errors.New("The token is expired.")
	//	} else {
	//		return &ti, nil
	//	}
	return &ti, nil
}
开发者ID:walkline,项目名称:MoC-pulse-backend,代码行数:26,代码来源:auth.go

示例9: main

func main() {
	help := fmt.Sprintf("%s link|unlink elb1 elb2 ...", os.Args[0])
	args := os.Args[1:]
	if len(args) < 2 {
		log.Fatalf("Too few arguments: %s", help)
	}
	cmd := args[0]
	elbs := args[1:]
	announcer, err := NewAnnouncer()
	if err != nil {
		log.Fatal(err)
	}
	switch cmd {
	case "link":
		err = announcer.LinkELB(elbs...)
		if err != nil {
			log.Fatal(err)
		}
	case "unlink":
		err = announcer.UnlinkELB(elbs...)
		if err != nil {
			log.Fatal(err)
		}
	default:
		log.Fatalf("Command not recognized: %s, %s", cmd, help)
	}
}
开发者ID:misakwa,项目名称:elbannouncer,代码行数:27,代码来源:elbannouncer.go

示例10: main

func main() {
	flag.Parse()
	args := flag.Args()
	if len(args) < 2 {
		log.Fatal("too few arguments")
		return
	}
	pattern := args[0]
	filename := args[1]

	re, _ := regexp.Compile(pattern)
	file, err := os.Open(filename)
	if err != nil {
		log.Fatal(err)
		return
	}

	i := 1
	reader := bufio.NewReader(file)
	for {
		line, _, err := reader.ReadLine()
		if err == io.EOF {
			return
		}
		if re.Match(line) {
			fmt.Printf("%d: %s\n", i, string(line))
		}
		i++
	}
}
开发者ID:junichi-tanaka,项目名称:go-study,代码行数:30,代码来源:gogrep.go

示例11: main

func main() {
	svcConfig := &service.Config{
		Name:        "GoServiceExampleStopPause",
		DisplayName: "Go Service Example: Stop Pause",
		Description: "This is an example Go service that pauses on stop.",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}
	if len(os.Args) > 1 {
		err = service.Control(s, os.Args[1])
		if err != nil {
			log.Fatal(err)
		}
		return
	}

	logger, err = s.Logger(nil)
	if err != nil {
		log.Fatal(err)
	}
	err = s.Run()
	if err != nil {
		logger.Error(err)
	}
}
开发者ID:couchbasedeps,项目名称:service,代码行数:29,代码来源:main.go

示例12: startMonitorFs

func startMonitorFs() {
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		log.Fatal(err)
	} else {
		reloadCfg.fsWatcher = watcher
		walkFn := func(path string, info os.FileInfo, err error) error {
			if err != nil { // TODO permisstion denyed
			}
			ignore := shouldIgnore(path)
			if ignore && info.IsDir() {
				log.Println("ignore dir", path)
				return filepath.SkipDir
			}
			if info.IsDir() && !ignore {
				err = watcher.Watch(path)
				if err != nil {
					log.Fatal(err)
				} else {
					log.Println("monitoring dir", path)
				}
			}
			return nil
		}
		if err := filepath.Walk(reloadCfg.root, walkFn); err != nil {
			log.Println(err)
		}
	}
}
开发者ID:jayvansantos,项目名称:http-watcher,代码行数:29,代码来源:http-watcher.go

示例13: main

func main() {
	flag.BoolVar(&fake, "n", false, "If true, don't actually do anything")
	flag.BoolVar(&verbose, "v", false, "Provide verbose output")
	flag.Var(&ignorePrefixes, "ignore", "Package prefix to ignore. Can be given multiple times.")
	flag.Parse()

	gopaths := filepath.SplitList(os.Getenv("GOPATH"))
	if len(gopaths) == 0 {
		log.Fatal("GOPATH must be set")
	}
	pkgName := flag.Arg(0)
	if pkgName == "" {
		log.Fatal("need a package name")
	}
	dest := flag.Arg(1)
	if dest == "" {
		log.Fatal("need a destination path")
	}

	ignorePrefixes = append(ignorePrefixes, pkgName)
	ignorePrefixes = append(ignorePrefixes, dest)
	rewrites = make(map[string]string)
	visited = make(map[string]bool)

	err := vendorize(pkgName, chooseGOPATH(gopaths, dest), dest)
	if err != nil {
		log.Fatal(err)
	}
}
开发者ID:kisielk,项目名称:vendorize,代码行数:29,代码来源:main.go

示例14: setupRamDisk

func setupRamDisk(path string) error {
	// err := exec.Command("umount", "-f", path).Run()
	// if err == nil {
	//   log.Printf("Unmounted ramdisk at %s - you may want to eject it!", path)
	// }

	// 1 MB
	diskPath, err := exec.Command("hdiutil", "attach", "-nomount", "ram://2048").Output()
	if err != nil {
		log.Fatal("Creating ramdisk: ", err)
	}
	diskPathStr := strings.TrimSpace(string(diskPath))
	log.Printf("Created ramdisk at %s", diskPathStr)

	err = exec.Command("newfs_hfs", diskPathStr).Run()
	if err != nil {
		log.Fatal("Formatting ramdisk: ", err)
	}
	log.Printf("Formatted ramdisk as HFS.")

	if _, err := os.Stat(path); os.IsNotExist(err) {
		err = os.Mkdir(path, 0700)
		if err != nil {
			log.Fatal("Making dir for ramdisk: ", err)
		}
	}

	err = exec.Command("mount", "-t", "hfs", diskPathStr, path).Run()
	if err != nil {
		log.Fatal("Mounting ramdisk: ", err)
	}
	log.Printf("Ramdisk mounted at %s", path)

	return nil
}
开发者ID:jeisc,项目名称:sneakynote.com,代码行数:35,代码来源:store_darwin.go

示例15: Configure

func (self *app) Configure(appName string, defaultCofig interface{}) {
	self.appName = appName

	// Read config
	self.config = defaultCofig
	if err := self.parseFlags(); err != nil {
		stdlog.Fatal(err)
	}

	// Application section
	if self.appConfig != nil {
		// Set up logger
		if err := self.setupLogger(); err != nil {
			stdlog.Fatal(err)
		}

		// Set up GOMAXPROCS
		if err := self.setupGOMAXPROCS(); err != nil {
			stdlog.Fatal(err)
		}

		// Set up monitoring
		if err := self.setupMonitoring(); err != nil {
			stdlog.Fatal(err)
		}
	}

	// Common section
	// Set up metatiler
	if err := self.setupMetatiler(); err != nil {
		stdlog.Fatal(err)
	}
}
开发者ID:mikhailborodin,项目名称:gopnik,代码行数:33,代码来源:app.go


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