短链接生成服务
特性
- 单点服务
- 主从服务
- rpc交互
- chan异步写入
- 服务内使用内存缓存
- 支持直接引入包使用
- 支持部署http服务使用
go build main.go && main
curl --location --request POST '127.0.0.1:8080/put' \
--form 'url=https://www.kxjun.top/'
# http://www.frommaster.com 长链生成的短链为 1
# Successed shortURL(short: long) is 0: https://www.kxjun.top
curl --location --request POST '127.0.0.1:8080/get' \
--form 'key=0'
# Successed shortURL(short: long) is 0: https://www.kxjun.top
使用浏览器访问:127.0.0.1:8080/0
会重定向到 https://www.kxjun.top
go build main.go
# 启动主服务
main -port=:8080 -rpc=true
# 启动从服务1
main -master=127.0.0.1:8080 -port=:8081
# 启动从服务2
main -master=127.0.0.1:8080 -port=:8082
curl --location --request POST '127.0.0.1:8081/put' \
--form 'url=https://www.slave1.top/'
curl --location --request POST '127.0.0.1:8082/put' \
--form 'url=https://www.slave2.top/'
curl --location --request POST '127.0.0.1:8080/put' \
--form 'url=https://www.master.top/'
# Successed shortURL(short: long) is 1: https://www.slave1.top/
# Successed shortURL(short: long) is 2: https://www.slave2.top/
# Successed shortURL(short: long) is 3: https://www.master.top/
# 主服务:127.0.0.1:8080
# 从服务1:127.0.0.1:8081
# 从服务2:127.0.0.1:8082
curl --location --request POST '127.0.0.1:8082/get' \
--form 'key=0'
# Successed shortURL(short: long) is 0: https://www.kxjun.top
使用浏览器访问:
主:127.0.0.1:8080/0
从:127.0.0.1:8081/0
or 127.0.0.1:8082/0
会重定向到 https://www.kxjun.top
$ main --help
Usage of main:
-file string
data store filename (default "store.json")
-host string
hostname (default "127.0.0.1")
-master string
rpc master address
-port string
http listen port (default ":8080")
-rpc
enable rpc service