+ FreePort Helper & Auto Session port
This commit is contained in:
parent
54a53ca82f
commit
1056defb31
8 changed files with 54 additions and 4 deletions
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
|
|
@ -91,7 +91,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
src: ./dist/release/*
|
src: ./dist/release/*
|
||||||
host: ${{ secrets.SSH_HOST }}
|
host: ${{ secrets.SSH_HOST }}
|
||||||
remote: /data/down/
|
remote: /data/release/ui/
|
||||||
port: ${{ secrets.SSH_PORT }}
|
port: ${{ secrets.SSH_PORT }}
|
||||||
user: ${{ secrets.SSH_USER }}
|
user: ${{ secrets.SSH_USER }}
|
||||||
key: ${{ secrets.SSH_KEY }}
|
key: ${{ secrets.SSH_KEY }}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ var langs = map[string]string{
|
||||||
"NEXT:": "下一步:",
|
"NEXT:": "下一步:",
|
||||||
"Listening": " 监听",
|
"Listening": " 监听",
|
||||||
"✨LISTENING✨": "✨服务正在运行✨",
|
"✨LISTENING✨": "✨服务正在运行✨",
|
||||||
|
"SessionPort": "会话服务端口",
|
||||||
}
|
}
|
||||||
|
|
||||||
// L 多语言切换
|
// L 多语言切换
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ var startCmd = &cobra.Command{
|
||||||
fmt.Println(color.WhiteString(L("Frontend")), color.GreenString(" http://%s%s/", host, port))
|
fmt.Println(color.WhiteString(L("Frontend")), color.GreenString(" http://%s%s/", host, port))
|
||||||
fmt.Println(color.WhiteString(L("Dashboard")), color.GreenString(" http://%s%s/xiang/login/admin", host, port))
|
fmt.Println(color.WhiteString(L("Dashboard")), color.GreenString(" http://%s%s/xiang/login/admin", host, port))
|
||||||
fmt.Println(color.WhiteString(L("API")), color.GreenString(" http://%s%s/api", host, port))
|
fmt.Println(color.WhiteString(L("API")), color.GreenString(" http://%s%s/api", host, port))
|
||||||
|
fmt.Println(color.WhiteString(L("SessionPort")), color.GreenString(" %d", share.SessionPort))
|
||||||
fmt.Println(color.WhiteString(L("Listening")), color.GreenString(" %s:%d", config.Conf.Host, config.Conf.Port))
|
fmt.Println(color.WhiteString(L("Listening")), color.GreenString(" %s:%d", config.Conf.Host, config.Conf.Port))
|
||||||
|
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
|
|
|
||||||
|
|
@ -38,3 +38,25 @@ func IP() map[string]string {
|
||||||
func ProcessIP(process *gou.Process) interface{} {
|
func ProcessIP(process *gou.Process) interface{} {
|
||||||
return IP()
|
return IP()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FreePort xiang.network.FreePort 获取可用端口
|
||||||
|
func FreePort() int {
|
||||||
|
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
|
||||||
|
if err != nil {
|
||||||
|
exception.New("获取可用端口失败 %s", 500, err.Error()).Throw()
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
l, err := net.ListenTCP("tcp", addr)
|
||||||
|
if err != nil {
|
||||||
|
exception.New("获取可用端口失败 %s", 500, err.Error()).Throw()
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
defer l.Close()
|
||||||
|
return l.Addr().(*net.TCPAddr).Port
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProcessFreePort xiang.network.FreePort 获取可用端口
|
||||||
|
func ProcessFreePort(process *gou.Process) interface{} {
|
||||||
|
return FreePort()
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,3 +18,15 @@ func TestProcessIP(t *testing.T) {
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
assert.True(t, len(resp) > 0)
|
assert.True(t, len(resp) > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFreePort(t *testing.T) {
|
||||||
|
port := FreePort()
|
||||||
|
assert.True(t, port > 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProcessFreePort(t *testing.T) {
|
||||||
|
res := gou.NewProcess("xiang.network.FreePort").Run()
|
||||||
|
port, ok := res.(int)
|
||||||
|
assert.True(t, ok)
|
||||||
|
assert.True(t, port > 0)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import "github.com/yaoapp/gou"
|
||||||
func init() {
|
func init() {
|
||||||
// 注册处理器
|
// 注册处理器
|
||||||
gou.RegisterProcessHandler("xiang.network.ip", ProcessIP)
|
gou.RegisterProcessHandler("xiang.network.ip", ProcessIP)
|
||||||
|
gou.RegisterProcessHandler("xiang.network.FreePort", ProcessFreePort)
|
||||||
gou.RegisterProcessHandler("xiang.network.Get", ProcessGet)
|
gou.RegisterProcessHandler("xiang.network.Get", ProcessGet)
|
||||||
gou.RegisterProcessHandler("xiang.network.Post", ProcessPost)
|
gou.RegisterProcessHandler("xiang.network.Post", ProcessPost)
|
||||||
gou.RegisterProcessHandler("xiang.network.PostJSON", ProcessPostJSON)
|
gou.RegisterProcessHandler("xiang.network.PostJSON", ProcessPostJSON)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package share
|
package share
|
||||||
|
|
||||||
|
// Logs
|
||||||
|
// (session -> freeport)
|
||||||
|
|
||||||
// VERSION 版本号
|
// VERSION 版本号
|
||||||
const VERSION = "0.9.0"
|
const VERSION = "0.9.0"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,15 +15,24 @@ import (
|
||||||
"github.com/yaoapp/gou/session"
|
"github.com/yaoapp/gou/session"
|
||||||
"github.com/yaoapp/kun/exception"
|
"github.com/yaoapp/kun/exception"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
|
"github.com/yaoapp/yao/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
var sessServer *olric.Olric
|
var sessServer *olric.Olric
|
||||||
|
|
||||||
|
// SessionPort Session 端口
|
||||||
|
var SessionPort int
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
SessionPort = network.FreePort()
|
||||||
|
klog.Trace("session port: %d", SessionPort)
|
||||||
|
}
|
||||||
|
|
||||||
// SessionConnect 加载会话信息
|
// SessionConnect 加载会话信息
|
||||||
func SessionConnect(conf config.SessionConfig) {
|
func SessionConnect(conf config.SessionConfig) {
|
||||||
|
|
||||||
var clientConfig = &client.Config{
|
var clientConfig = &client.Config{
|
||||||
Servers: []string{fmt.Sprintf("%s:%d", conf.Host, conf.Port)},
|
Servers: []string{fmt.Sprintf("%s:%d", "127.0.0.1", SessionPort)},
|
||||||
Serializer: serializer.NewMsgpackSerializer(),
|
Serializer: serializer.NewMsgpackSerializer(),
|
||||||
Client: config_olric.NewClient(),
|
Client: config_olric.NewClient(),
|
||||||
}
|
}
|
||||||
|
|
@ -46,9 +55,10 @@ func SessionServerStop() {
|
||||||
|
|
||||||
// SessionServerStart 启动会话服务器
|
// SessionServerStart 启动会话服务器
|
||||||
func SessionServerStart() {
|
func SessionServerStart() {
|
||||||
|
|
||||||
c := &config_olric.Config{
|
c := &config_olric.Config{
|
||||||
BindAddr: config.Conf.Session.Host,
|
BindAddr: "127.0.0.1",
|
||||||
BindPort: config.Conf.Session.Port,
|
BindPort: SessionPort,
|
||||||
ReadRepair: false,
|
ReadRepair: false,
|
||||||
ReplicaCount: 1,
|
ReplicaCount: 1,
|
||||||
WriteQuorum: 1,
|
WriteQuorum: 1,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue