Commit 907750c9 authored by ibuler's avatar ibuler

[Update] 修改client

parent 1cbc95dd
......@@ -22,6 +22,7 @@ type Client struct {
Timeout time.Duration
Headers map[string]string
Auth ClientAuth
BaseHost string
basicAuth []string
cookie map[string]string
http *http.Client
......@@ -32,15 +33,16 @@ type UrlParser interface {
parse(url string, params ...map[string]string) string
}
func NewClient(timeout time.Duration) *Client {
headers := make(map[string]string, 1)
func NewClient(timeout time.Duration, baseHost string) *Client {
headers := make(map[string]string, 0)
client := http.DefaultClient
client.Timeout = timeout * time.Second
return &Client{
Timeout: timeout * time.Second,
Headers: headers,
http: client,
cookie: make(map[string]string, 0),
BaseHost: baseHost,
Timeout: timeout * time.Second,
Headers: headers,
http: client,
cookie: make(map[string]string, 0),
}
}
......@@ -77,6 +79,9 @@ func (c *Client) ParseUrlQuery(url string, query map[string]string) string {
} else {
url += "?" + param
}
if c.BaseHost != "" {
url = strings.TrimRight(c.BaseHost, "/") + url
}
return url
}
......
......@@ -50,12 +50,12 @@ func (s *Switch) watchWindowChange(ctx context.Context, winCh <-chan ssh.Window,
return
case win, ok := <-winCh:
if !ok {
break
return
}
err := s.serverConn.SetWinSize(win.Height, win.Width)
if err != nil {
logger.Error("Change server win size err: ", err)
break
return
}
logger.Debugf("Window server change: %d*%d", win.Height, win.Width)
}
......
package service
import (
"path"
"path/filepath"
"strings"
"cocogo/pkg/common"
"cocogo/pkg/config"
"path"
"path/filepath"
)
var client = common.NewClient(10)
var authClient = common.NewClient(10)
var baseHost string
var client = common.NewClient(30, "")
var authClient = common.NewClient(30, "")
func Initial() {
keyPath := config.Conf.AccessKeyFile
baseHost = strings.TrimRight(config.Conf.CoreHost, "/")
client.BaseHost = config.Conf.CoreHost
authClient.BaseHost = config.Conf.CoreHost
if !path.IsAbs(config.Conf.AccessKeyFile) {
keyPath = filepath.Join(config.Conf.RootPath, keyPath)
......
......@@ -14,7 +14,7 @@ func RegisterTerminal(name, token, comment string) (res model.Terminal) {
client.Headers["Authorization"] = fmt.Sprintf("BootstrapToken %s", token)
data := map[string]string{"name": name, "comment": comment}
err := client.Post(baseHost+TerminalRegisterURL, data, &res)
err := client.Post(TerminalRegisterURL, data, &res)
if err != nil {
logger.Error(err)
}
......@@ -26,7 +26,7 @@ func TerminalHeartBeat(sIds []string) (res []model.TerminalTask) {
data := map[string][]string{
"sessions": sIds,
}
err := authClient.Post(baseHost+TerminalHeartBeatURL, data, &res)
err := authClient.Post(TerminalHeartBeatURL, data, &res)
if err != nil {
logger.Error(err)
}
......@@ -35,7 +35,7 @@ func TerminalHeartBeat(sIds []string) (res []model.TerminalTask) {
func CreateSession(data map[string]interface{}) bool {
var res map[string]interface{}
err := authClient.Post(baseHost+SessionListURL, data, &res)
err := authClient.Post(SessionListURL, data, &res)
if err == nil {
return true
}
......@@ -49,7 +49,7 @@ func FinishSession(sid, dataEnd string) {
"is_finished": true,
"date_end": dataEnd,
}
Url := fmt.Sprintf(baseHost+SessionDetailURL, sid)
Url := fmt.Sprintf(SessionDetailURL, sid)
err := authClient.Patch(Url, data, &res)
if err != nil {
logger.Error(err)
......@@ -59,7 +59,7 @@ func FinishSession(sid, dataEnd string) {
func FinishReply(sid string) bool {
var res map[string]interface{}
data := map[string]bool{"has_replay": true}
Url := fmt.Sprintf(baseHost+SessionDetailURL, sid)
Url := fmt.Sprintf(SessionDetailURL, sid)
err := authClient.Patch(Url, data, &res)
if err != nil {
logger.Error(err)
......@@ -71,7 +71,7 @@ func FinishReply(sid string) bool {
func FinishTask(tid string) bool {
var res map[string]interface{}
data := map[string]bool{"is_finished": true}
Url := fmt.Sprintf(baseHost+FinishTaskURL, tid)
Url := fmt.Sprintf(FinishTaskURL, tid)
err := authClient.Patch(Url, data, res)
if err != nil {
logger.Error(err)
......@@ -81,7 +81,7 @@ func FinishTask(tid string) bool {
}
func LoadConfigFromServer() (res model.TerminalConf) {
err := authClient.Get(baseHost+TerminalConfigURL, &res)
err := authClient.Get(TerminalConfigURL, &res)
if err != nil {
logger.Error(err)
}
......
......@@ -7,7 +7,7 @@ LANG="zh_CN en_US"
DOMAIN=coco
BIN=${PROJECT_DIR}/cmd/geni18n.go
INPUT=pkg
OUTPUT=${PROJECT_DIR}/pkg/i18n/locale/
OUTPUT=${PROJECT_DIR}/cmd/locale/
init_message() {
for lang in $LANG;do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment