Skip to content

Commit

Permalink
doc: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ztj1993 committed Oct 25, 2019
1 parent 6533896 commit bd6ba63
Showing 1 changed file with 55 additions and 14 deletions.
69 changes: 55 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Config Api

这是一个配置 restful api 接口,是一个 json yaml restful 接口。
这是一个 config restful api 接口。

项目主要解决在命令行下操作 json, yaml 配置文件问题
主要解决在命令行下操作 json, yaml, ini 等配置文件问题

## 项目功能
- 通过 API 接口操作配置项
- 上传 JSON, YAML 配置文件
- 操作 JSON, YAML 配置项(增删改查)
- 通过 API 接口操作配置文件
- 支持 JSON, YAML 配置文件的增删改查
- 输出 JSON, YAML 配置文件
- 支持将环境变量转为 INI 配置文件

## 项目地址
- Github(国外):https://github.com/ztj1993/config-api.git
Expand All @@ -26,7 +26,12 @@ docker run -d --name config-api -p 5000:5000 ztj1993/config-api
```

## 使用示例

> JSON 配置文件操作示例
```
$ uri=http://127.0.0.1:5000
$ #获取配置原始数据
$ data=$(cat /etc/docker/daemon.json) && echo ${data}
Expand All @@ -35,27 +40,29 @@ $ data=$(cat /etc/docker/daemon.json) && echo ${data}
}
$ #初始化配置游标
$ cursor_id=$(curl -sf http://127.0.0.1:5000/init) && echo ${cursor_id}
$ cursor_id=$(curl -fsS ${uri}/init) && echo ${cursor_id}
158853936809905161020585456234816085535
$ cursor_uri=${uri}/${cursor_id}
$ #将配置上传到游标
$ curl http://127.0.0.1:5000/${cursor_id}/load/json -d "${data}"
$ curl ${cursor_uri}/load/json -d "${data}"
ok
$ #操作配置
$ curl http://127.0.0.1:5000/${cursor_id}/set/bool?key=tlsverify -d "true"
$ curl http://127.0.0.1:5000/${cursor_id}/set/str?key=tlscacert -d "/etc/certs/ca.pem"
$ curl http://127.0.0.1:5000/${cursor_id}/set/str?key=tlscert -d "/etc/certs/server-cert.pem"
$ curl http://127.0.0.1:5000/${cursor_id}/set/str?key=tlskey -d "/etc/certs/server-key.pem"
$ curl http://127.0.0.1:5000/${cursor_id}/append/str?key=hosts -d "tcp://0.0.0.0:2376"
$ curl http://127.0.0.1:5000/${cursor_id}/append/str?key=hosts -d "unix:///var/run/docker.sock"
$ curl -H "Content-Type: text/plain" ${cursor_uri}/set/bool?key=tlsverify -d "true"
$ curl -H "Content-Type: text/plain" ${cursor_uri}/set/str?key=tlscacert -d "/etc/certs/ca.pem"
$ curl -H "Content-Type: text/plain" ${cursor_uri}/set/str?key=tlscert -d "/etc/certs/server-cert.pem"
$ curl -H "Content-Type: text/plain" ${cursor_uri}/set/str?key=tlskey -d "/etc/certs/server-key.pem"
$ curl -H "Content-Type: text/plain" ${cursor_uri}/append/str?key=hosts -d "tcp://0.0.0.0:2376"
$ curl -H "Content-Type: text/plain" ${cursor_uri}/append/str?key=hosts -d "unix:///var/run/docker.sock"
ok
$ #输出配置
$ curl http://127.0.0.1:5000/${cursor_id}/output/json
$ curl ${cursor_uri}/output/json
{
"registry-mirrors": [
Expand All @@ -73,6 +80,40 @@ $ curl http://127.0.0.1:5000/${cursor_id}/output/json
```

> 环境变量生成 INI 配置文件示例
```
$ export FRP_COMMON_SERVER_ADDR=0.0.0.0
$ export FRP_COMMON_BIND_PORT=7000
$ export FRP_SSH_TYPE=tcp
$ export FRP_SSH_LOCAL_IP=127.0.0.1
$ export FRP_SSH_LOCAL_PORT=22
$ export FRP_SSH_REMOTE_PORT=6000
$ data=$(env | grep FRP) && echo "${data}"
FRP_COMMON_SERVER_ADDR=0.0.0.0
FRP_COMMON_BIND_PORT=7000
FRP_SSH_TYPE=tcp
FRP_SSH_LOCAL_IP=127.0.0.1
FRP_SSH_LOCAL_PORT=22
FRP_SSH_REMOTE_PORT=6000
$ query_args="prefix=FRP&delimiter=_&section_lower=1&key_lower=1"
$ curl -H "Content-Type: text/plain" http://127.0.0.1:5000/env_to_ini?${query_args} -d "${data}"
[common]
server_addr = 0.0.0.0
bind_port = 7000
[ssh]
local_ip = 127.0.0.1
remote_port = 6000
local_port = 22
type = tcp
```

## 文档说明
- [接口文档](Docs/Api.md)

Expand Down

0 comments on commit bd6ba63

Please sign in to comment.