Add godoc documentation to client package

- Add package-level doc comment
- Add doc comments to ClientConfig, Client, Status, Account, Track types
- Document all exported methods and fields

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
MrixsandClaude Code committed 2026-10-18 08:37:39 +03:00
1 parent 70c2a5cd01
commit 5786f0df1e
1 file changed
+28 -20
+28 -20
View File
@@ -1,3 +1,4 @@
// Package client provides the core Yandex Music API client and related types.
package client package client
import ( import (
@@ -9,7 +10,7 @@ import (
"gitea.mrixs.me/Mrixs/yandex-music-api-go/internal/utils" "gitea.mrixs.me/Mrixs/yandex-music-api-go/internal/utils"
) )
// ClientConfig holds configuration for the Client // ClientConfig holds configuration for the Client.
type ClientConfig struct { type ClientConfig struct {
Token string Token string
BaseURL string BaseURL string
@@ -22,7 +23,9 @@ type ClientConfig struct {
JSONBackend utils.JSONBackend JSONBackend utils.JSONBackend
} }
// Client is the main Yandex Music API client // Client is the main Yandex Music API client.
// It provides methods for interacting with the Yandex Music API,
// including tracks, albums, artists, playlists, radio, and more.
type Client struct { type Client struct {
config ClientConfig config ClientConfig
request *Request request *Request
@@ -31,7 +34,8 @@ type Client struct {
accountUID *int64 accountUID *int64
} }
// NewClient creates a new Yandex Music client // NewClient creates a new Yandex Music client with the given configuration.
// If BaseURL, Language, or Timeout are not set in the config, sensible defaults are used.
func NewClient(config ClientConfig) *Client { func NewClient(config ClientConfig) *Client {
if config.BaseURL == "" { if config.BaseURL == "" {
config.BaseURL = DefaultBaseURL config.BaseURL = DefaultBaseURL
@@ -66,7 +70,8 @@ func NewClient(config ClientConfig) *Client {
} }
} }
// Init initializes the client by fetching account info // Init initializes the client by fetching account info from the /account/status endpoint.
// It populates the client's internal account state (GetMe and GetAccountUID).
func (c *Client) Init(ctx context.Context) error { func (c *Client) Init(ctx context.Context) error {
status, err := c.GetAccountStatus(ctx) status, err := c.GetAccountStatus(ctx)
if err != nil { if err != nil {
@@ -79,76 +84,79 @@ func (c *Client) Init(ctx context.Context) error {
return nil return nil
} }
// GetRequest returns the underlying request handler // GetRequest returns the underlying request handler used by this client.
// The returned RequestInterface can be used to make raw API requests.
func (c *Client) GetRequest() models.RequestInterface { func (c *Client) GetRequest() models.RequestInterface {
return c.request return c.request
} }
// GetToken returns the current token // GetToken returns the current OAuth token used for authentication.
func (c *Client) GetToken() string { func (c *Client) GetToken() string {
return c.config.Token return c.config.Token
} }
// SetToken updates the token // SetToken updates the OAuth token used for authentication.
// It also updates the underlying request handler's authorization header.
func (c *Client) SetToken(token string) { func (c *Client) SetToken(token string) {
c.config.Token = token c.config.Token = token
c.request.SetToken(token) c.request.SetToken(token)
} }
// GetDevice returns the device string // GetDevice returns the device identifier string used in API requests.
func (c *Client) GetDevice() string { func (c *Client) GetDevice() string {
return c.device return c.device
} }
// GetMe returns the account status // GetMe returns the account status fetched during Init, or nil if Init has not been called.
func (c *Client) GetMe() *Status { func (c *Client) GetMe() *Status {
return c.me return c.me
} }
// GetAccountUID returns the account UID // GetAccountUID returns the authenticated user's account UID, or nil if not available.
func (c *Client) GetAccountUID() *int64 { func (c *Client) GetAccountUID() *int64 {
return c.accountUID return c.accountUID
} }
// Context returns a context for requests (can be overridden for timeouts) // Context returns a context for requests (can be overridden for timeouts).
// By default it returns context.Background().
func (c *Client) Context() context.Context { func (c *Client) Context() context.Context {
return context.Background() return context.Background()
} }
// WithContext returns a new client with a custom context // WithContext returns a new client with a custom context.
// In Go, context is typically passed to each method rather than stored, so this returns the same client.
func (c *Client) WithContext(ctx context.Context) *Client { func (c *Client) WithContext(ctx context.Context) *Client {
// In Go, we typically pass context to each method rather than storing it // In Go, we typically pass context to each method rather than storing it
return c return c
} }
// DeviceAuth performs OAuth Device Flow authentication // DeviceAuth performs OAuth Device Flow authentication.
// The onCode callback is invoked with the device code so the user can authorize on a separate device.
func (c *Client) DeviceAuth(ctx context.Context, onCode func(*DeviceCode)) (*OAuthToken, error) { func (c *Client) DeviceAuth(ctx context.Context, onCode func(*DeviceCode)) (*OAuthToken, error) {
return c.request.DeviceAuth(ctx, onCode) return c.request.DeviceAuth(ctx, onCode)
} }
// RefreshToken refreshes the access token // RefreshToken refreshes the access token using the provided refresh token.
// It delegates to the underlying request handler.
func (c *Client) RefreshToken(ctx context.Context, refreshToken string) (*OAuthToken, error) { func (c *Client) RefreshToken(ctx context.Context, refreshToken string) (*OAuthToken, error) {
return c.request.RefreshToken(ctx, refreshToken) return c.request.RefreshToken(ctx, refreshToken)
} }
// Status represents account status // Status represents account status returned by the /account/status endpoint.
type Status struct { type Status struct {
Account *Account `json:"account"` Account *Account `json:"account"`
// Other fields...
} }
// Account represents a user account // Account represents a user account.
type Account struct { type Account struct {
UID int64 `json:"uid"` UID int64 `json:"uid"`
Login string `json:"login"` Login string `json:"login"`
DisplayName string `json:"display_name"` DisplayName string `json:"display_name"`
// Other fields...
} }
// Track represents a music track (minimal for now) // Track represents a music track (minimal subset of fields).
type Track struct { type Track struct {
ID string `json:"id"` ID string `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Duration int `json:"duration_ms"` Duration int `json:"duration_ms"`
// Other fields...
} }