Files
yingmeng-ios-switf/yinmeng-ios/HttpRequest/YMRequestConfig.swift

57 lines
2.2 KiB
Swift
Raw Normal View History

2024-02-21 21:30:13 +08:00
//
// YMRequestConfig.swift
// yinmeng-ios
//
// Created by MaiMang on 2024/2/2.
//
import Foundation
import Moya
///
/// Network configuration information, only need to be configured once when the program is started
public struct YMRequestConfig {
/// Whether to add the Debugging plugin by default
public static var addDebugging: Bool = false
/// Whether to add the Indicator plugin by default
public static var addIndicator: Bool = false
/// Set the request timeout, the default is 30 seconds
public static var timeoutIntervalForRequest: Double = 30
public static var interceptor: RequestInterceptor? = nil
/// Root path address
public static var baseURL: APIHost = ""
/// Default request type, default `post`
public static var baseMethod: APIMethod = APIMethod.post
/// Default basic parameters, similar to: userID, token, etc.
public static var baseParameters: APIParameters = [:]
/// Default Header argument, `NetworkHttpHeaderPlugin`.
public static var baseHeaders: [String: String] = [:]
/// Plugins that require default injection, generally not recommended
/// However, you can inject this kind of global unified general plugin, such as secret key plugin, certificate plugin, etc.
public static var basePlugins: [PluginSubType]?
/// Loading animation JSON, for `AnimatedLoadingPlugin` used.
public static var animatedJSON: String?
/// Loading the plugin name, to remove the loading plugin from level status bar window.
public static var loadingPluginNames: [String] = ["Loading", "AnimatedLoading"]
/// Auto close all loading after the end of the last network requesting.
public static var lastCompleteAndCloseLoadingHUDs: Bool = true
/// Update the default basic parameter data, which is generally used for what operation the user has switched.
/// - Parameters:
/// - value: Update value
/// - key: Update key
public static func updateBaseParametersWithValue(_ value: AnyObject?, key: String) {
var dict = YMRequestConfig.baseParameters
if let value = value {
dict.updateValue(value, forKey: key)
} else {
dict.removeValue(forKey: key)
}
YMRequestConfig.baseParameters = dict
}
}