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


Golang log.Fatalln函数代码示例

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


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

示例1: main

func main() {
	flag.Parse()
	var handle *pcap.Handle
	var err error
	if *fname != "" {
		if handle, err = pcap.OpenOffline(*fname); err != nil {
			log.Fatalln("PCAP OpenOffline error:", err)
		}
	} else {
		if handle, err = pcap.OpenLive(*iface, int32(*snaplen), true, time.Second); err != nil {
			log.Fatalln("PCAP OpenLive error:", err)
		}
		if *tstype != "" {
			if t, err := pcap.TimestampSourceFromString(*tstype); err != nil {
				log.Fatalf("Supported timestamp types: %v", handle.SupportedTimestamps())
			} else if err := handle.SetTimestampSource(t); err != nil {
				log.Fatalf("Supported timestamp types: %v", handle.SupportedTimestamps())
			}
		}
		if len(flag.Args()) > 0 {
			bpffilter := strings.Join(flag.Args(), " ")
			fmt.Fprintf(os.Stderr, "Using BPF filter %q\n", bpffilter)
			if err = handle.SetBPFFilter(bpffilter); err != nil {
				log.Fatalln("BPF filter error:", err)
			}
		}
	}
	dumpcommand.Run(handle)
}
开发者ID:jcantrill,项目名称:geard,代码行数:29,代码来源:main.go

示例2: TestGetTeam

func TestGetTeam(t *testing.T) {

	db, err := openDB()

	defer db.Close()

	team1 := steward.Team{
		ID: -1, Name: "MySuperTeam", Subnet: "192.168.111/24",
		Vulnbox: "pl.hold1", UseNetbox: false, Netbox: "nb.hold1"}

	team1.ID, _ = steward.AddTeam(db.db, team1)

	_team1, err := steward.GetTeam(db.db, team1.ID)
	if err != nil {
		log.Fatalln("Get team failed:", err)
	}

	if _team1 != team1 {
		log.Fatalln("Added team broken")
	}

	_, err = steward.GetTeam(db.db, 10) // invalid team id
	if err == nil {
		log.Fatalln("Get invalid team broken")
	}
}
开发者ID:jollheef,项目名称:tin_foil_hat,代码行数:26,代码来源:team_test.go

示例3: TestProgressWriterIgnoreTotal

func TestProgressWriterIgnoreTotal(t *testing.T) {
	filename := "progress_test.go"
	f, err := os.Open(filename)
	defer f.Close()
	if err != nil {
		log.Fatalln(err)
	}
	fs, err := os.Stat(filename)
	if err != nil {
		log.Fatalln(err)
	}

	p := New()
	p.IgnoreTotal = true
	p.Progress = func(current, total, expected int64) {
		log.Println("Ignore total writing", current, total, expected)
		assert.Equal(t, true, current >= total)
	}

	b := new(bytes.Buffer)
	w := io.MultiWriter(p, b)
	_, err = io.Copy(w, f)
	if err != nil {
		log.Fatalln(err)
	}
	assert.Equal(t, fs.Size(), int64(b.Len()))
}
开发者ID:nkwangleiGIT,项目名称:dockerboard,代码行数:27,代码来源:progress_test.go

示例4: init

func init() {
	flag.Parse()

	if *conf == "" {
		log.Fatalln("配置文件不存在")
	}

	confData, err := ioutil.ReadFile(*conf)
	if err != nil {
		log.Fatalln("读取配置文件出错,错误信息为:", err)
	}

	IniFile, err = ini.Load(confData)
	if err != nil {
		log.Fatalln("生成配置文件结构出错,错误信息为:", err)
	}

	pool = GetRedisPool()

	//	httpclient = http.Client{
	//		Transport: &http.Transport{
	//			Dial: func(netw, addr string) (net.Conn, error) {
	//				deadline := time.Now().Add(25 * time.Second)
	//				c, err := net.DialTimeout(netw, addr, time.Second*20)
	//				if err != nil {
	//					return nil, err
	//				}
	//				c.SetDeadline(deadline)
	//				return c, nil
	//			},
	//			DisableKeepAlives: true,
	//		},
	//	}
}
开发者ID:qgweb,项目名称:gopro,代码行数:34,代码来源:main.go

示例5: main

func main() {
	flag.Parse()
	file := flag.Arg(0)

	io, err := os.Open(file)
	if err != nil {
		log.Fatalln("Can't open file: ", file)
	}

	img, err := jpeg.Decode(io, &jpeg.DecoderOptions{})
	if img == nil {
		log.Fatalln("Got nil")
	}
	if err != nil {
		log.Fatalln("Got Error: %v", err)
	}

	//
	// write your code here ...
	//

	switch img.(type) {
	case *image.YCbCr:
		log.Println("decoded YCbCr")
	case *image.Gray:
		log.Println("decoded Gray")
	default:
		log.Println("unknown format")
	}
}
开发者ID:edvakf,项目名称:go-libjpeg,代码行数:30,代码来源:main.go

示例6: main

func main() {
	err := graphics.Init()
	if err != nil {
		log.Fatalln(err)
	}
	defer graphics.Quit()

	win, err := graphics.CreateWindow(800, 600, "Test")
	if err != nil {
		log.Fatalln(err)
	}
	defer win.Destroy()

	if len(os.Args) == 1 {
		newBackEnd()
	}

	frontend := NewPlayerFrontend(win)

	if len(os.Args) == 1 {
		joinEvent := &events.PlayerJoin{
			UUID: frontend.id,
		}
		events.SendEvent(joinEvent)

		go StartNetworkListener()
		loadlevel := events.LoadLevel{
			FileName: "assets/testTiles.json",
		}
		events.SendEvent(&loadlevel)
	} else {
		NewNetworkBackend(os.Args[1])
	}
	frontend.Mainloop()
}
开发者ID:Oralordos,项目名称:Game-Programming-Project,代码行数:35,代码来源:main.go

示例7: main

func main() {
	var file *os.File
	var err error

	if file, err = os.Open("files/sample.tar.bz2"); err != nil {
		log.Fatalln(err)
	}
	defer file.Close()

	reader := tar.NewReader(bzip2.NewReader(file))

	var header *tar.Header
	for {
		header, err = reader.Next()
		if err == io.EOF {
			// ファイルの最後
			break
		}
		if err != nil {
			log.Fatalln(err)
		}

		buf := new(bytes.Buffer)
		if _, err = io.Copy(buf, reader); err != nil {
			log.Fatalln(err)
		}

		if err = ioutil.WriteFile("output/"+header.Name, buf.Bytes(), 0755); err != nil {
			log.Fatal(err)
		}
	}
}
开发者ID:qt-luigi,项目名称:golangcafe,代码行数:32,代码来源:tarbzip.go

示例8: viewInvite

func viewInvite(w http.ResponseWriter, r *http.Request) {
	mail := r.PostFormValue("mail")
	conf, err := loadConf()
	if err != nil {
		log.Fatalln(err)
	}

	client := &http.Client{}
	data := url.Values{
		"email":      {mail},
		"token":      {conf.Token},
		"set_active": {"true"},
	}

	resp, err := client.Post(
		"https://"+conf.URL+"/api/users.admin.invite",
		"application/x-www-form-urlencoded",
		strings.NewReader(data.Encode()),
	)
	if err != nil {
		log.Fatalln(err)
	}
	body, _ := ioutil.ReadAll(resp.Body)

	var status map[string]interface{}
	json.Unmarshal(body, &status)
	fmt.Println(status["ok"])
	statusOk := fmt.Sprint(status["ok"])

	if statusOk == "true" {
		fmt.Fprintf(w, mail+"に招待状を送信しました.")
	} else {
		fmt.Fprintf(w, "失敗した。失敗した。失敗した。"+fmt.Sprint(status["error"]))
	}
}
开发者ID:ieee0824,项目名称:slack-invite-oss,代码行数:35,代码来源:main.go

示例9: main

func main() {
	tpl, err := template.ParseGlob("templates/*.gmao")
	if err != nil {
		log.Fatalln(err)
	}

	err = tpl.Execute(os.Stdout, nil)
	if err != nil {
		log.Fatalln(err)
	}

	err = tpl.ExecuteTemplate(os.Stdout, "vespa.gmao", nil)
	if err != nil {
		log.Fatalln(err)
	}

	err = tpl.ExecuteTemplate(os.Stdout, "two.gmao", nil)
	if err != nil {
		log.Fatalln(err)
	}

	err = tpl.ExecuteTemplate(os.Stdout, "one.gmao", nil)
	if err != nil {
		log.Fatalln(err)
	}
}
开发者ID:GoesToEleven,项目名称:golang-web,代码行数:26,代码来源:main.go

示例10: run

func (publ *Publisher) run() {
	sock, err := pub.NewSocket()
	if err != nil {
		log.Fatalln("pub.NewSocket error:", err)
	}
	sock.AddTransport(inproc.NewTransport())
	sock.AddTransport(tcp.NewTransport())
	defer sock.Close()
	if publ.Connect {
		err = sock.Dial(publ.Endpoint)
	} else {
		err = sock.Listen(publ.Endpoint)
	}
	if err != nil {
		log.Fatalln("sock connect failed:", err)
	}

	// sending on a socket straight away silently fails, so wait 20ms. ugh.
	time.Sleep(time.Millisecond * 20)

	for ev := range publ.Channel {
		// format: topic\0data
		data := fmt.Sprintf("%s\000%s", ev.Topic, ev.String())
		err := sock.Send([]byte(data))
		if err != nil {
			log.Fatalln("Failed to Send message:", err)
		}
	}
}
开发者ID:kienhung,项目名称:gohome,代码行数:29,代码来源:publisher.go

