v0.9.10 优化 process 增加 会话服务器
This commit is contained in:
parent
622c9a9ab3
commit
1fc21beeee
9 changed files with 177 additions and 48 deletions
|
|
@ -20,6 +20,7 @@ var Conf Config
|
|||
type Config struct {
|
||||
XiangConfig
|
||||
Service ServiceConfig `json:"service,omitempty"`
|
||||
Session SessionConfig `json:"session,omitempty"`
|
||||
Database DatabaseConfig `json:"database,omitempty"`
|
||||
JWT JWTConfig `json:"jwt,omitempty"`
|
||||
Log LogConfig `json:"log,omitempty"`
|
||||
|
|
@ -58,6 +59,14 @@ type ServiceConfig struct {
|
|||
Port int `json:"port,omitempty" env:"XIANG_SERVICE_PORT" envDefault:"5099"` // 服务监听端口
|
||||
}
|
||||
|
||||
// SessionConfig 会话服务器
|
||||
type SessionConfig struct {
|
||||
Debug bool `json:"debug,omitempty" env:"XIANG_SESSION_DEBUG" envDefault:"false"` // DEBUG 开关
|
||||
Hosting bool `json:"hosting,omitempty" env:"XIANG_SESSION_HOSTING" envDefault:"true"` // 会话服务器
|
||||
Host string `json:"host,omitempty" env:"XIANG_SESSION_HOST" envDefault:"127.0.0.1"` // 会话服务器IP
|
||||
Port int `json:"port,omitempty" env:"XIANG_SESSION_PORT" envDefault:"3322"` // 会话服务器端口
|
||||
}
|
||||
|
||||
// DatabaseConfig 数据库配置
|
||||
type DatabaseConfig struct {
|
||||
Debug bool `json:"debug,omitempty" env:"XIANG_DB_DEBUG" envDefault:"false"` // DEBUG 开关
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ func uiIndexHtml() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "ui/index.html", size: 12, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "ui/index.html", size: 12, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -224,7 +224,7 @@ func xiangDs_store() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/.DS_Store", size: 6148, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/.DS_Store", size: 6148, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -244,7 +244,7 @@ func xiangApisReadmeMd() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/apis/README.md", size: 13, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/apis/README.md", size: 13, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -264,7 +264,7 @@ func xiangApisChartHttpJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/apis/chart.http.json", size: 624, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/apis/chart.http.json", size: 624, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -284,7 +284,7 @@ func xiangApisPageHttpJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/apis/page.http.json", size: 609, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/apis/page.http.json", size: 609, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -304,7 +304,7 @@ func xiangApisStorageHttpJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/apis/storage.http.json", size: 1092, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/apis/storage.http.json", size: 1092, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -324,7 +324,7 @@ func xiangApisTableHttpJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/apis/table.http.json", size: 2632, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/apis/table.http.json", size: 2632, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -344,7 +344,7 @@ func xiangApisUserHttpJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/apis/user.http.json", size: 1453, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/apis/user.http.json", size: 1453, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -364,7 +364,7 @@ func xiangApisXiangHttpJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/apis/xiang.http.json", size: 1239, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/apis/xiang.http.json", size: 1239, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -384,7 +384,7 @@ func xiangDataAppJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/data/app.json", size: 245, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/data/app.json", size: 245, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -404,7 +404,7 @@ func xiangDataIconsDs_store() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/data/icons/.DS_Store", size: 6148, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/data/icons/.DS_Store", size: 6148, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -424,7 +424,7 @@ func xiangDataIcons404Png() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/data/icons/404.png", size: 9342, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/data/icons/404.png", size: 9342, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -444,7 +444,7 @@ func xiangDataIconsIconIcns() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/data/icons/icon.icns", size: 75636, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/data/icons/icon.icns", size: 75636, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -464,7 +464,7 @@ func xiangDataIconsIconIco() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/data/icons/icon.ico", size: 31310, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/data/icons/icon.ico", size: 31310, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -484,7 +484,7 @@ func xiangDataIconsIconPng() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/data/icons/icon.png", size: 22420, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/data/icons/icon.png", size: 22420, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -504,7 +504,7 @@ func xiangDataIndexHtml() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/data/index.html", size: 302, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/data/index.html", size: 302, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -524,7 +524,7 @@ func xiangFlowsReadmeMd() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/flows/README.md", size: 12, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/flows/README.md", size: 12, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -544,7 +544,7 @@ func xiangFlowsMenuFlowJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/flows/menu.flow.json", size: 1045, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/flows/menu.flow.json", size: 1045, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -564,7 +564,7 @@ func xiangFlowsTableGetFlowJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/flows/table/get.flow.json", size: 541, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/flows/table/get.flow.json", size: 541, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -584,7 +584,7 @@ func xiangModelsReadmeMd() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/models/README.md", size: 15, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/models/README.md", size: 15, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -604,7 +604,7 @@ func xiangModelsMenuJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/models/menu.json", size: 2378, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/models/menu.json", size: 2378, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -624,7 +624,7 @@ func xiangModelsUserJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/models/user.json", size: 8826, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/models/user.json", size: 8826, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -644,7 +644,7 @@ func xiangModelsWorkflowModJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/models/workflow.mod.json", size: 3333, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/models/workflow.mod.json", size: 3333, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -664,7 +664,7 @@ func xiangTablesReadmeMd() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/tables/README.md", size: 15, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/tables/README.md", size: 15, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -684,7 +684,7 @@ func xiangTablesMenuJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/tables/menu.json", size: 10382, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/tables/menu.json", size: 10382, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -704,7 +704,7 @@ func xiangTablesUserJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xiang/tables/user.json", size: 1422, mode: os.FileMode(420), modTime: time.Unix(1638111968, 0)}
|
||||
info := bindataFileInfo{name: "xiang/tables/user.json", size: 1422, mode: os.FileMode(420), modTime: time.Unix(1638115948, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,10 +33,6 @@ func init() {
|
|||
|
||||
gou.RegisterProcessHandler("xiang.helper.Print", ProcessPrint)
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.Get", ProcessGet)
|
||||
gou.RegisterProcessHandler("xiang.helper.Post", ProcessPost)
|
||||
gou.RegisterProcessHandler("xiang.helper.Send", ProcessSend)
|
||||
|
||||
}
|
||||
|
||||
// ProcessPrint xiang.helper.Print 打印语句
|
||||
|
|
|
|||
|
|
@ -5,4 +5,8 @@ import "github.com/yaoapp/gou"
|
|||
func init() {
|
||||
// 注册处理器
|
||||
gou.RegisterProcessHandler("xiang.network.ip", ProcessIP)
|
||||
gou.RegisterProcessHandler("xiang.network.Get", ProcessGet)
|
||||
gou.RegisterProcessHandler("xiang.network.Post", ProcessPost)
|
||||
gou.RegisterProcessHandler("xiang.network.PostJSON", ProcessPostJSON)
|
||||
gou.RegisterProcessHandler("xiang.network.Send", ProcessSend)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
package helper
|
||||
package network
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
|
@ -27,22 +28,35 @@ func RequestPost(url string, data interface{}, headers map[string]string) Respon
|
|||
return RequestSend("POST", url, map[string]interface{}{}, data, headers)
|
||||
}
|
||||
|
||||
// RequestPostJSON 发送POST请求
|
||||
func RequestPostJSON(url string, data interface{}, headers map[string]string) Response {
|
||||
if headers == nil {
|
||||
headers = map[string]string{}
|
||||
}
|
||||
headers["content-type"] = "application/json;charset=utf8"
|
||||
return RequestSend("POST", url, map[string]interface{}{}, data, headers)
|
||||
}
|
||||
|
||||
// RequestSend 发送Request请求
|
||||
func RequestSend(method string, url string, params map[string]interface{}, data interface{}, headers map[string]string) Response {
|
||||
|
||||
var body []byte
|
||||
var err error
|
||||
if data != nil {
|
||||
body, err = jsoniter.Marshal(data)
|
||||
if err != nil {
|
||||
return Response{
|
||||
Status: 500,
|
||||
Body: err.Error(),
|
||||
Data: map[string]interface{}{"code": 500, "message": err.Error()},
|
||||
Headers: map[string]interface{}{
|
||||
"Content-Type": "application/json;charset=utf8",
|
||||
},
|
||||
if strings.HasPrefix(strings.ToLower(headers["content-type"]), "application/json") {
|
||||
body, err = jsoniter.Marshal(data)
|
||||
if err != nil {
|
||||
return Response{
|
||||
Status: 500,
|
||||
Body: err.Error(),
|
||||
Data: map[string]interface{}{"code": 500, "message": err.Error()},
|
||||
Headers: map[string]interface{}{
|
||||
"Content-Type": "application/json;charset=utf8",
|
||||
},
|
||||
}
|
||||
}
|
||||
} else {
|
||||
body = []byte(fmt.Sprintf("%v", data))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -59,8 +73,10 @@ func RequestSend(method string, url string, params map[string]interface{}, data
|
|||
}
|
||||
|
||||
// Request Header
|
||||
for name, header := range headers {
|
||||
req.Header.Set(name, header)
|
||||
if headers != nil {
|
||||
for name, header := range headers {
|
||||
req.Header.Set(name, header)
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := (&http.Client{}).Do(req)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package helper
|
||||
package network
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -25,6 +25,24 @@ func ProcessPost(process *gou.Process) interface{} {
|
|||
return RequestPost(url, data, headers)
|
||||
}
|
||||
|
||||
// ProcessPostJSON xiang.helper.PostJSON HTTP Post
|
||||
func ProcessPostJSON(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
var data interface{}
|
||||
headers := map[string]string{}
|
||||
url := process.ArgsString(0)
|
||||
if process.NumOfArgs() > 1 {
|
||||
data = process.Args[1]
|
||||
}
|
||||
if process.NumOfArgs() > 2 {
|
||||
inputHeaders := process.ArgsMap(2)
|
||||
for name, value := range inputHeaders {
|
||||
headers[name] = fmt.Sprintf("%v", value)
|
||||
}
|
||||
}
|
||||
return RequestPostJSON(url, data, headers)
|
||||
}
|
||||
|
||||
// ProcessSend xiang.helper.Send HTTP Send
|
||||
func ProcessSend(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package helper
|
||||
package network
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
|
@ -26,9 +26,14 @@ func TestRequestPost(t *testing.T) {
|
|||
assert.Equal(t, 404, resp.Status)
|
||||
}
|
||||
|
||||
func TestRequestPostJSON(t *testing.T) {
|
||||
resp := RequestPostJSON("https://api.github.com/zen", map[string]interface{}{"foo": "bar"}, nil)
|
||||
assert.Equal(t, 404, resp.Status)
|
||||
}
|
||||
|
||||
func TestRequestProcessGet(t *testing.T) {
|
||||
args := []interface{}{"https://api.github.com/zen"}
|
||||
res := gou.NewProcess("xiang.helper.Get", args...).Run()
|
||||
res := gou.NewProcess("xiang.network.Get", args...).Run()
|
||||
resp, ok := res.(Response)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 200, resp.Status)
|
||||
|
|
@ -37,7 +42,15 @@ func TestRequestProcessGet(t *testing.T) {
|
|||
|
||||
func TestRequestProcessPost(t *testing.T) {
|
||||
args := []interface{}{"https://api.github.com/zen", map[string]interface{}{"foo": "bar"}, nil}
|
||||
res := gou.NewProcess("xiang.helper.Post", args...).Run()
|
||||
res := gou.NewProcess("xiang.network.Post", args...).Run()
|
||||
resp, ok := res.(Response)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 404, resp.Status)
|
||||
}
|
||||
|
||||
func TestRequestProcessPostJSON(t *testing.T) {
|
||||
args := []interface{}{"https://api.github.com/zen", map[string]interface{}{"foo": "bar"}, nil}
|
||||
res := gou.NewProcess("xiang.network.PostJSON", args...).Run()
|
||||
resp, ok := res.(Response)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 404, resp.Status)
|
||||
|
|
@ -45,7 +58,7 @@ func TestRequestProcessPost(t *testing.T) {
|
|||
|
||||
func TestRequestProcessSend(t *testing.T) {
|
||||
args := []interface{}{"GET", "https://api.github.com/zen"}
|
||||
res := gou.NewProcess("xiang.helper.Send", args...).Run()
|
||||
res := gou.NewProcess("xiang.network.Send", args...).Run()
|
||||
resp, ok := res.(Response)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 200, resp.Status)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package share
|
||||
|
||||
// VERSION 版本号
|
||||
const VERSION = "0.9.8"
|
||||
const VERSION = "0.9.10"
|
||||
|
||||
// DOMAIN 许可域(废弃)
|
||||
const DOMAIN = "*.iqka.com"
|
||||
|
|
|
|||
73
share/session.go
Normal file
73
share/session.go
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
package share
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
||||
"github.com/buraksezer/olric"
|
||||
"github.com/buraksezer/olric/client"
|
||||
config_olric "github.com/buraksezer/olric/config"
|
||||
"github.com/buraksezer/olric/serializer"
|
||||
"github.com/yaoapp/gou/session"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/xiang/config"
|
||||
)
|
||||
|
||||
// SessionConnect 加载会话信息
|
||||
func SessionConnect() {
|
||||
if config.Conf.Session.Hosting {
|
||||
SessionServer()
|
||||
return
|
||||
}
|
||||
|
||||
var clientConfig = &client.Config{
|
||||
Servers: []string{fmt.Sprintf("%s:%d", config.Conf.Session.Host, config.Conf.Session.Port)},
|
||||
Serializer: serializer.NewMsgpackSerializer(),
|
||||
Client: config_olric.NewClient(),
|
||||
}
|
||||
|
||||
c, err := client.New(clientConfig)
|
||||
if err != nil {
|
||||
exception.New("会话服务器连接失败 %s", 500, err.Error()).Throw()
|
||||
}
|
||||
|
||||
dm := c.NewDMap("local-session")
|
||||
session.MemoryUse(session.ClientDMap{DMap: dm})
|
||||
}
|
||||
|
||||
// SessionServer 启动会话服务器
|
||||
func SessionServer() {
|
||||
|
||||
c := config_olric.New("local")
|
||||
c.BindAddr = config.Conf.Session.Host
|
||||
c.BindPort = config.Conf.Session.Port
|
||||
|
||||
c.Logger.SetOutput(ioutil.Discard) // 暂时关闭日志
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
c.Started = func() {
|
||||
defer cancel()
|
||||
// log.Println("[INFO] Olric is ready to accept connections")
|
||||
}
|
||||
|
||||
db, err := olric.New(c)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create Olric instance: %v", err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
err = db.Start() // Call Start at background. It's a blocker call.
|
||||
if err != nil {
|
||||
log.Fatalf("olric.Start returned an error: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
<-ctx.Done()
|
||||
dm, err := db.NewDMap("local-session")
|
||||
if err != nil {
|
||||
log.Fatalf("olric.NewDMap returned an error: %v", err)
|
||||
}
|
||||
|
||||
session.MemoryUse(session.ServerDMap{DMap: dm})
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue