當前位置: 首頁>>代碼示例>>Golang>>正文


Golang log.Fatalf函數代碼示例

本文整理匯總了Golang中github.com/apex/log.Fatalf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Fatalf函數的具體用法?Golang Fatalf怎麽用?Golang Fatalf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Fatalf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: logsCmdRun

func logsCmdRun(c *cobra.Command, args []string) {
	lv := &logsCmdLocalValues

	l, err := pv.project.Logs(pv.session, lv.name, lv.Filter)
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	if lv.Follow {
		for event := range l.Tail() {
			fmt.Printf("%s", *event.Message)
		}

		if err := l.Err(); err != nil {
			log.Fatalf("error: %s", err)
		}
	}

	events, err := l.Fetch()
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	for _, event := range events {
		fmt.Printf("%s", *event.Message)
	}

}
開發者ID:johannesboyne,項目名稱:apex,代碼行數:28,代碼來源:apex_logs.go

示例2: preRun

func (pv *PersistentValues) preRun(c *cobra.Command, args []string) {
	if l, err := log.ParseLevel(pv.LogLevel); err == nil {
		log.SetLevel(l)
	}

	pv.session = session.New(aws.NewConfig())

	pv.project = &project.Project{
		Log:  log.Log,
		Path: ".",
	}

	if pv.DryRun {
		log.SetLevel(log.WarnLevel)
		pv.project.Service = dryrun.New(pv.session)
		pv.project.Concurrency = 1
	} else {
		pv.project.Service = lambda.New(pv.session)
	}

	if pv.Chdir != "" {
		if err := os.Chdir(pv.Chdir); err != nil {
			log.Fatalf("error: %s", err)
		}
	}

	if err := pv.project.Open(); err != nil {
		log.Fatalf("error opening project: %s", err)
	}
}
開發者ID:pilwon,項目名稱:apex,代碼行數:30,代碼來源:persistent.go

示例3: Action

// Action is the default cli action to execute
func Action(c *cli.Context) {
	// Initialize the SSH server
	server, err := ssh2docker.NewServer()
	if err != nil {
		log.Fatalf("Cannot create server: %v", err)
	}

	// Restrict list of allowed images
	if c.String("allowed-images") != "" {
		server.AllowedImages = strings.Split(c.String("allowed-images"), ",")
	}

	// Configure server
	server.DefaultShell = c.String("shell")
	server.DockerRunArgsInline = c.String("docker-run-args")
	server.DockerExecArgsInline = c.String("docker-exec-args")
	server.NoJoin = c.Bool("no-join")
	server.CleanOnStartup = c.Bool("clean-on-startup")
	server.PasswordAuthScript = c.String("password-auth-script")
	server.PublicKeyAuthScript = c.String("publickey-auth-script")
	server.LocalUser = c.String("local-user")
	server.Banner = c.String("banner")

	// Register the SSH host key
	hostKey := c.String("host-key")
	switch hostKey {
	case "built-in":
		hostKey = DefaultHostKey
	case "system":
		hostKey = "/etc/ssh/ssh_host_rsa_key"
	}
	err = server.AddHostKey(hostKey)
	if err != nil {
		log.Fatalf("Cannot add host key: %v", err)
	}

	// Bind TCP socket
	bindAddress := c.String("bind")
	listener, err := net.Listen("tcp", bindAddress)
	if err != nil {
		log.Fatalf("Failed to start listener on %q: %v", bindAddress, err)
	}
	log.Infof("Listening on %q", bindAddress)

	// Initialize server
	if err = server.Init(); err != nil {
		log.Fatalf("Failed to initialize the server: %v", err)
	}

	// Accept new clients
	for {
		conn, err := listener.Accept()
		if err != nil {
			log.Errorf("Accept failed: %v", err)
			continue
		}
		go server.Handle(conn)
	}
}
開發者ID:moul,項目名稱:ssh2docker,代碼行數:60,代碼來源:main.go

示例4: main

func main() {
	args, err := docopt.Parse(usage, nil, true, version, false)
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	log.SetHandler(cli.Default)

	if l, err := log.ParseLevel(args["--log-level"].(string)); err == nil {
		log.SetLevel(l)
	}

	if args["help"].(bool) {
		showHelp(args["<topic>"])
		return
	}

	session := session.New(aws.NewConfig())

	project := &project.Project{
		Log:  log.Log,
		Path: ".",
	}

	if args["--dry-run"].(bool) {
		log.SetLevel(log.WarnLevel)
		project.Service = dryrun.New(session)
		project.Concurrency = 1
	} else {
		project.Service = lambda.New(session)
	}

	if dir, ok := args["--chdir"].(string); ok {
		if err := os.Chdir(dir); err != nil {
			log.Fatalf("error: %s", err)
		}
	}

	if err := project.Open(); err != nil {
		log.Fatalf("error opening project: %s", err)
	}

	switch {
	case args["list"].(bool):
		list(project)
	case args["deploy"].(bool):
		deploy(project, args["<name>"].([]string), args["--env"].([]string))
	case args["delete"].(bool):
		delete(project, args["<name>"].([]string), args["--yes"].(bool))
	case args["invoke"].(bool):
		invoke(project, args["<name>"].([]string), args["--verbose"].(bool), args["--async"].(bool))
	case args["rollback"].(bool):
		rollback(project, args["<name>"].([]string), args["<version>"])
	case args["build"].(bool):
		build(project, args["<name>"].([]string))
	case args["logs"].(bool):
		tail(project, args["<name>"].([]string), args["--filter"].(string))
	}
}
開發者ID:yuishug,項目名稱:apex,代碼行數:59,代碼來源:apex.go

示例5: downloadReleaseAsset

func downloadReleaseAsset(r *github.ReleaseAsset, newName *string, newPath *string) {
	var outDir string
	if newPath == nil {
		outDir = binDir()
	} else {
		outDir = *newPath
	}

	downloadUrlString := *r.BrowserDownloadURL

	log.Infof("Downloading release asset: %s", downloadUrlString)
	log.Infof("Copying to: %s", outDir)

	downloadUrl, err := url.Parse(downloadUrlString)
	if err != nil {
		log.Fatalf("Error: Could not parse URL: %v", err)
	}

	var fileName string
	if newName == nil {
		_, fileName = path.Split(downloadUrl.Path)
	} else {
		fileName = *newName
	}

	outName := outDir + "/" + fileName
	out, err := os.Create(outName)
	if err != nil {
		log.Fatalf("Error: Could not create local file: %v", err)
	}

	defer out.Close()
	resp, err := http.Get(downloadUrlString)
	if err != nil {
		log.Fatalf("Error: Could not get remote file: %v", err)
	}
	defer resp.Body.Close()
	bar := ioprogress.DrawTextFormatBar(20)
	progressFunc := ioprogress.DrawTerminalf(os.Stdout, func(progress, total int64) string {
		return fmt.Sprintf("%s %s %20s", fileName, bar(progress, total), ioprogress.DrawTextFormatBytes(progress, total))
	})

	progress := &ioprogress.Reader{
		Reader:       resp.Body,
		Size:         resp.ContentLength,
		DrawInterval: time.Millisecond,
		DrawFunc:     progressFunc,
	}

	_, err = io.Copy(out, progress)
	if err != nil {
		log.Fatalf("Error: Could not copy local file: %v", err)
	}

	err = os.Chmod(outName, 0755)
	if err != nil {
		log.Fatalf("Error: Could not make %s executable. Try with (sudo)?", outName)
	}
}
開發者ID:tobyjoe,項目名稱:grab,代碼行數:59,代碼來源:main.go

示例6: invokeCmdRun

// reads request json from stdin and outputs the responses
func invokeCmdRun(c *cobra.Command, args []string) {
	lv := &invokeCmdLocalValues
	dec := json.NewDecoder(os.Stdin)
	kind := function.RequestResponse

	if lv.Async {
		kind = function.Event
	}

	err := pv.project.LoadFunctions(lv.name)
	if err != nil {
		log.Fatalf("error: %s", err)
		return
	}

	fn := pv.project.Functions[0]

	for {
		var v map[string]interface{}
		err := dec.Decode(&v)

		if err == io.EOF {
			break
		}

		if err != nil {
			log.Fatalf("error parsing response: %s", err)
		}

		var reply, logs io.Reader

		if e, ok := v["event"].(map[string]interface{}); ok {
			reply, logs, err = fn.Invoke(e, v["context"], kind)
		} else {
			reply, logs, err = fn.Invoke(v, nil, kind)
		}

		if err != nil {
			log.Fatalf("error response: %s", err)
		}

		if lv.Logs {
			io.Copy(os.Stderr, logs)
		}

		io.Copy(os.Stdout, reply)
		fmt.Fprintf(os.Stdout, "\n")
	}
}
開發者ID:lc0,項目名稱:apex,代碼行數:50,代碼來源:apex_invoke.go

示例7: build

// build outputs the generated archive to stdout.
func build(project *project.Project, name []string) {
	fn, err := project.FunctionByName(name[0])
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	zip, err := fn.Zip()
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	_, err = io.Copy(os.Stdout, zip)
	if err != nil {
		log.Fatalf("error: %s", err)
	}
}
開發者ID:jordan-acosta,項目名稱:apex,代碼行數:17,代碼來源:apex.go

示例8: main

func main() {
	log.SetHandler(cli.Default)

	if err := root.Command.Execute(); err != nil {
		log.Fatalf("Error: %s", err)
	}
}
開發者ID:elizar,項目名稱:apex,代碼行數:7,代碼來源:main.go

示例9: main

func main() {
	log.SetHandler(cli.Default)

	args := os.Args[1:]

	// Cobra does not (currently) allow us to pass flags for a sub-command
	// as if they were arguments, so we inject -- here after the first TF command.
	// TODO(tj): replace with a real solution and send PR to Cobra #251
	if len(os.Args) > 1 && os.Args[1] == "infra" {
		off := 1

	out:
		for i, a := range args {
			for _, cmd := range tf {
				if a == cmd {
					off = i
					break out
				}
			}
		}

		args = append(args[0:off], append([]string{"--"}, args[off:]...)...)
	}

	root.Command.SetArgs(args)

	if err := root.Command.Execute(); err != nil {
		log.Fatalf("Error: %s", err)
	}

	stats.Client.ConditionalFlush(500, 24*time.Hour)
}
開發者ID:Robh081956,項目名稱:apex,代碼行數:32,代碼來源:main.go

示例10: binDir

func binDir() string {
	dir, err := os.Getwd()
	if err != nil {
		log.Fatalf("Error: No working directory")
	}
	log.Infof("GOOS: %s", runtime.GOOS)

	switch runtime.GOOS {
	case "darwin":
		fallthrough
	case "dragonfly":
		fallthrough
	case "linux":
		fallthrough
	case "freebsd":
		fallthrough
	case "netbsd":
		fallthrough
	case "openbsd":
		dir = "/usr/local/bin"
		break
	default:
		break
	}
	return dir
}
開發者ID:tobyjoe,項目名稱:grab,代碼行數:26,代碼來源:main.go

示例11: rollback

// rollback the function with optional version.
func rollback(project *project.Project, name []string, version interface{}) {
	fn, err := project.FunctionByName(name[0])
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	if version == nil {
		err = fn.Rollback()
	} else {
		err = fn.RollbackVersion(version.(string))
	}

	if err != nil {
		log.Fatalf("error: %s", err)
	}
}
開發者ID:jordan-acosta,項目名稱:apex,代碼行數:17,代碼來源:apex.go

示例12: metricsCmdRun

func metricsCmdRun(c *cobra.Command, args []string) {
	lv := &metricsCmdLocalValues

	err := pv.project.LoadFunctions(lv.name)
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	fn := pv.project.Functions[0]

	d, err := time.ParseDuration(lv.duration)
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	start := time.Now().UTC().Add(-d)
	end := time.Now().UTC()

	mc := &metrics.MetricCollector{
		Metrics:      []string{"Invocations", "Errors", "Duration", "Throttles"},
		Collected:    0,
		FunctionName: fn.FunctionName,
		Service:      cloudwatch.New(pv.session),
		StartDate:    start,
		EndDate:      end,
	}

	aggregated := make(map[string]aggregatedMetric)

	for n := range mc.Collect() {
		aggregated[n.Name] = aggregatedMetric{n.Name, aggregate(n.Value)}
	}

	println()
	defer println()

	for _, m := range aggregated {
		switch m.Name {
		case "Duration":
			fmt.Printf("  \033[34m%11s:\033[0m %vms\n", m.Name, m.Count)
		default:
			fmt.Printf("  \033[34m%11s:\033[0m %v\n", m.Name, m.Count)
		}
	}
}
開發者ID:lc0,項目名稱:apex,代碼行數:45,代碼來源:apex_metrics.go

示例13: buildCmdRun

// outputs the generated archive to stdout
func buildCmdRun(c *cobra.Command, args []string) {
	lv := &buildCmdLocalValues

	fn, err := pv.project.FunctionByName(lv.name)
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	zip, err := fn.Build()
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	_, err = io.Copy(os.Stdout, zip)
	if err != nil {
		log.Fatalf("error: %s", err)
	}
}
開發者ID:pilwon,項目名稱:apex,代碼行數:19,代碼來源:apex_build.go

示例14: New

func New(network, raddr string, priority syslog.Priority, tag string) *Handler {
	w, err := syslog.Dial(network, raddr, priority, tag)
	if err != nil {
		log.Fatalf("%v", err)
	}
	return &Handler{
		w: w,
	}
}
開發者ID:moul,項目名稱:ssh2docker,代碼行數:9,代碼來源:sysloghandler.go

示例15: rollbackCmdRun

func rollbackCmdRun(c *cobra.Command, args []string) {
	lv := &rollbackCmdLocalValues

	fn, err := pv.project.FunctionByName(lv.name)
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	if lv.version == "" {
		err = fn.Rollback()
	} else {
		err = fn.RollbackVersion(lv.version)
	}

	if err != nil {
		log.Fatalf("error: %s", err)
	}
}
開發者ID:pilwon,項目名稱:apex,代碼行數:18,代碼來源:apex_rollback.go


注:本文中的github.com/apex/log.Fatalf函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。