Documentation
¶
Overview ¶
Package tailorclient is an UNOFFICIAL Go client library for the Tailor Platform.
It does not implement its own login flow. Authentication piggybacks on the official Tailor SDK (https://github.com/tailor-platform/sdk): the user logs in once with `npx tailor-sdk login`, and this package reuses the access / refresh tokens that the SDK stores in ~/.config/tailor-platform/config.yaml (file or keyring).
New returns a connect-go OperatorServiceClient already wired with bearer-token authentication and automatic refresh on Unauthenticated errors. Tokens can also be supplied explicitly via WithTokens.
Example ¶
Example builds an authenticated client from the SDK config and calls an OperatorService RPC. The RPC method is promoted from the embedded tailorv1connect.OperatorServiceClient, so it is callable directly on *Client.
package main
import (
"context"
"fmt"
"log"
tailorv1 "buf.build/gen/go/tailor-inc/tailor/protocolbuffers/go/tailor/v1"
"connectrpc.com/connect"
tailorclient "github.com/k1LoW/tailor-client-go"
)
func main() {
ctx := context.Background()
c, err := tailorclient.New(ctx)
if err != nil {
log.Fatal(err)
}
res, err := c.GetApplication(ctx, connect.NewRequest(&tailorv1.GetApplicationRequest{
WorkspaceId: "ws_xxx",
ApplicationName: "my-app",
}))
if err != nil {
log.Fatal(err)
}
fmt.Println(res.Msg.GetApplication().GetName())
}
Output:
Index ¶
Examples ¶
Constants ¶
const DefaultPlatformURL = "https://api.tailor.tech"
DefaultPlatformURL is the production Tailor Platform endpoint.
Variables ¶
This section is empty.
Functions ¶
func IsTokenExpired ¶
IsTokenExpired checks if a token_expires_at string indicates an expired token.
func ReadSDKTokens ¶
ReadSDKTokens reads access_token, refresh_token, and token_expires_at from the SDK config for the current_user. Supports both file-based (v1) and keyring-based (v2) storage.
func WriteSDKTokens ¶
WriteSDKTokens updates the tokens for the current_user. Writes to keyring or config file depending on the user's storage mode.
Types ¶
type Client ¶
type Client struct {
tailorv1connect.OperatorServiceClient
// contains filtered or unexported fields
}
Client is an authenticated Tailor Platform client.
It embeds OperatorServiceClient, so RPC methods can be called directly (e.g. c.GetApplication). The auto-refresh interceptor is wired into the embedded client at construction time.
func New ¶
New builds an authenticated client.
Without WithTokens, New reads the current user's tokens from the Tailor SDK config and proactively refreshes them if expired. Token refresh on unauthenticated RPC errors is always enabled; SDK config writeback is opt-in via WithTokenPersist.
Example (ExplicitTokens) ¶
ExampleNew_explicitTokens passes tokens explicitly instead of reading the SDK config.
package main
import (
"context"
"log"
tailorclient "github.com/k1LoW/tailor-client-go"
)
func main() {
ctx := context.Background()
_, err := tailorclient.New(ctx,
tailorclient.WithTokens("access-token", "refresh-token"),
tailorclient.WithPlatformURL(tailorclient.DefaultPlatformURL),
)
if err != nil {
log.Fatal(err)
}
}
Output:
Example (PersistTokens) ¶
ExampleNew_persistTokens enables SDK config writeback on token refresh. Disabled by default.
package main
import (
"context"
"log"
tailorclient "github.com/k1LoW/tailor-client-go"
)
func main() {
ctx := context.Background()
_, err := tailorclient.New(ctx, tailorclient.WithTokenPersist())
if err != nil {
log.Fatal(err)
}
}
Output:
func (*Client) HTTPClient ¶
func (c *Client) HTTPClient() connect.HTTPClient
HTTPClient returns the underlying HTTP client.
func (*Client) PlatformURL ¶
PlatformURL returns the configured Tailor Platform endpoint.
type Option ¶
type Option func(*options)
Option configures New.
func WithHTTPClient ¶
func WithHTTPClient(h connect.HTTPClient) Option
WithHTTPClient overrides the underlying HTTP client.
func WithInterceptors ¶
func WithInterceptors(ics ...connect.Interceptor) Option
WithInterceptors appends additional connect interceptors. The auto-refresh interceptor is always installed first.
func WithPlatformURL ¶
WithPlatformURL overrides the Tailor Platform endpoint.
func WithTokenPersist ¶
func WithTokenPersist() Option
WithTokenPersist enables writing refreshed tokens back to the SDK config. Disabled by default.
func WithTokens ¶
WithTokens uses the supplied tokens instead of reading the SDK config.
type SDKConfig ¶
type SDKConfig struct {
Version int `yaml:"version"`
MinSDKVersion string `yaml:"min_sdk_version,omitempty"`
LatestVersion *int `yaml:"latest_version,omitempty"`
LatestMinSDKVersion string `yaml:"latest_min_sdk_version,omitempty"`
Users map[string]*SDKUserTokens `yaml:"users"`
Profiles yaml.MapSlice `yaml:"profiles,omitempty"`
CurrentUser *string `yaml:"current_user"`
}
SDKConfig represents the Tailor SDK config.yaml (v1/v2 format).
type SDKUserTokens ¶
type TokenResponse ¶
type TokenResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
Error string `json:"error,omitempty"`
}
TokenResponse is the response from the OAuth2 token endpoint.
func RefreshAccessToken ¶
func RefreshAccessToken(platformURL, refreshToken string) (*TokenResponse, error)
RefreshAccessToken exchanges a refresh_token for a new access_token.