Skip to content

refactor: log params and channel params - #1341

Merged
xyfacai merged 1 commit into
alphafrom
refactor/log-params
Jul 7, 2025
Merged

xyfacai merged 1 commit into
alphafrom
refactor/log-params

Conversation

@xyfacai

@xyfacai xyfacai commented Jul 7, 2025 •

Copy link
Copy Markdown
Collaborator

refactor: log params and channel params

Summary by CodeRabbit

  • New Features

    • Introduced structured settings for channels and users, improving type safety and clarity in configuration management.
  • Refactor

    • Replaced generic map-based handling of channel and user settings with strongly typed data structures.
    • Updated various internal processes to use structured parameters for logging and settings management.
    • Simplified access to configuration fields, removing the need for manual type assertions.
  • Bug Fixes

    • Added validation for channel settings during creation and updates to prevent invalid configurations.
  • Chores

    • Removed obsolete constants and files related to channel and user settings.

refactor: log params and channel params
@coderabbitai

coderabbitai Bot commented Jul 7, 2025 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

This change replaces all map-based handling of user and channel settings with strongly typed DTO structs, updating method signatures, function calls, and context usage throughout the codebase. It introduces new DTOs for settings, refactors logging and notification logic to use these types, and removes related constants and map-based utilities.

Changes

File(s) Change Summary
common/gin.go Added generic GetContextKeyType[T any] for typed Gin context retrieval.
common/str.go Added GetJsonString(data any) string for marshaling data to JSON string.
constant/channel_setting.go, constant/user_setting.go Deleted files and removed related string constants for settings.
controller/channel-test.go, relay/relay-text.go, relay/relay_task.go,
relay/relay-mj.go, service/quota.go
Refactored calls to model.RecordConsumeLog to use a struct parameter instead of multiple arguments.
controller/channel.go Added validation of channel settings using ValidateSettings() in add/update flows.
controller/user.go Replaced all map-based user setting references with dto.UserSetting struct fields and constants.
dto/channel_settings.go, dto/user_settings.go Introduced DTO structs for channel/user settings and notification types.
main.go Moved logger setup into InitResources().
middleware/distributor.go Standardized context key usage with common.SetContextKey and constants.
model/channel.go Switched channel settings to use dto.ChannelSettings struct; added ValidateSettings().
model/log.go Refactored logging to use RecordConsumeLogParams struct and direct struct field access for settings.
model/user.go, model/user_cache.go Replaced map-based user settings with dto.UserSetting struct; updated method signatures and error handling.
relay/channel/api_request.go, relay/channel/coze/relay-coze.go,
relay/channel/vertex/service_account.go
Simplified proxy retrieval using strongly typed channel settings.
relay/channel/openai/adaptor.go, relay/channel/openai/relay-openai.go Directly accessed boolean flags from typed channel settings instead of map lookups.
relay/common/relay_info.go Updated RelayInfo to use typed settings DTOs; used generic context getter for retrieval.
relay/helper/price.go Accessed user setting flags directly from dto.UserSetting struct.
service/user_notify.go Refactored notification logic to use dto.UserSetting struct; updated function signature and field access.

Sequence Diagram(s)

sequenceDiagram
    participant Controller
    participant Model
    participant DTO
    participant Service

    Controller->>Model: SetSetting(dto.UserSetting/ChannelSettings)
    Model->>DTO: Marshal struct to JSON
    Model-->>Model: Store JSON string in DB
    Model->>Model: GetSetting()
    Model->>DTO: Unmarshal JSON to struct
    Model-->>Controller/Service: Return typed DTO struct
    Controller/Service->>Service: Pass DTO struct for logging/notification
    Service->>Service: Access struct fields directly
Loading

Possibly related PRs

  • QuantumNous/new-api#1326: Adds typed helper functions for Gin context key access in common/gin.go, related to the introduction of the generic typed context getter in this PR.

Poem

In a warren of code, where the structs now hop,
The maps are all gone, and the type-checks stop.
Settings are tidy, in DTO fields they dwell,
Logging and notifying, all structured and well.
🐇✨ With a thump of my paw, I cheer this new day,
For strongly typed settings have come out to play!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 265c7d9 and 7b29f42.

📒 Files selected for processing (27)
  • common/gin.go (1 hunks)
  • common/str.go (1 hunks)
  • constant/channel_setting.go (0 hunks)
  • constant/user_setting.go (0 hunks)
  • controller/channel-test.go (1 hunks)
  • controller/channel.go (2 hunks)
  • controller/user.go (5 hunks)
  • dto/channel_settings.go (1 hunks)
  • dto/user_settings.go (1 hunks)
  • main.go (1 hunks)
  • middleware/distributor.go (2 hunks)
  • model/channel.go (3 hunks)
  • model/log.go (3 hunks)
  • model/user.go (4 hunks)
  • model/user_cache.go (3 hunks)
  • relay/channel/api_request.go (1 hunks)
  • relay/channel/coze/relay-coze.go (1 hunks)
  • relay/channel/openai/adaptor.go (1 hunks)
  • relay/channel/openai/relay-openai.go (2 hunks)
  • relay/channel/vertex/service_account.go (1 hunks)
  • relay/common/relay_info.go (3 hunks)
  • relay/helper/price.go (1 hunks)
  • relay/relay-mj.go (5 hunks)
  • relay/relay-text.go (1 hunks)
  • relay/relay_task.go (1 hunks)
  • service/quota.go (4 hunks)
  • service/user_notify.go (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@xyfacai
xyfacai merged commit efb9885 into alpha Jul 7, 2025
@Calcium-Ion
Calcium-Ion deleted the refactor/log-params branch July 26, 2025 06:07
@coderabbitai coderabbitai Bot mentioned this pull request Aug 25, 2025
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Apr 28, 2026
8 of 11 tasks
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant