8000 GitHub - landscapeside/rehost: 基于retrofit的地址管理器
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

landscapeside/rehost

Repository files navigation

特性:

支持基于retrofit网络库的动态主机地址切换工具

支持管理多服务器环境

引入

// 根build.gradle
allprojects {
    repositories {
        ...
        maven { url 'https://www.jitpack.io' }
    }
}

// app的build.gradle
implementation "com.github.landscapeside:rehost:latest.release"

使用

  • 在应用module(一般名字叫app)的src/main/assets目录下新建hosts.json文件,其内容格式如下:
//每个配置项均由name标识配置名字以及urls包含主机地址数组,名字不可重复
[
  {
    "name": "dev",
    "urls": [
      "https://bpm.ijovo.com/",
      "http://jxbscbd.ijovo.com/"
    ]
  },
  {
    "name": "release",
    "urls": [
      "https://bpmts.ijovo.com/",
      "https://api.jxbscbd.com/"
    ]
  },
  {
    "name": "virtualServer",
    "urls": [
      "http://localhost:10000/",
      "http://localhost:10000/"
    ]
  }
]

  • Application实现类的onCreate生命周期中初始化:
// 得到一个未设置baseUrl的Retrofit.Builder,具体方式参考retrofit用法
// 用法一
ReHost.init(
        this,
        BuildConfig.DEBUG,
        retrofitBuilder
    ){switchRelease->
	if(switchRelease){
		// 切换到正式环境了,可以执行一些其他操作
	}else{
		.....
	}
}

// 用法二
ReHost.init(
        this,
        BuildConfig.DEBUG,
        retrofitBuilder
    )

  • 通过某个按钮可以打开环境选择器:
// 点击某个调试按钮后:
ReHost.openBoard(activity)

选择器如图:

勾选某个配置之后即可生效,关闭窗口即可,另可通过编辑和新增对配置进行管理

  • 将retrofit.create方法调用替换为ReHost.createApiX调用,X支持0-9(即配置项中地址数量最多支持10个)

About

基于retrofit的地址管理器

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0