全局配置推荐在Application中设置
class App : Application() {
override fun onCreate() {
super.onCreate()
initNet("http://182.92.97.186/") {
converter(JsonConvert()) // 转换器
cacheEnabled() // 开启缓存
}
}
}
class App : Application() {
override fun onCreate() {
super.onCreate()
initNet("http://182.92.97.186/") {
converter(JsonConvert()) // 转换器
cacheEnabled() // 开启缓存
}
}
}
initNet 作用域内可选函数
单例对象NetConfig存储了初始化时的配置, 可以后期动态读写.
例如Retrofit的baseUrl
功能就可以直接修改NetConfig.host