wget https://dl.google.com/go/go1.14.linux-amd64.tar.gz
tar -C /usr/local/ -xvf go1.14.linux-amd64.tar.gz
vim /etc/profile
export GOROOT=/usr/local/go
export PATH=$PATH:/usr/local/go/bin
export GOPATH=/data/golang
go version
发布地址:https://github.com/oubingbing/go-websokcet.git (git pull) 发布分支: master 发布备注:
vim /etc/profile
GOPROXY=https://goproxy.io
GO111MODULE=on
在项目目录下执行一下命令
set GOOS=linux
set GOARCH=amd64
go build
先给生成的二级制文件scoket读写的权限 然后执行以下命令启动服务
nohup ./socket &
该服务的端口为 8088
参考配置
[root@txy-op-elk-05 conf.d]# vim socket.domain.com.conf
server {
listen 80;
server_name socket.domain.com;
charset utf-8;
default_type 'text/html';
client_max_body_size 4G;
error_log /data/logs/nginx/socket.domain.com.error.log;
access_log /data/logs/nginx/socket.domain.com.access.log;
index index.php index.html;
location / {
proxy_pass http://127.0.0.1:8088;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
完成部署
请求URL:
http://127.0.0.1:8088/auth
请求方式:
- POST
参数:
参数名 | 必选 | 类型 | 说明 |
---|---|---|---|
sign | 是 | string | 后端返回的token,aes-128-ecb对称加密字符串,签名密钥可在config.ini中key_sign处修改 |
返回示例
{
"code":200,
"message":"授权成功",
"data":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6IloxOHpYMkZmTVE9PSIsImV4cCI6MTU4MTQ5NTgyOX0.fUUvADIm7otda4Z58fq1PIgcXnzBGhx6_ERDBBQjYKc",
"contact_email":"[email protected]"
}
返回参数说明
参数名 | 类型 | 说明 |
---|---|---|
code | int | 不为200即报错 |
message | string | 接口提示信息 |
data | string | token |
请求URL:
ws://127.0.0.1:8088/ws
请求方式:
- GET
参数:
参数名 | 必选 | 类型 | 说明 |
---|---|---|---|
token | 是 | string | 后端返回的token |
返回示例
{"code":201,"message":"连接成功","data":null,"contact_email":"[email protected]"}
返回参数说明
参数名 | 类型 | 说明 |
---|---|---|
code | int | 201为心跳检测或者握手成功,200为业务数据推送 |
message | string | 接口提示信息 |
data | string | 业务数据 |
请求URL:
ws://127.0.0.1:8088/ws
请求方式:
- GET
参数:
参数名 | 必选 | 类型 | 说明 |
---|---|---|---|
token | 是 | string | 后端返回的token |
返回示例
{"code":201,"message":"连接成功","data":null,"contact_email":"[email protected]"}
返回参数说明
参数名 | 类型 | 说明 |
---|---|---|
code | int | 201为心跳检测或者握手成功,200为业务数据推送 |
message | string | 接口提示信息 |
data | string | 业务数据 |
请求URL:
http://127.0.0.1:8088/push
请求方式:
- POST
参数:
参数名 | 必选 | 类型 | 说明 |
---|---|---|---|
message | 是 | string | 推送的业务消息 |
token | 是 | string | bearer token,或者可以跟在URL地址后,如:http://127.0.0.1:8088/push?token=****** |
返回示例
{
"code" : 200
"message" : "推送成功"
"data" => null
"contact_email" : "[email protected]"
}
返回参数说明
参数名 | 类型 | 说明 |
---|---|---|
code | int | 不为200即报错 |
message | string | 接口提示信息 |
data | string | nil |