refactor(channels): normalize at cache fill and eliminate frontend as-cast
- channel.go: convert normalizeBillingModelSource into a (*Channel) method for entity cohesion - channel_service.go: normalize in populateChannelCache so every cache-backed reader (gateway, billing, future endpoints) sees the default; drop the duplicate fallback inside resolveMapping - table: tighten Row with status?: ChannelStatus / billing_model_source?: BillingModelSource, remove the [key: string]: unknown index signature - admin view: drop the `as ChannelStatus` / `as BillingModelSource` assertions and add statusStyleOf / billingSourceLabelOf helpers with runtime fallback so unseen values render as "-" instead of crashing
This commit is contained in:
@@ -111,6 +111,18 @@ func (c *Channel) IsActive() bool {
|
||||
return c.Status == StatusActive
|
||||
}
|
||||
|
||||
// normalizeBillingModelSource 若 BillingModelSource 为空则回填默认值 ChannelMapped。
|
||||
// 作为 *Channel 的实体方法集中管理默认值,service 层只需在 Channel 进入内存
|
||||
// (缓存装填、repo 读出)时调用一次,下游读路径就无需重复兜底。
|
||||
func (c *Channel) normalizeBillingModelSource() {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
if c.BillingModelSource == "" {
|
||||
c.BillingModelSource = BillingModelSourceChannelMapped
|
||||
}
|
||||
}
|
||||
|
||||
// GetModelPricing 根据模型名查找渠道定价,未找到返回 nil。
|
||||
// 精确匹配,大小写不敏感。返回值拷贝,不污染缓存。
|
||||
func (c *Channel) GetModelPricing(model string) *ChannelModelPricing {
|
||||
|
||||
Reference in New Issue
Block a user