添加网络层并接入 v9 登录流程及单元测试
This commit is contained in:
32
suixinkan/App/NetworkServices.swift
Normal file
32
suixinkan/App/NetworkServices.swift
Normal file
@ -0,0 +1,32 @@
|
||||
//
|
||||
// NetworkServices.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@MainActor
|
||||
/// 全局网络依赖容器,集中提供 APIClient 与 AuthAPI。
|
||||
final class NetworkServices {
|
||||
static let shared = NetworkServices()
|
||||
|
||||
let apiClient: APIClient
|
||||
let authAPI: AuthAPI
|
||||
|
||||
/// 生产环境默认初始化。
|
||||
private init() {
|
||||
let client = APIClient(environment: .current)
|
||||
apiClient = client
|
||||
authAPI = AuthAPI(client: client)
|
||||
client.bindAuthTokenProvider {
|
||||
let token = AppStore.shared.token.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
return token.isEmpty ? nil : token
|
||||
}
|
||||
}
|
||||
|
||||
/// 测试专用初始化,允许注入 mock `APIClient`。
|
||||
init(apiClient: APIClient) {
|
||||
self.apiClient = apiClient
|
||||
authAPI = AuthAPI(client: apiClient)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user