package orchclient import ( "context" "net/http" "connectrpc.com/connect" "git.dev.alexdunmow.com/block/core/internal/api/orchestrator/v1/orchestratorv1connect" ) type Client struct { Host string Token string Auth orchestratorv1connect.PluginAuthServiceClient Scope orchestratorv1connect.PluginScopeServiceClient Reg orchestratorv1connect.PluginRegistryServiceClient Pub orchestratorv1connect.PluginPublishServiceClient Account orchestratorv1connect.AccountServiceClient } func New(host, token string) *Client { httpClient := &http.Client{} opts := []connect.ClientOption{ connect.WithInterceptors(bearerInterceptor(token)), } c := &Client{Host: host, Token: token} c.Auth = orchestratorv1connect.NewPluginAuthServiceClient(httpClient, host, opts...) c.Scope = orchestratorv1connect.NewPluginScopeServiceClient(httpClient, host, opts...) c.Reg = orchestratorv1connect.NewPluginRegistryServiceClient(httpClient, host, opts...) c.Pub = orchestratorv1connect.NewPluginPublishServiceClient(httpClient, host, opts...) c.Account = orchestratorv1connect.NewAccountServiceClient(httpClient, host, opts...) return c } func bearerInterceptor(token string) connect.Interceptor { return connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc { return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) { if token != "" { req.Header().Set("Authorization", "Bearer "+token) } return next(ctx, req) } }) }