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) } }
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) } }
// 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 }