本文整理汇总了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)
}
示例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)
}
}
}
示例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)
}
示例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()
}
}
}
示例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)
}
}
示例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)
}
}
}
示例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.")
}
}
示例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
}
示例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)
}
}
示例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++
}
}
示例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)
}
}
示例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)
}
}
}
示例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)
}
}
示例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
}
示例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)
}
}