Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
b453c327
Commit
b453c327
authored
Apr 02, 2026
by
erio
Browse files
refactor: split channelToResponse into pricingToResponse + intervalToResponse
parent
3cd398b0
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/internal/handler/admin/channel_handler.go
View file @
b453c327
...
...
@@ -142,50 +142,58 @@ func channelToResponse(ch *service.Channel) *channelResponse {
resp
.
ModelPricing
=
make
([]
channelModelPricingResponse
,
0
,
len
(
ch
.
ModelPricing
))
for
_
,
p
:=
range
ch
.
ModelPricing
{
models
:=
p
.
Models
if
models
==
nil
{
models
=
[]
string
{}
}
billingMode
:=
string
(
p
.
BillingMode
)
if
billingMode
==
""
{
billingMode
=
string
(
service
.
BillingModeToken
)
}
platform
:=
p
.
Platform
if
platform
==
""
{
platform
=
service
.
PlatformAnthropic
}
intervals
:=
make
([]
pricingIntervalResponse
,
0
,
len
(
p
.
Intervals
))
for
_
,
iv
:=
range
p
.
Intervals
{
intervals
=
append
(
intervals
,
pricingIntervalResponse
{
ID
:
iv
.
ID
,
MinTokens
:
iv
.
MinTokens
,
MaxTokens
:
iv
.
MaxTokens
,
TierLabel
:
iv
.
TierLabel
,
InputPrice
:
iv
.
InputPrice
,
OutputPrice
:
iv
.
OutputPrice
,
CacheWritePrice
:
iv
.
CacheWritePrice
,
CacheReadPrice
:
iv
.
CacheReadPrice
,
PerRequestPrice
:
iv
.
PerRequestPrice
,
SortOrder
:
iv
.
SortOrder
,
})
}
resp
.
ModelPricing
=
append
(
resp
.
ModelPricing
,
channelModelPricingResponse
{
ID
:
p
.
ID
,
Platform
:
platform
,
Models
:
models
,
BillingMode
:
billingMode
,
InputPrice
:
p
.
InputPrice
,
OutputPrice
:
p
.
OutputPrice
,
CacheWritePrice
:
p
.
CacheWritePrice
,
CacheReadPrice
:
p
.
CacheReadPrice
,
ImageOutputPrice
:
p
.
ImageOutputPrice
,
PerRequestPrice
:
p
.
PerRequestPrice
,
Intervals
:
intervals
,
})
resp
.
ModelPricing
=
append
(
resp
.
ModelPricing
,
pricingToResponse
(
&
p
))
}
return
resp
}
func
pricingToResponse
(
p
*
service
.
ChannelModelPricing
)
channelModelPricingResponse
{
models
:=
p
.
Models
if
models
==
nil
{
models
=
[]
string
{}
}
billingMode
:=
string
(
p
.
BillingMode
)
if
billingMode
==
""
{
billingMode
=
string
(
service
.
BillingModeToken
)
}
platform
:=
p
.
Platform
if
platform
==
""
{
platform
=
service
.
PlatformAnthropic
}
intervals
:=
make
([]
pricingIntervalResponse
,
0
,
len
(
p
.
Intervals
))
for
_
,
iv
:=
range
p
.
Intervals
{
intervals
=
append
(
intervals
,
intervalToResponse
(
iv
))
}
return
channelModelPricingResponse
{
ID
:
p
.
ID
,
Platform
:
platform
,
Models
:
models
,
BillingMode
:
billingMode
,
InputPrice
:
p
.
InputPrice
,
OutputPrice
:
p
.
OutputPrice
,
CacheWritePrice
:
p
.
CacheWritePrice
,
CacheReadPrice
:
p
.
CacheReadPrice
,
ImageOutputPrice
:
p
.
ImageOutputPrice
,
PerRequestPrice
:
p
.
PerRequestPrice
,
Intervals
:
intervals
,
}
}
func
intervalToResponse
(
iv
service
.
PricingInterval
)
pricingIntervalResponse
{
return
pricingIntervalResponse
{
ID
:
iv
.
ID
,
MinTokens
:
iv
.
MinTokens
,
MaxTokens
:
iv
.
MaxTokens
,
TierLabel
:
iv
.
TierLabel
,
InputPrice
:
iv
.
InputPrice
,
OutputPrice
:
iv
.
OutputPrice
,
CacheWritePrice
:
iv
.
CacheWritePrice
,
CacheReadPrice
:
iv
.
CacheReadPrice
,
PerRequestPrice
:
iv
.
PerRequestPrice
,
SortOrder
:
iv
.
SortOrder
,
}
}
func
pricingRequestToService
(
reqs
[]
channelModelPricingRequest
)
[]
service
.
ChannelModelPricing
{
result
:=
make
([]
service
.
ChannelModelPricing
,
0
,
len
(
reqs
))
for
_
,
r
:=
range
reqs
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment