agcapi

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildEndpointURL

func BuildEndpointURL(baseURL, path string, params, query map[string]string) (string, error)

func ConfigDir

func ConfigDir() (string, error)

func CredentialsPath

func CredentialsPath() (string, error)

func SaveCredential

func SaveCredential(path string, credential Credential) error

func ServiceAccountJWT

func ServiceAccountJWT(account ServiceAccountFile, now time.Time) (string, error)

func ValidateCredential

func ValidateCredential(credential Credential) error

Types

type AGCError

type AGCError struct {
	StatusCode int             `json:"statusCode"`
	Code       string          `json:"code,omitempty"`
	Message    string          `json:"message"`
	RawBody    json.RawMessage `json:"rawBody,omitempty"`
}

func ParseAGCError

func ParseAGCError(statusCode int, data []byte) AGCError

func (AGCError) Error

func (e AGCError) Error() string

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
}

func NewClient

func NewClient(baseURL string) Client

func (Client) TokenEndpoint

func (c Client) TokenEndpoint() string

type Credential

type Credential struct {
	Name               string    `json:"name"`
	Mode               string    `json:"mode"`
	ServiceAccountFile string    `json:"serviceAccountFile,omitempty"`
	ClientID           string    `json:"clientId,omitempty"`
	ClientKey          string    `json:"clientKey,omitempty"`
	Active             bool      `json:"active,omitempty"`
	CreatedAt          time.Time `json:"createdAt"`
}

func ActiveCredential

func ActiveCredential(store CredentialStore) (Credential, bool)

func CredentialByName

func CredentialByName(store CredentialStore, name string) (Credential, bool)

type CredentialStore

type CredentialStore struct {
	Accounts []Credential `json:"accounts"`
}

func LoadCredentials

func LoadCredentials(path string) (CredentialStore, error)

type InvokeRequest

type InvokeRequest struct {
	Endpoint    domain.Endpoint   `json:"endpoint"`
	BaseURL     string            `json:"baseUrl"`
	Params      map[string]string `json:"params,omitempty"`
	Query       map[string]string `json:"query,omitempty"`
	Headers     map[string]string `json:"headers,omitempty"`
	Body        []byte            `json:"-"`
	AccessToken string            `json:"-"`
	DryRun      bool              `json:"dryRun"`
}

type InvokeResponse

type InvokeResponse struct {
	Method      string          `json:"method"`
	URL         string          `json:"url"`
	StatusCode  int             `json:"statusCode,omitempty"`
	ContentType string          `json:"contentType,omitempty"`
	Body        json.RawMessage `json:"body,omitempty"`
	RawBody     []byte          `json:"-"`
	DryRun      bool            `json:"dryRun"`
}

func InvokeEndpoint

func InvokeEndpoint(ctx context.Context, client *http.Client, req InvokeRequest) (InvokeResponse, error)

type PaginatedResponse

type PaginatedResponse[T any] struct {
	Data       []T    `json:"data"`
	NextCursor string `json:"nextCursor,omitempty"`
	Total      int    `json:"total,omitempty"`
}

type ServiceAccountFile

type ServiceAccountFile struct {
	ProjectID  string `json:"project_id"`
	KeyID      string `json:"key_id"`
	PrivateKey string `json:"private_key"`
	SubAccount string `json:"sub_account"`
	TokenURI   string `json:"token_uri"`
}

func LoadServiceAccount

func LoadServiceAccount(path string) (ServiceAccountFile, error)

type TokenResponse

type TokenResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type,omitempty"`
	ExpiresIn   int    `json:"expires_in,omitempty"`
}

func APIClientToken

func APIClientToken(ctx context.Context, client *http.Client, baseURL, clientID, clientKey string) (TokenResponse, error)

func AccessToken

func AccessToken(ctx context.Context, client *http.Client, baseURL string, credential Credential) (TokenResponse, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL