示例#1
0
文件: agent.go 项目: iwarsong/bearded
func takeApi(fn func(*cli.Context, *client.Client)) func(*cli.Context) {
	return func(ctx *cli.Context) {
		api := client.NewClient(ctx.String("api-addr"), nil)
		if ctx.GlobalBool("debug") {
			api.Debug = true
		}
		api.Token = ctx.String("token")
		fn(ctx, api)
	}
}
示例#2
0
func takeApi(fn func(*cli.Context, *client.Client, Timeout)) func(*cli.Context) {
	return func(ctx *cli.Context) {
		timeout := func() context.Context {
			return utils.JustTimeout(context.Background(), time.Duration(ctx.Int("api-timeout"))*time.Second)
		}
		api := client.NewClient(ctx.String("api-addr"), nil)
		if ctx.GlobalBool("debug") {
			api.Debug = true
		}
		fn(ctx, api, timeout)
	}
}
示例#3
0
// Run agent inside current process
// Start httptest local server
func RunInternalAgent(app http.Handler) error {
	ts := httptest.NewServer(app)
	hostname, err := utils.GetHostname()
	if err != nil {
		return err
	}
	api := client.NewClient(fmt.Sprintf("%s/api/", ts.URL), nil)
	api.Token = "agent-token"
	go func() {
		agent.ServeAgent(hostname, api)
	}()
	return nil
}