예제 #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
파일: common.go 프로젝트: iwarsong/bearded
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
}