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


Golang stats.Track函數代碼示例

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


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

示例1: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Logs", map[string]interface{}{
		"has_filter": filter != "",
		"since":      duration,
		"follow":     follow,
	})

	if err := root.Project.LoadFunctions(args...); err != nil {
		return err
	}

	config := logs.Config{
		Service:       cloudwatchlogs.New(root.Session),
		StartTime:     time.Now().Add(-duration).UTC(),
		PollInterval:  5 * time.Second,
		Follow:        follow,
		FilterPattern: filter,
	}

	l := &logs.Logs{
		Config: config,
	}

	for _, fn := range root.Project.Functions {
		l.GroupNames = append(l.GroupNames, fn.GroupName())
	}

	for event := range l.Start() {
		fmt.Printf("\033[34m%s\033[0m %s", event.GroupName, event.Message)
	}

	return l.Err()
}
開發者ID:DavidTPate,項目名稱:apex,代碼行數:34,代碼來源:logs.go

示例2: run

// Run command.
func run(c *cobra.Command, args []string) (err error) {
	stats.Track("Docs", nil)

	var w io.WriteCloser = os.Stdout

	if isatty.IsTerminal(os.Stdout.Fd()) {
		cmd := exec.Command("less", "-R")
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr

		defer cmd.Wait()

		w, err = cmd.StdinPipe()
		if err != nil {
			return err
		}
		defer w.Close()

		if err := cmd.Start(); err != nil {
			return err
		}
	}

	_, err = io.Copy(w, doc.Reader())
	return err
}
開發者ID:DavidTPate,項目名稱:apex,代碼行數:27,代碼來源:docs.go

示例3: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Deploy", map[string]interface{}{
		"concurrency": concurrency,
		"has_alias":   alias != "",
		"env":         len(env),
		"args":        len(args),
	})

	root.Project.Concurrency = concurrency
	root.Project.Alias = alias

	if err := root.Project.LoadFunctions(args...); err != nil {
		return err
	}

	for _, fn := range root.Project.Functions {
		stats.Track("Deploy Function", map[string]interface{}{
			"runtime":      fn.Runtime,
			"has_alias":    alias != "",
			"has_env_file": envFile != "",
			"env":          len(env),
		})
	}

	if envFile != "" {
		if err := root.Project.LoadEnvFromFile(envFile); err != nil {
			return fmt.Errorf("reading env file %q: %s", envFile, err)
		}
	}

	vars, err := utils.ParseEnv(env)
	if err != nil {
		return err
	}

	for k, v := range vars {
		root.Project.Setenv(k, v)
	}

	return root.Project.DeployAndClean()
}
開發者ID:DavidTPate,項目名稱:apex,代碼行數:42,代碼來源:deploy.go

示例4: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Metrics", map[string]interface{}{
		"since": duration,
	})

	if err := root.Project.LoadFunctions(args...); err != nil {
		return err
	}

	service := lambda.New(root.Session)

	config := metrics.Config{
		Service:   cloudwatch.New(root.Session),
		StartDate: time.Now().UTC().Add(-duration),
		EndDate:   time.Now().UTC(),
	}

	m := metrics.Metrics{
		Config: config,
	}

	for _, fn := range root.Project.Functions {
		m.FunctionNames = append(m.FunctionNames, fn.FunctionName)
	}

	aggregated := m.Collect()

	fmt.Println()
	for _, fn := range root.Project.Functions {
		m := aggregated[fn.FunctionName]

		conf, err := service.GetFunctionConfiguration(&lambda.GetFunctionConfigurationInput{FunctionName: &fn.FunctionName})
		if err != nil {
			return err
		}

		memory := int(*conf.MemorySize)
		costTotal := humanize.FormatFloat("", cost.Cost(m.Invocations, m.Duration, memory))
		costDuration := humanize.FormatFloat("", cost.DurationCost(m.Duration, memory))
		costInvocations := humanize.FormatFloat("", cost.RequestCost(m.Invocations))

		fmt.Printf("  \033[%dm%s\033[0m\n", colors.Blue, fn.Name)
		fmt.Printf("    total cost: $%s\n", costTotal)
		fmt.Printf("    invocations: %s ($%s)\n", humanize.Comma(int64(m.Invocations)), costInvocations)
		fmt.Printf("    duration: %s ($%s)\n", time.Millisecond*time.Duration(m.Duration), costDuration)
		fmt.Printf("    throttles: %v\n", m.Throttles)
		fmt.Printf("    errors: %s\n", humanize.Comma(int64(m.Errors)))
		fmt.Printf("    memory: %d\n", memory)
		fmt.Println()
	}

	return nil
}
開發者ID:Robh081956,項目名稱:apex,代碼行數:54,代碼來源:metrics.go

示例5: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Init", nil)

	if err := root.Prepare(c, args); err != nil {
		return err
	}

	region := root.Config.Region
	if region == nil {
		return errors.New("AWS region missing, are your credentials set up? Visit http://apex.run/#aws-credentials for more details")
	}

	return boot.All(*region)
}
開發者ID:Robh081956,項目名稱:apex,代碼行數:15,代碼來源:init.go

示例6: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Invoke", map[string]interface{}{
		"has_alias": alias != "",
		"has_logs":  includeLogs,
	})

	dec := json.NewDecoder(input())

	root.Project.Alias = alias

	if err := root.Project.LoadFunctions(name); err != nil {
		return err
	}

	fn := root.Project.Functions[0]

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

		if err == io.EOF {
			break
		}

		if err != nil {
			return fmt.Errorf("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"])
		} else {
			reply, logs, err = fn.Invoke(v, nil)
		}

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

		if err != nil {
			return fmt.Errorf("function response: %s", err)
		}

		io.Copy(os.Stdout, reply)
		fmt.Fprintf(os.Stdout, "\n")
	}

	return nil
}
開發者ID:Robh081956,項目名稱:apex,代碼行數:51,代碼來源:invoke.go

