Add comprehensive godoc documentation to all exported symbols

- Document all exported types, functions, methods, and constants across 52 files
- Add package-level doc comments to client, models, utils, and ynison packages
- Document HTTP method and endpoint path for each API client method
- Document model struct fields and DeJSON/DeList/ToJSON/ToMap methods
- Fix duplicate package doc comment in internal/models/base.go

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
MrixsandClaude Code committed 2026-10-18 08:57:43 +03:00
1 parent 7a68ad86cb
commit 0456ca0665
54 files changed
+1097 -652

No files matched your search

+22 -13
View File
@@ -13,7 +13,7 @@ import (
"gitea.mrixs.me/Mrixs/yandex-music-api-go/internal/utils"
)
// Default values
// Default values for the Yandex Music API client.
const (
DefaultBaseURL = "https://api.music.yandex.net"
DefaultTimeout = 5 * time.Second
@@ -21,7 +21,7 @@ const (
DefaultClientHeader = "YandexMusicAndroid/24023621"
)
// RequestConfig holds configuration for the request client
// RequestConfig holds configuration for the request client.
type RequestConfig struct {
BaseURL string
Token string
@@ -36,14 +36,16 @@ type RequestConfig struct {
OnSchemaMismatch utils.SchemaMismatchHandler
}
// Request handles HTTP requests to Yandex Music API
// Request handles HTTP requests to the Yandex Music API.
// It manages the HTTP client, authentication headers, and request signing.
type Request struct {
config RequestConfig
client *http.Client
schemaTracker *utils.SchemaMismatchTracker
}
// NewRequest creates a new Request instance
// NewRequest creates a new Request instance with the given configuration.
// It sets up the HTTP client, default headers, and authentication if a token is provided.
func NewRequest(config RequestConfig) *Request {
if config.BaseURL == "" {
config.BaseURL = DefaultBaseURL
@@ -92,7 +94,8 @@ func NewRequest(config RequestConfig) *Request {
return r
}
// SetToken updates the authorization token
// SetToken updates the authorization token used for API requests.
// When a token is provided, it sets the Authorization header to "OAuth <token>".
func (r *Request) SetToken(token string) {
r.config.Token = token
if token != "" {
@@ -102,33 +105,38 @@ func (r *Request) SetToken(token string) {
}
}
// SetLanguage sets the Accept-Language header
// SetLanguage sets the Accept-Language header for API requests.
func (r *Request) SetLanguage(lang string) {
r.config.Language = lang
r.config.Headers["Accept-Language"] = lang
}
// Get performs a GET request
// Get performs a GET request to the given path with query parameters.
// The response is unmarshaled into the result pointer.
func (r *Request) Get(ctx context.Context, path string, params map[string]string, result any) error {
return r.doRequest(ctx, "GET", path, params, nil, result)
}
// Post performs a POST request
// Post performs a POST request to the given path with a JSON body.
// The response is unmarshaled into the result pointer.
func (r *Request) Post(ctx context.Context, path string, body any, result any) error {
return r.doRequest(ctx, "POST", path, nil, body, result)
}
// Put performs a PUT request
// Put performs a PUT request to the given path with a JSON body.
// The response is unmarshaled into the result pointer.
func (r *Request) Put(ctx context.Context, path string, body any, result any) error {
return r.doRequest(ctx, "PUT", path, nil, body, result)
}
// Delete performs a DELETE request
// Delete performs a DELETE request to the given path with an optional JSON body.
// The response is unmarshaled into the result pointer.
func (r *Request) Delete(ctx context.Context, path string, body any, result any) error {
return r.doRequest(ctx, "DELETE", path, nil, body, result)
}
// doRequest performs the actual HTTP request
// doRequest performs the actual HTTP request to the Yandex Music API.
// It handles URL building, request signing, response parsing, and error handling.
func (r *Request) doRequest(ctx context.Context, method, path string, params map[string]string, body any, result any) error {
// Build URL
fullURL := r.config.BaseURL + path
@@ -209,7 +217,7 @@ func (r *Request) doRequest(ctx context.Context, method, path string, params map
return nil
}
// handleErrorResponse handles HTTP error responses
// handleErrorResponse handles HTTP error responses by mapping status codes to typed errors.
func (r *Request) handleErrorResponse(statusCode int, body []byte) error {
var msg string
apiResp, err := utils.DeJSON(body)
@@ -235,7 +243,8 @@ func (r *Request) handleErrorResponse(statusCode int, body []byte) error {
}
}
// Download downloads a file from a URL
// Download downloads a file from the given URL and returns the raw response body.
// It is used for downloading track files and lyrics text.
func (r *Request) Download(ctx context.Context, urlStr string) ([]byte, error) {
req, err := http.NewRequestWithContext(ctx, "GET", urlStr, nil)
if err != nil {