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
6d5e52db
Commit
6d5e52db
authored
May 15, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 暂存
parent
60328525
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
10 deletions
+50
-10
config.go
pkg/config/config.go
+44
-5
parsercmd.go
pkg/proxy/parsercmd.go
+3
-2
init.go
pkg/service/init.go
+3
-3
No files found.
pkg/config/config.go
View file @
6d5e52db
...
...
@@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"os"
"reflect"
"strings"
"sync"
)
...
...
@@ -41,7 +42,7 @@ type Config struct {
Language
string
`yaml:"LANG"`
LanguageCode
string
`yaml:"LANGUAGE_CODE"`
// Abandon
Mux
sync
.
RWMutex
mu
sync
.
RWMutex
}
func
(
c
*
Config
)
EnsureConfigValid
()
{
...
...
@@ -56,8 +57,8 @@ func (c *Config) EnsureConfigValid() {
}
func
(
c
*
Config
)
LoadFromYAML
(
body
[]
byte
)
error
{
c
.
Mux
.
Lock
()
defer
c
.
Mux
.
Unlock
()
c
.
mu
.
Lock
()
defer
c
.
mu
.
Unlock
()
err
:=
yaml
.
Unmarshal
(
body
,
c
)
if
err
!=
nil
{
log
.
Printf
(
"Load yaml error: %v"
,
err
)
...
...
@@ -74,8 +75,8 @@ func (c *Config) LoadFromYAMLPath(filepath string) error {
}
func
(
c
*
Config
)
LoadFromJSON
(
body
[]
byte
)
error
{
c
.
Mux
.
Lock
()
defer
c
.
Mux
.
Unlock
()
c
.
mu
.
Lock
()
defer
c
.
mu
.
Unlock
()
err
:=
json
.
Unmarshal
(
body
,
c
)
if
err
!=
nil
{
log
.
Printf
(
"Config load yaml error"
)
...
...
@@ -97,6 +98,44 @@ func (c *Config) LoadFromEnv() error {
return
c
.
LoadFromYAML
(
envYAML
)
}
func
(
c
*
Config
)
Get
(
key
string
)
reflect
.
Value
{
c
.
mu
.
Lock
()
defer
c
.
mu
.
Unlock
()
//t := reflect.TypeOf(c)
v
:=
reflect
.
ValueOf
(
c
)
return
v
.
FieldByName
(
key
)
//for i := 0; i < v.NumField(); i++ {
// if v.Field(i).CanInterface() && t.Field(i).Name == key {
// return v.Field(i).Interface()
// }
//}
//return nil
}
func
(
c
*
Config
)
GetString
(
key
string
)
string
{
value
:=
c
.
Get
(
key
)
return
value
.
String
()
}
func
(
c
*
Config
)
GetBool
(
key
string
)
bool
{
value
:=
c
.
Get
(
key
)
return
value
.
Bool
()
}
func
(
c
*
Config
)
GetInt
(
key
string
)
int
{
value
:=
c
.
Get
(
key
)
return
int
(
value
.
Int
())
}
func
(
c
*
Config
)
GetMap
(
key
string
)
map
[
string
]
string
{
//value := c.Get(key)
//
//if val, ok := value.(map[string]string); ok {
// return val
//}
return
map
[
string
]
string
{}
}
func
(
c
*
Config
)
Load
(
filepath
string
)
error
{
err
:=
c
.
LoadFromYAMLPath
(
filepath
)
if
err
!=
nil
{
...
...
pkg/proxy/parsercmd.go
View file @
6d5e52db
...
...
@@ -2,12 +2,13 @@ package proxy
import
(
"bytes"
"cocogo/pkg/utils"
"regexp"
"strings"
"cocogo/pkg/utils"
)
var
ps1Pattern
,
_
=
regexp
.
Compile
(
"^
\\
[?.*@.*
\\
]?[
\\
$#]
\\
s|mysql>
\\
s"
)
var
ps1Pattern
=
regexp
.
MustCompile
(
`^\[?.*@.*\]?[\\$#]\s|mysql>\s`
)
func
NewCmdParser
()
*
CmdParser
{
parser
:=
&
CmdParser
{}
...
...
pkg/service/init.go
View file @
6d5e52db
...
...
@@ -77,15 +77,15 @@ func MustLoadServerConfigOnce() {
func
LoadConfigFromServer
()
(
err
error
)
{
conf
:=
config
.
Conf
conf
.
Mux
.
Lock
()
defer
conf
.
Mux
.
Unlock
()
conf
.
mu
.
Lock
()
defer
conf
.
mu
.
Unlock
()
err
=
authClient
.
Get
(
TerminalConfigURL
,
conf
)
return
err
}
func
KeepSyncConfigWithServer
()
{
for
{
logger
.
Debug
(
"Sync config
from
server"
)
logger
.
Debug
(
"Sync config
with
server"
)
err
:=
LoadConfigFromServer
()
if
err
!=
nil
{
logger
.
Warn
(
"Sync config with server error: "
,
err
)
...
...
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