示例7: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Deploy", map[string]interface{}{
		"concurrency": concurrency,
		"has_alias":   alias != "",
		"env":         len(env),
		"args":        len(args),
	})

	root.Project.Concurrency = concurrency
	root.Project.Alias = alias

	c.Root().PersistentFlags().Lookup("name string")

	if err := root.Project.LoadFunctions(args...); err != nil {
		return err
	}

	for _, fn := range root.Project.Functions {
		stats.Track("Deploy Function", map[string]interface{}{
			"runtime":   fn.Runtime,
			"has_alias": alias != "",
			"env":       len(env),
		})
	}

	for _, s := range env {
		parts := strings.SplitN(s, "=", 2)
		if len(parts) == 2 {
			root.Project.Setenv(parts[0], parts[1])
		} else {
			return fmt.Errorf("environment variable %s needs a value", parts[0])
		}
	}

	return root.Project.DeployAndClean()
}
開發者ID:Robh081956,項目名稱:apex,代碼行數:37,代碼來源:deploy.go

示例8: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("List", map[string]interface{}{
		"tfvars": tfvars,
	})

	if err := root.Project.LoadFunctions(); err != nil {
		return err
	}

	if tfvars {
		outputTFvars()
	} else {
		outputList()
	}

	return nil
}
開發者ID:tobyjoe,項目名稱:apex,代碼行數:18,代碼來源:list.go

示例9: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Rollback", map[string]interface{}{
		"has_alias":   alias != "",
		"has_version": version != "",
	})

	root.Project.Alias = alias

	if err := root.Project.LoadFunctions(args...); err != nil {
		return err
	}

	if version == "" {
		return root.Project.Rollback()
	}

	return root.Project.RollbackVersion(version)
}
開發者ID:DavidTPate,項目名稱:apex,代碼行數:19,代碼來源:rollback.go

示例10: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Init", nil)

	if err := root.Prepare(c, args); err != nil {
		return err
	}

	region := root.Config.Region
	if region == nil {
		return errors.New(credentialsError)
	}

	b := boot.Bootstrapper{
		IAM:    iam.New(root.Session),
		Region: *region,
	}

	return b.Boot()
}
開發者ID:DavidTPate,項目名稱:apex,代碼行數:20,代碼來源:init.go

示例11: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Infra", nil)

	err := root.Project.LoadFunctions()

	// Hack to prevent initial `apex infra apply` from failing,
	// as we load functions to expose their ARNs.
	if err != nil {
		if !strings.Contains(err.Error(), "Role: zero value") {
			return err
		}
	}

	p := &infra.Proxy{
		Functions:   root.Project.Functions,
		Region:      *root.Session.Config.Region,
		Environment: root.Project.Environment,
	}

	return p.Run(args...)
}
開發者ID:Robh081956,項目名稱:apex,代碼行數:22,代碼來源:infra.go

示例12: run

// Run command.
func run(c *cobra.Command, args []string) error {
	if err := root.Project.LoadFunctions(name); err != nil {
		return err
	}

	fn := root.Project.Functions[0]

	stats.Track("Build", map[string]interface{}{
		"runtime":      fn.Runtime,
		"env":          len(env),
		"has_env_file": envFile != "",
	})

	if envFile != "" {
		if err := root.Project.LoadEnvFromFile(envFile); err != nil {
			return fmt.Errorf("reading env file %q: %s", envFile, err)
		}
	}

	vars, err := utils.ParseEnv(env)
	if err != nil {
		return err
	}

	for k, v := range vars {
		root.Project.Setenv(k, v)
	}

	zip, err := fn.Build()
	if err != nil {
		return err
	}

	if err := fn.Clean(); err != nil {
		return err
	}

	_, err = io.Copy(os.Stdout, zip)
	return err
}
開發者ID:coderhaoxin,項目名稱:apex,代碼行數:41,代碼來源:build.go

示例13: run

// Run command.
func run(c *cobra.Command, args []string) error {
	if err := root.Project.LoadFunctions(name); err != nil {
		return err
	}

	fn := root.Project.Functions[0]

	stats.Track("Build", map[string]interface{}{
		"runtime": fn.Runtime,
	})

	zip, err := fn.Build()
	if err != nil {
		return err
	}

	if err := fn.Clean(); err != nil {
		return err
	}

	_, err = io.Copy(os.Stdout, zip)
	return err
}
開發者ID:Robh081956,項目名稱:apex,代碼行數:24,代碼來源:build.go

示例14: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Delete", map[string]interface{}{
		"force": force,
		"args":  len(args),
	})

	if err := root.Project.LoadFunctions(args...); err != nil {
		return err
	}

	if !force && len(root.Project.Functions) > 1 {
		fmt.Printf("The following will be deleted:\n\n")
		for _, fn := range root.Project.Functions {
			fmt.Printf("  - %s\n", fn.Name)
		}
		fmt.Printf("\n")
	}

	if !force && !prompt.Confirm("Are you sure? (yes/no) ") {
		return nil
	}

	return root.Project.Delete()
}
開發者ID:Robh081956,項目名稱:apex,代碼行數:25,代碼來源:delete.go

示例15: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Upgrade", nil)
	return upgrade.Upgrade(version.Version)
}
開發者ID:DavidTPate,項目名稱:apex,代碼行數:5,代碼來源:upgrade.go


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