示例11: main

func main() {
	src, err := os.Open("table.csv")
	if err != nil {
		log.Fatalln("error opening table.csv:", err)
	}
	defer src.Close()

	dst, err := os.Create("table.json")
	if err != nil {
		log.Fatalln("error opening table.csv:", err)
	}
	defer dst.Close()

	rdr := csv.NewReader(src)
	rows, err := rdr.ReadAll()
	if err != nil {
		log.Fatalln("error reading file:", err)
	}

	records := make([]record, len(rows))
	for _, row := range rows[1:] {
		records = append(records, makeRecord(row))
	}

	err = json.NewEncoder(dst).Encode(records)
	if err != nil {
		log.Fatalln("error encoding to json:", err)
	}
}
开发者ID:rpendrick,项目名称:examples,代码行数:29,代码来源:main.go

示例12: getUsers

func getUsers(db *sql.DB) []User {
	q := `
		SELECT
			ID, Name, Phone, Created
		FROM
			users
		ORDER BY datetime(Created) DESC
	`

	rows, err := db.Query(q)
	if err != nil {
		log.Fatalln(err)
	}
	defer rows.Close()

	var users []User
	for rows.Next() {
		user := User{}
		err = rows.Scan(&user.ID, &user.Name, &user.Phone, &user.Created)
		if err != nil {
			log.Fatalln(err)
		}
		users = append(users, user)
	}
	return users
}
开发者ID:prinsmike,项目名称:ex,代码行数:26,代码来源:sqlite3.go

示例13: BenchmarkPreparedStatementsSingle

// BenchmarkPreparedStatementsSingle is the case that the user creates a single prepared statement uses it reuses it
func BenchmarkPreparedStatementsSingle(b *testing.B) {
	conn := mysqlConn()
	b.ResetTimer()

	stmt, err := conn.Prepare("select id, subject, state from tickets where subdomain_id = ? and (state = ? or state = ?) limit 1")
	if err != nil {
		log.Fatalln(err)
	}
	for n := 0; n < b.N; n++ {
		rows, err := stmt.Query(1, "open", "spam")
		if err != nil {
			log.Fatalln(err)
		}

		var id int
		var subject string
		var state string
		for rows.Next() {
			err := rows.Scan(&id, &subject, &state)
			if err != nil {
				log.Fatalln(err)
			}
		}

		rows.Close()
	}

	conn.Close()
}
开发者ID:c4pt0r,项目名称:golang-sql-benchmark,代码行数:30,代码来源:sql_benchmark_test.go

示例14: ParseConfig

func ParseConfig(cfg string) {
	if cfg == "" {
		log.Fatalln("use -c to specify configuration file")
	}

	if !file.IsExist(cfg) {
		log.Fatalln("config file:", cfg, "is not existent. maybe you need `mv cfg.example.json cfg.json`")
	}

	ConfigFile = cfg

	configContent, err := file.ToTrimString(cfg)
	if err != nil {
		log.Fatalln("read config file:", cfg, "fail:", err)
	}

	var c GlobalConfig
	err = json.Unmarshal([]byte(configContent), &c)
	if err != nil {
		log.Fatalln("parse config file:", cfg, "fail:", err)
	}

	lock.Lock()
	defer lock.Unlock()

	config = &c

	log.Println("read config file:", cfg, "successfully")
}
开发者ID:donh,项目名称:agent,代码行数:29,代码来源:cfg.go

示例15: Listen

// Listen creates a UDP server that parses statsd data into metrics and
// sends them over a channel.
func Listen(addr string, c chan Packet, clean bool) {
	cleaner := NewCleaner()
	laddr, err := net.ResolveUDPAddr("udp", addr)
	if err != nil {
		log.Fatalln("fatal: failed to resolve address", err)
	}
	conn, err := net.ListenUDP("udp", laddr)
	if err != nil {
		log.Fatalln("fatal: failed to listen", err)
	}
	for {
		buf := make([]byte, 1452)
		n, raddr, err := conn.ReadFrom(buf[:])
		t := time.Now().UTC()
		if err != nil {
			log.Println("error: Failed to recieve packet", err)
		} else {
			metrics, err := Parse(buf[0:n])
			if err != nil {
				log.Println("error: Failed to recieve packet", err)
			}
			if metrics != nil {
				var p Packet
				if clean {
					cleaned := cleaner.CleanMetrics(*metrics)
					p = Packet{&cleaned, raddr, t}
				} else {
					p = Packet{metrics, raddr, t}
				}

				c <- p
			}
		}
	}
}
开发者ID:paulhammond,项目名称:statsp,代码行数:37,代码来源:server.go


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