- 新增 backend/.golangci.yml 配置 12 个 linter(forbidigo、errorlint、errcheck、staticcheck、revive、gocritic、gosec、bodyclose、noctx、nilerr、goimports、gocyclo) - 新增 lefthook.yml 配置 pre-commit hook 自动运行 lint - 修复存量代码违规:errors.Is/As 替换、zap.Error 替换、import 排序、errcheck 修复 - 更新 README 补充编码规范说明 - 归档 backend-code-lint 变更
40 lines
810 B
Go
40 lines
810 B
Go
package service
|
|
|
|
import (
|
|
"nex/backend/internal/domain"
|
|
appErrors "nex/backend/pkg/errors"
|
|
)
|
|
|
|
type routingService struct {
|
|
cache *RoutingCache
|
|
}
|
|
|
|
func NewRoutingService(cache *RoutingCache) RoutingService {
|
|
return &routingService{cache: cache}
|
|
}
|
|
|
|
func (s *routingService) RouteByModelName(providerID, modelName string) (*domain.RouteResult, error) {
|
|
model, err := s.cache.GetModel(providerID, modelName)
|
|
if err != nil {
|
|
return nil, appErrors.ErrModelNotFound
|
|
}
|
|
|
|
if !model.Enabled {
|
|
return nil, appErrors.ErrModelDisabled
|
|
}
|
|
|
|
provider, err := s.cache.GetProvider(model.ProviderID)
|
|
if err != nil {
|
|
return nil, appErrors.ErrProviderNotFound
|
|
}
|
|
|
|
if !provider.Enabled {
|
|
return nil, appErrors.ErrProviderDisabled
|
|
}
|
|
|
|
return &domain.RouteResult{
|
|
Provider: provider,
|
|
Model: model,
|
|
}, nil
|
|
}
|