mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
chore(docs): add and refine package-level comments across modules
- Added detailed package-level comments to improve documentation coverage. - Clarified parameter descriptions, return types, and functionality of exported methods across packages. - Enhanced overall code readability and API documentation consistency.
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
// Package usage provides usage tracking and logging functionality for the CLI Proxy API server.
|
||||
// It includes plugins for monitoring API usage, token consumption, and other metrics
|
||||
// to help with observability and billing purposes.
|
||||
package usage
|
||||
|
||||
import (
|
||||
@@ -13,12 +16,23 @@ func init() {
|
||||
}
|
||||
|
||||
// LoggerPlugin outputs every usage record to the application log.
|
||||
// It implements the coreusage.Plugin interface to provide usage tracking
|
||||
// and logging capabilities for monitoring API consumption.
|
||||
type LoggerPlugin struct{}
|
||||
|
||||
// NewLoggerPlugin constructs a new logger plugin instance.
|
||||
//
|
||||
// Returns:
|
||||
// - *LoggerPlugin: A new logger plugin instance
|
||||
func NewLoggerPlugin() *LoggerPlugin { return &LoggerPlugin{} }
|
||||
|
||||
// HandleUsage implements coreusage.Plugin.
|
||||
// It processes usage records by marshaling them to JSON and logging them
|
||||
// at debug level for observability purposes.
|
||||
//
|
||||
// Parameters:
|
||||
// - ctx: The context for the usage record
|
||||
// - record: The usage record to process and log
|
||||
func (p *LoggerPlugin) HandleUsage(ctx context.Context, record coreusage.Record) {
|
||||
// Output all relevant fields for observability; keep logging lightweight and non-blocking.
|
||||
data, _ := json.Marshal(record)
|
||||
|
||||
Reference in New Issue
Block a user