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
import (
@@ -9,7 +10,7 @@ import (
"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 {
Token string
BaseURL string
@@ -22,7 +23,9 @@ type ClientConfig struct {
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 {
config ClientConfig
request *Request
@@ -31,7 +34,8 @@ type Client struct {
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 {
if config.BaseURL == "" {
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 {
status, err := c.GetAccountStatus(ctx)
if err != nil {
@@ -79,76 +84,79 @@ func (c *Client) Init(ctx context.Context) error {
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 {
return c.request
}
// GetToken returns the current token
// GetToken returns the current OAuth token used for authentication.
func (c *Client) GetToken() string {
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) {
c.config.Token = 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 {
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 {
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 {
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 {
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 {
// In Go, we typically pass context to each method rather than storing it
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) {
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) {
return c.request.RefreshToken(ctx, refreshToken)
}
// Status represents account status
// Status represents account status returned by the /account/status endpoint.
type Status struct {
Account *Account `json:"account"`
// Other fields...
}
// Account represents a user account
// Account represents a user account.
type Account struct {
UID int64 `json:"uid"`
Login string `json:"login"`
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 {
ID string `json:"id"`
Title string `json:"title"`
Duration int `json:"duration_ms"`
// Other fields...
}