修复CPU占用问题,添加servers.JOIN,LEAVE,LIST包
This commit is contained in:
8
.idea/.gitignore
generated
vendored
8
.idea/.gitignore
generated
vendored
@ -1,8 +0,0 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
4
.idea/coreapp.iml
generated
4
.idea/coreapp.iml
generated
@ -2,9 +2,7 @@
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="Go" enabled="true" />
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
|
2
.idea/material_theme_project_new.xml
generated
2
.idea/material_theme_project_new.xml
generated
@ -5,7 +5,7 @@
|
||||
<MTProjectMetadataState>
|
||||
<option name="migrated" value="true" />
|
||||
<option name="pristineConfig" value="false" />
|
||||
<option name="userId" value="1a45d7d0:197e35b8048:-7ff6" />
|
||||
<option name="userId" value="-38549ec7:1971fe58c79:-7ffe" />
|
||||
</MTProjectMetadataState>
|
||||
</option>
|
||||
</component>
|
||||
|
2
.idea/modules.xml
generated
2
.idea/modules.xml
generated
@ -2,7 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/coreapp.iml" filepath="$PROJECT_DIR$/.idea/coreapp.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/CoreApp.iml" filepath="$PROJECT_DIR$/.idea/CoreApp.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
1
.idea/vcs.xml
generated
1
.idea/vcs.xml
generated
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
33
go.mod
33
go.mod
@ -3,35 +3,36 @@ module coreapp
|
||||
go 1.24
|
||||
|
||||
require (
|
||||
github.com/gin-contrib/cors v1.7.6
|
||||
github.com/gin-gonic/gin v1.10.1
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
google.golang.org/protobuf v1.36.6
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/bytedance/sonic v1.11.6 // indirect
|
||||
github.com/bytedance/sonic/loader v0.1.1 // indirect
|
||||
github.com/cloudwego/base64x v0.1.4 // indirect
|
||||
github.com/cloudwego/iasm v0.2.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/bytedance/sonic v1.13.3 // indirect
|
||||
github.com/bytedance/sonic/loader v0.2.4 // indirect
|
||||
github.com/cloudwego/base64x v0.1.5 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
|
||||
github.com/gin-contrib/sse v1.1.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.20.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/go-playground/validator/v10 v10.26.0 // indirect
|
||||
github.com/goccy/go-json v0.10.5 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
golang.org/x/arch v0.8.0 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
golang.org/x/net v0.25.0 // indirect
|
||||
golang.org/x/sys v0.20.0 // indirect
|
||||
golang.org/x/text v0.15.0 // indirect
|
||||
github.com/ugorji/go/codec v1.3.0 // indirect
|
||||
golang.org/x/arch v0.18.0 // indirect
|
||||
golang.org/x/crypto v0.39.0 // indirect
|
||||
golang.org/x/net v0.41.0 // indirect
|
||||
golang.org/x/sys v0.33.0 // indirect
|
||||
golang.org/x/text v0.26.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
89
go.sum
89
go.sum
@ -1,18 +1,21 @@
|
||||
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
|
||||
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
|
||||
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
|
||||
github.com/bytedance/sonic v1.13.3 h1:MS8gmaH16Gtirygw7jV91pDCN33NyMrPbN7qiYhEsF0=
|
||||
github.com/bytedance/sonic v1.13.3/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
|
||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
|
||||
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
|
||||
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
|
||||
github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
|
||||
github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
|
||||
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
|
||||
github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
|
||||
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY=
|
||||
github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok=
|
||||
github.com/gin-contrib/cors v1.7.6 h1:3gQ8GMzs1Ylpf70y8bMw4fVpycXIeX1ZemuSQIsnQQY=
|
||||
github.com/gin-contrib/cors v1.7.6/go.mod h1:Ulcl+xN4jel9t1Ry8vqph23a60FwH9xVLd+3ykmTjOk=
|
||||
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
|
||||
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
|
||||
github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ=
|
||||
github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
@ -21,21 +24,25 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
|
||||
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k=
|
||||
github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
|
||||
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
|
||||
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
|
||||
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
||||
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
||||
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
@ -45,49 +52,43 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
||||
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
||||
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
|
||||
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA=
|
||||
github.com/ugorji/go/codec v1.3.0/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
|
||||
golang.org/x/arch v0.18.0 h1:WN9poc33zL4AzGxqf8VtpKUnGvMi8O9lhNyBMF/85qc=
|
||||
golang.org/x/arch v0.18.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
|
||||
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
|
||||
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
|
||||
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
|
||||
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
|
||||
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
|
||||
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
|
||||
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||
|
1
main.go
1
main.go
@ -23,7 +23,6 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
defer exit()
|
||||
signalChan := make(chan os.Signal, 1)
|
||||
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
@ -7,6 +7,9 @@ enum ServerPacketType {
|
||||
NEW = 2;
|
||||
DELETE = 3;
|
||||
CONNECT = 4;
|
||||
JOIN = 5;
|
||||
LEAVE = 6;
|
||||
LIST = 7;
|
||||
}
|
||||
|
||||
message ServerPacket {
|
||||
@ -30,4 +33,13 @@ message ServerDeletePacket {
|
||||
message ServerConnectPacket {
|
||||
string serverId = 1;
|
||||
string player = 2;
|
||||
}
|
||||
|
||||
message ServerPlayerPacket {
|
||||
string player = 1;
|
||||
}
|
||||
|
||||
message ServerListPacket {
|
||||
string serverId = 1;
|
||||
repeated string players = 2;
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.6
|
||||
// protoc v5.29.3
|
||||
// protoc v6.31.1
|
||||
// source: server.proto
|
||||
|
||||
package minecraft
|
||||
@ -29,6 +29,9 @@ const (
|
||||
ServerPacketType_NEW ServerPacketType = 2
|
||||
ServerPacketType_DELETE ServerPacketType = 3
|
||||
ServerPacketType_CONNECT ServerPacketType = 4
|
||||
ServerPacketType_JOIN ServerPacketType = 5
|
||||
ServerPacketType_LEAVE ServerPacketType = 6
|
||||
ServerPacketType_LIST ServerPacketType = 7
|
||||
)
|
||||
|
||||
// Enum value maps for ServerPacketType.
|
||||
@ -39,6 +42,9 @@ var (
|
||||
2: "NEW",
|
||||
3: "DELETE",
|
||||
4: "CONNECT",
|
||||
5: "JOIN",
|
||||
6: "LEAVE",
|
||||
7: "LIST",
|
||||
}
|
||||
ServerPacketType_value = map[string]int32{
|
||||
"PING": 0,
|
||||
@ -46,6 +52,9 @@ var (
|
||||
"NEW": 2,
|
||||
"DELETE": 3,
|
||||
"CONNECT": 4,
|
||||
"JOIN": 5,
|
||||
"LEAVE": 6,
|
||||
"LIST": 7,
|
||||
}
|
||||
)
|
||||
|
||||
@ -308,6 +317,102 @@ func (x *ServerConnectPacket) GetPlayer() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
type ServerPlayerPacket struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Player string `protobuf:"bytes,1,opt,name=player,proto3" json:"player,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *ServerPlayerPacket) Reset() {
|
||||
*x = ServerPlayerPacket{}
|
||||
mi := &file_server_proto_msgTypes[4]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *ServerPlayerPacket) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ServerPlayerPacket) ProtoMessage() {}
|
||||
|
||||
func (x *ServerPlayerPacket) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_server_proto_msgTypes[4]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use ServerPlayerPacket.ProtoReflect.Descriptor instead.
|
||||
func (*ServerPlayerPacket) Descriptor() ([]byte, []int) {
|
||||
return file_server_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *ServerPlayerPacket) GetPlayer() string {
|
||||
if x != nil {
|
||||
return x.Player
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type ServerListPacket struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
ServerId string `protobuf:"bytes,1,opt,name=serverId,proto3" json:"serverId,omitempty"`
|
||||
Players []string `protobuf:"bytes,2,rep,name=players,proto3" json:"players,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *ServerListPacket) Reset() {
|
||||
*x = ServerListPacket{}
|
||||
mi := &file_server_proto_msgTypes[5]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *ServerListPacket) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ServerListPacket) ProtoMessage() {}
|
||||
|
||||
func (x *ServerListPacket) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_server_proto_msgTypes[5]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use ServerListPacket.ProtoReflect.Descriptor instead.
|
||||
func (*ServerListPacket) Descriptor() ([]byte, []int) {
|
||||
return file_server_proto_rawDescGZIP(), []int{5}
|
||||
}
|
||||
|
||||
func (x *ServerListPacket) GetServerId() string {
|
||||
if x != nil {
|
||||
return x.ServerId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ServerListPacket) GetPlayers() []string {
|
||||
if x != nil {
|
||||
return x.Players
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_server_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_server_proto_rawDesc = "" +
|
||||
@ -329,14 +434,22 @@ const file_server_proto_rawDesc = "" +
|
||||
"\bserverId\x18\x01 \x01(\tR\bserverId\"I\n" +
|
||||
"\x13ServerConnectPacket\x12\x1a\n" +
|
||||
"\bserverId\x18\x01 \x01(\tR\bserverId\x12\x16\n" +
|
||||
"\x06player\x18\x02 \x01(\tR\x06player*H\n" +
|
||||
"\x06player\x18\x02 \x01(\tR\x06player\",\n" +
|
||||
"\x12ServerPlayerPacket\x12\x16\n" +
|
||||
"\x06player\x18\x01 \x01(\tR\x06player\"H\n" +
|
||||
"\x10ServerListPacket\x12\x1a\n" +
|
||||
"\bserverId\x18\x01 \x01(\tR\bserverId\x12\x18\n" +
|
||||
"\aplayers\x18\x02 \x03(\tR\aplayers*g\n" +
|
||||
"\x10ServerPacketType\x12\b\n" +
|
||||
"\x04PING\x10\x00\x12\b\n" +
|
||||
"\x04PONG\x10\x01\x12\a\n" +
|
||||
"\x03NEW\x10\x02\x12\n" +
|
||||
"\n" +
|
||||
"\x06DELETE\x10\x03\x12\v\n" +
|
||||
"\aCONNECT\x10\x04B\x12Z\x10router/minecraftb\x06proto3"
|
||||
"\aCONNECT\x10\x04\x12\b\n" +
|
||||
"\x04JOIN\x10\x05\x12\t\n" +
|
||||
"\x05LEAVE\x10\x06\x12\b\n" +
|
||||
"\x04LIST\x10\aB\x12Z\x10router/minecraftb\x06proto3"
|
||||
|
||||
var (
|
||||
file_server_proto_rawDescOnce sync.Once
|
||||
@ -351,13 +464,15 @@ func file_server_proto_rawDescGZIP() []byte {
|
||||
}
|
||||
|
||||
var file_server_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||
var file_server_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
|
||||
var file_server_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
|
||||
var file_server_proto_goTypes = []any{
|
||||
(ServerPacketType)(0), // 0: ServerPacketType
|
||||
(*ServerPacket)(nil), // 1: ServerPacket
|
||||
(*ServerNewPacket)(nil), // 2: ServerNewPacket
|
||||
(*ServerDeletePacket)(nil), // 3: ServerDeletePacket
|
||||
(*ServerConnectPacket)(nil), // 4: ServerConnectPacket
|
||||
(*ServerPlayerPacket)(nil), // 5: ServerPlayerPacket
|
||||
(*ServerListPacket)(nil), // 6: ServerListPacket
|
||||
}
|
||||
var file_server_proto_depIdxs = []int32{
|
||||
0, // 0: ServerPacket.typ:type_name -> ServerPacketType
|
||||
@ -380,7 +495,7 @@ func file_server_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_server_proto_rawDesc), len(file_server_proto_rawDesc)),
|
||||
NumEnums: 1,
|
||||
NumMessages: 4,
|
||||
NumMessages: 6,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
|
@ -3,6 +3,7 @@ package minecraft
|
||||
import (
|
||||
"coreapp/util"
|
||||
"coreapp/util/ws"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
"google.golang.org/protobuf/proto"
|
||||
@ -41,14 +42,15 @@ func (typ ServerType) Prefix() string {
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Group string `json:"group"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Type ServerType `json:"type"`
|
||||
Motd string `json:"motd"`
|
||||
LastHB time.Time
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Group string `json:"group"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Type ServerType `json:"type"`
|
||||
Motd string `json:"motd"`
|
||||
Players []string `json:"players"`
|
||||
LastHB time.Time
|
||||
}
|
||||
|
||||
var servers = sync.Map{}
|
||||
@ -88,11 +90,12 @@ func ServerMiddleware() gin.HandlerFunc {
|
||||
}
|
||||
|
||||
func ServerList(c *gin.Context) {
|
||||
serverList := make(map[string]*Server)
|
||||
var serverList []Server
|
||||
|
||||
// 遍历 sync.Map
|
||||
servers.Range(func(key, value interface{}) bool {
|
||||
serverList[key.(string)] = value.(*Server)
|
||||
server := value.(*Server)
|
||||
serverList = append(serverList, *server)
|
||||
return true // 继续遍历
|
||||
})
|
||||
|
||||
@ -104,12 +107,12 @@ func ServerList(c *gin.Context) {
|
||||
}
|
||||
|
||||
type ServerRegisterData struct {
|
||||
Name string `json:"name"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Type ServerType `json:"type"`
|
||||
Group string `json:"group"`
|
||||
Motd string `json:"motd"`
|
||||
Group string `json:"group,omitempty"`
|
||||
Motd string `json:"motd,omitempty"`
|
||||
}
|
||||
|
||||
func ServerRegister(c *gin.Context) {
|
||||
@ -223,6 +226,23 @@ func ServerMessage(c *gin.Context) {
|
||||
if c.GetString("serverId") == "PROXY" {
|
||||
serverProxyConn = wrapped
|
||||
serverProxyLastHB = time.Now()
|
||||
servers.Range(func(_, value any) bool {
|
||||
server := value.(*Server)
|
||||
newPkt := &ServerNewPacket{
|
||||
ServerId: server.Id,
|
||||
Name: server.Name,
|
||||
Host: server.Host,
|
||||
Port: int32(server.Port),
|
||||
Group: server.Group,
|
||||
Motd: server.Motd,
|
||||
}
|
||||
buf, err := serverWrapPacket(ServerPacketType_NEW, newPkt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
wrapped.WriteChan <- ws.Binary(buf)
|
||||
return true
|
||||
})
|
||||
go serverProxyReadLoop(wrapped)
|
||||
} else {
|
||||
go serverReadLoop(wrapped, c.GetString("serverId"))
|
||||
@ -230,6 +250,9 @@ func ServerMessage(c *gin.Context) {
|
||||
}
|
||||
|
||||
func serverReadLoop(conn *ws.Conn, serverId string) {
|
||||
defer func() {
|
||||
fmt.Printf("%s closed\n", serverId)
|
||||
}()
|
||||
for {
|
||||
// 使用 Load 读取,避免并发问题
|
||||
serverVal, ok := servers.Load(serverId)
|
||||
@ -266,6 +289,43 @@ func serverReadLoop(conn *ws.Conn, serverId string) {
|
||||
if serverProxyConn != nil {
|
||||
serverProxyConn.WriteChan <- ws.Binary(msg)
|
||||
}
|
||||
case ServerPacketType_JOIN:
|
||||
var payload ServerPlayerPacket
|
||||
err := proto.Unmarshal(pkt.GetPayload(), &payload)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
server.Players = append(server.Players, payload.Player)
|
||||
case ServerPacketType_LEAVE:
|
||||
var payload ServerPlayerPacket
|
||||
err := proto.Unmarshal(pkt.GetPayload(), &payload)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for i, player := range server.Players {
|
||||
if player == payload.Player {
|
||||
server.Players = append(server.Players[:i], server.Players[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
case ServerPacketType_LIST:
|
||||
var payload ServerListPacket
|
||||
err := proto.Unmarshal(pkt.GetPayload(), &payload)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
reply := &ServerListPacket{
|
||||
ServerId: payload.ServerId,
|
||||
}
|
||||
if s, ok := servers.Load(payload.ServerId); ok {
|
||||
reply.Players = s.(*Server).Players
|
||||
buf, err := proto.Marshal(reply)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
conn.WriteChan <- ws.Binary(buf)
|
||||
return
|
||||
}
|
||||
}
|
||||
default:
|
||||
if conn.IsClosed() {
|
||||
@ -280,28 +340,26 @@ func serverProxyReadLoop(conn *ws.Conn) {
|
||||
serverProxyConn = nil
|
||||
}()
|
||||
for {
|
||||
select {
|
||||
case msg := <-conn.ReadChan:
|
||||
if msg == nil {
|
||||
return
|
||||
msg := <-conn.ReadChan
|
||||
if msg == nil {
|
||||
return
|
||||
}
|
||||
pkt := &ServerPacket{}
|
||||
err := proto.Unmarshal(msg, pkt)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
switch pkt.GetTyp() {
|
||||
case ServerPacketType_PING:
|
||||
serverProxyLastHB = time.Now()
|
||||
resp := &ServerPacket{
|
||||
Typ: ServerPacketType_PONG,
|
||||
}
|
||||
pkt := &ServerPacket{}
|
||||
err := proto.Unmarshal(msg, pkt)
|
||||
buf, err := proto.Marshal(resp)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
switch pkt.GetTyp() {
|
||||
case ServerPacketType_PING:
|
||||
serverProxyLastHB = time.Now()
|
||||
resp := &ServerPacket{
|
||||
Typ: ServerPacketType_PONG,
|
||||
}
|
||||
buf, err := proto.Marshal(resp)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
conn.WriteChan <- ws.Binary(buf)
|
||||
}
|
||||
conn.WriteChan <- ws.Binary(buf)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -312,7 +370,7 @@ var serverUpgrader = websocket.Upgrader{
|
||||
}
|
||||
|
||||
func generateServerId(prefix string) string {
|
||||
return string(prefix) + util.RandStringNumber(rand.Intn(2)+1) + strings.ToUpper(util.RandStringAlphabet(rand.Intn(2)+1))
|
||||
return prefix + util.RandStringNumber(rand.Intn(2)+1) + strings.ToUpper(util.RandStringAlphabet(rand.Intn(2)+1))
|
||||
}
|
||||
|
||||
var serverHBTicker = time.NewTicker(time.Second * 5)
|
||||
|
@ -2,12 +2,19 @@ package router
|
||||
|
||||
import (
|
||||
"coreapp/router/minecraft"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Route(server *gin.Engine) {
|
||||
server.Use(cors.New(cors.Config{
|
||||
AllowAllOrigins: true,
|
||||
AllowCredentials: true,
|
||||
AllowMethods: []string{"*"},
|
||||
ExposeHeaders: []string{"*"},
|
||||
AllowHeaders: []string{"*"},
|
||||
}))
|
||||
rootGroup := server.Group("/")
|
||||
|
||||
minecraftGroup := rootGroup.Group("/minecraft")
|
||||
{
|
||||
servers := minecraftGroup.Group("/servers")
|
||||
|
@ -1,6 +1,9 @@
|
||||
package ws
|
||||
|
||||
import "github.com/gorilla/websocket"
|
||||
import (
|
||||
"context"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
type Packet struct {
|
||||
isBinary bool
|
||||
@ -24,6 +27,7 @@ func Binary(buf []byte) *Packet {
|
||||
type Conn struct {
|
||||
WriteChan chan *Packet
|
||||
ReadChan chan []byte
|
||||
ctx context.Context
|
||||
conn *websocket.Conn
|
||||
close bool
|
||||
}
|
||||
@ -40,6 +44,7 @@ func (conn *Conn) ReadLoop() {
|
||||
for !conn.close {
|
||||
_, message, err := conn.conn.ReadMessage()
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
break
|
||||
}
|
||||
conn.ReadChan <- message
|
||||
@ -67,6 +72,7 @@ func (conn *Conn) WriteLoop() {
|
||||
}
|
||||
|
||||
func (conn *Conn) Close() error {
|
||||
conn.ReadChan <- nil
|
||||
conn.close = true
|
||||
return conn.conn.Close()
|
||||
}
|
||||
|
Reference in New Issue
Block a user