當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。