Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
koko
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
koko
Commits
907750c9
Commit
907750c9
authored
Apr 30, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改client
parent
1cbc95dd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
24 deletions
+27
-24
client.go
pkg/common/client.go
+11
-6
switch.go
pkg/proxy/switch.go
+2
-2
init.go
pkg/service/init.go
+6
-8
terminal.go
pkg/service/terminal.go
+7
-7
message.sh
tools/message.sh
+1
-1
No files found.
pkg/common/client.go
View file @
907750c9
...
...
@@ -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
}
...
...
pkg/proxy/switch.go
View file @
907750c9
...
...
@@ -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
)
}
...
...
pkg/service/init.go
View file @
907750c9
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
)
...
...
pkg/service/terminal.go
View file @
907750c9
...
...
@@ -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
)
}
...
...
tools/message.sh
View file @
907750c9
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment