Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
shenyizhong
/
minsync
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 7e265479
authored
Jan 10, 2022
by
shenyizhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* code review
1 parent
1638a80a
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
52 deletions
src/def/errcode.go
src/httpcli/httpcli.go
src/main.go
src/nodetree/nodetree.go
src/travloc/travloc.go
src/travremot/travremot.go
src/def/errcode.go
View file @
7e26547
...
@@ -12,4 +12,6 @@ const (
...
@@ -12,4 +12,6 @@ const (
ERR_JSON_PARSE
ErrCode
=
-
10006
ERR_JSON_PARSE
ErrCode
=
-
10006
ERR_HTTP_REQUEST
ErrCode
=
-
10007
ERR_HTTP_REQUEST
ErrCode
=
-
10007
ERR_INVALID_PATH
ErrCode
=
-
10008
ERR_INVALID_PATH
ErrCode
=
-
10008
ERR_NOT_DIR
ErrCode
=
-
10009
ERR_INVALID_HOST
ErrCode
=
-
10010
)
)
src/httpcli/httpcli.go
View file @
7e26547
...
@@ -47,6 +47,8 @@ func init() {
...
@@ -47,6 +47,8 @@ func init() {
log
.
Println
(
err
)
log
.
Println
(
err
)
return
return
}
}
nodetree
.
StrHost
=
conf
.
Host
nodetree
.
IntPort
=
conf
.
Port
host
=
conf
.
Host
host
=
conf
.
Host
port
=
conf
.
Port
port
=
conf
.
Port
}
}
...
...
src/main.go
View file @
7e26547
...
@@ -16,8 +16,8 @@ import (
...
@@ -16,8 +16,8 @@ import (
"minsync/travremot"
"minsync/travremot"
_
"minsync/upload"
_
"minsync/upload"
_
"net/http"
_
"net/http"
"path/filepath"
"os"
"os"
"path/filepath"
"runtime"
"runtime"
"strings"
"strings"
)
)
...
@@ -58,6 +58,10 @@ func main() {
...
@@ -58,6 +58,10 @@ func main() {
nodetree
.
StrDst
=
os
.
Args
[
3
]
nodetree
.
StrDst
=
os
.
Args
[
3
]
}
}
if
nodetree
.
StrHost
==
""
{
fmt
.
Println
(
"parse config error"
)
return
}
if
runtime
.
GOOS
==
"windows"
{
if
runtime
.
GOOS
==
"windows"
{
nodetree
.
StrSrc
=
strings
.
Replace
(
nodetree
.
StrSrc
,
"
\\
"
,
"/"
,
-
1
)
nodetree
.
StrSrc
=
strings
.
Replace
(
nodetree
.
StrSrc
,
"
\\
"
,
"/"
,
-
1
)
nodetree
.
StrDst
=
strings
.
Replace
(
nodetree
.
StrDst
,
"
\\
"
,
"/"
,
-
1
)
nodetree
.
StrDst
=
strings
.
Replace
(
nodetree
.
StrDst
,
"
\\
"
,
"/"
,
-
1
)
...
@@ -102,25 +106,6 @@ func main() {
...
@@ -102,25 +106,6 @@ func main() {
nodetree
.
StrToken
=
string
(
data
)
nodetree
.
StrToken
=
string
(
data
)
}
}
pwd
,
err
:=
os
.
Getwd
()
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
}
file
,
err
:=
os
.
Open
(
pwd
+
"/config.json"
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
}
defer
file
.
Close
()
decoder
:=
json
.
NewDecoder
(
file
)
conf
:=
nodetree
.
Configuration
{}
err
=
decoder
.
Decode
(
&
conf
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
}
if
nodetree
.
StrOp
==
"upload"
{
if
nodetree
.
StrOp
==
"upload"
{
nodetree
.
StrDst
=
"data"
+
nodetree
.
StrDst
nodetree
.
StrDst
=
"data"
+
nodetree
.
StrDst
nodetree
.
StrSrc
,
err
=
filepath
.
Abs
(
nodetree
.
StrSrc
)
nodetree
.
StrSrc
,
err
=
filepath
.
Abs
(
nodetree
.
StrSrc
)
...
...
src/nodetree/nodetree.go
View file @
7e26547
...
@@ -90,6 +90,8 @@ var StrOp string
...
@@ -90,6 +90,8 @@ var StrOp string
var
StrSrc
string
var
StrSrc
string
var
StrDst
string
var
StrDst
string
var
StrToken
string
var
StrToken
string
var
StrHost
string
var
IntPort
int
func
init
()
{
func
init
()
{
...
...
src/travloc/travloc.go
View file @
7e26547
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
_
"fmt"
_
"fmt"
"io/ioutil"
"io/ioutil"
"log"
"log"
"minsync/def"
"minsync/httpcli"
"minsync/httpcli"
"minsync/nodetree"
"minsync/nodetree"
"os"
"os"
...
@@ -35,25 +36,24 @@ func Explorer(option nodetree.OptionLoc, op string) (nodetree.NodeLoc, error) {
...
@@ -35,25 +36,24 @@ func Explorer(option nodetree.OptionLoc, op string) (nodetree.NodeLoc, error) {
return
root
,
nil
return
root
,
nil
}
}
func
exploreRecursive
(
node
*
nodetree
.
NodeLoc
,
option
*
nodetree
.
OptionLoc
,
op
string
)
{
func
exploreRecursive
(
node
*
nodetree
.
NodeLoc
,
option
*
nodetree
.
OptionLoc
,
op
string
)
(
def
.
ErrCode
,
error
)
{
p
,
err
:=
os
.
Stat
(
node
.
Path
)
p
,
err
:=
os
.
Stat
(
node
.
Path
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Println
(
err
)
log
.
Println
(
err
)
return
return
def
.
ERR_SYSTEM
,
err
}
}
node
.
Name
=
p
.
Name
()
node
.
Name
=
p
.
Name
()
node
.
IsDir
=
p
.
IsDir
()
node
.
IsDir
=
p
.
IsDir
()
if
!
p
.
IsDir
()
{
if
!
p
.
IsDir
()
{
return
return
def
.
SUCCESS
,
nil
}
}
sub
,
err
:=
ioutil
.
ReadDir
(
node
.
Path
)
sub
,
err
:=
ioutil
.
ReadDir
(
node
.
Path
)
if
err
!=
nil
{
if
err
!=
nil
{
info
:=
"dir is not exist, or open failed"
log
.
Println
(
err
)
log
.
Printf
(
"%v: %v"
,
info
,
err
)
return
def
.
ERR_SYSTEM
,
err
return
}
}
for
_
,
f
:=
range
sub
{
for
_
,
f
:=
range
sub
{
...
@@ -90,6 +90,7 @@ func exploreRecursive(node *nodetree.NodeLoc, option *nodetree.OptionLoc, op str
...
@@ -90,6 +90,7 @@ func exploreRecursive(node *nodetree.NodeLoc, option *nodetree.OptionLoc, op str
}
}
}
}
}
}
return
def
.
SUCCESS
,
nil
}
}
func
IsInSlice
(
slice
[]
string
,
s
string
)
bool
{
func
IsInSlice
(
slice
[]
string
,
s
string
)
bool
{
...
...
src/travremot/travremot.go
View file @
7e26547
...
@@ -6,30 +6,17 @@ import (
...
@@ -6,30 +6,17 @@ import (
"io/ioutil"
"io/ioutil"
"log"
"log"
"minsync/auth"
"minsync/auth"
"minsync/def"
"minsync/httpcli"
"minsync/httpcli"
"minsync/nodetree"
"minsync/nodetree"
"net/http"
"net/http"
"os"
_
"os"
"strconv"
"strconv"
"strings"
"strings"
)
)
var
host
string
var
port
int
func
init
()
{
func
init
()
{
log
.
Println
(
"minsync.travremot.init() called"
)
log
.
Println
(
"minsync.travremot.init() called"
)
file
,
_
:=
os
.
Open
(
"./config.json"
)
defer
file
.
Close
()
decoder
:=
json
.
NewDecoder
(
file
)
conf
:=
nodetree
.
Configuration
{}
err
:=
decoder
.
Decode
(
&
conf
)
if
err
!=
nil
{
log
.
Println
(
"Error:"
,
err
)
}
host
=
conf
.
Host
port
=
conf
.
Port
}
}
func
Explorer
(
option
nodetree
.
OptionRemot
)
(
nodetree
.
NodeRemot
,
error
)
{
func
Explorer
(
option
nodetree
.
OptionRemot
)
(
nodetree
.
NodeRemot
,
error
)
{
...
@@ -53,55 +40,73 @@ func Explorer(option nodetree.OptionRemot) (nodetree.NodeRemot, error) {
...
@@ -53,55 +40,73 @@ func Explorer(option nodetree.OptionRemot) (nodetree.NodeRemot, error) {
return
root
,
nil
return
root
,
nil
}
}
func
exploreRecursive
(
node
*
nodetree
.
NodeRemot
,
option
*
nodetree
.
OptionRemot
)
{
func
exploreRecursive
(
node
*
nodetree
.
NodeRemot
,
option
*
nodetree
.
OptionRemot
)
(
def
.
ErrCode
,
error
)
{
log
.
Printf
(
"travremot.exploreRecursive() node.Name: %s"
,
node
.
Name
)
log
.
Printf
(
"travremot.exploreRecursive() node.Name: %s"
,
node
.
Name
)
// "http://122.112.207.59:8989/front/data/query_list?pages=1&pagesize=200&prefix="
// "http://122.112.207.59:8989/front/data/query_list?pages=1&pagesize=200&prefix="
url
:=
"http://"
url
:=
"http://"
url
+=
h
ost
url
+=
nodetree
.
StrH
ost
url
+=
":"
url
+=
":"
url
+=
strconv
.
Itoa
(
p
ort
)
url
+=
strconv
.
Itoa
(
nodetree
.
IntP
ort
)
url
+=
"/front/data/query_list?pages=1&pagesize=1&prefix="
url
+=
"/front/data/query_list?pages=1&pagesize=1&prefix="
url
+=
node
.
Name
url
+=
node
.
Name
req
,
_
:=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
def
.
ERR_HTTP_REQUEST
,
err
}
req
.
Header
.
Add
(
"token"
,
auth
.
GetToken
())
req
.
Header
.
Add
(
"token"
,
auth
.
GetToken
())
var
resp
*
http
.
Response
var
resp
*
http
.
Response
resp
,
err
:
=
http
.
DefaultClient
.
Do
(
req
)
resp
,
err
=
http
.
DefaultClient
.
Do
(
req
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Println
(
err
)
log
.
Println
(
err
)
return
def
.
ERR_HTTP_REQUEST
,
err
}
}
defer
resp
.
Body
.
Close
()
defer
resp
.
Body
.
Close
()
body
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
def
.
ERR_SYSTEM
,
err
}
var
jsonRes
nodetree
.
DataRemot
var
jsonRes
nodetree
.
DataRemot
json
.
Unmarshal
(
body
,
&
jsonRes
)
json
.
Unmarshal
(
body
,
&
jsonRes
)
url
=
"http://"
url
=
"http://"
url
+=
h
ost
url
+=
nodetree
.
StrH
ost
url
+=
":"
url
+=
":"
url
+=
strconv
.
Itoa
(
p
ort
)
url
+=
strconv
.
Itoa
(
nodetree
.
IntP
ort
)
url
+=
"/front/data/query_list?pages=1&pagesize="
url
+=
"/front/data/query_list?pages=1&pagesize="
url
+=
strconv
.
Itoa
(
jsonRes
.
Data
.
Total
)
url
+=
strconv
.
Itoa
(
jsonRes
.
Data
.
Total
)
url
+=
"&prefix="
url
+=
"&prefix="
url
+=
node
.
Name
url
+=
node
.
Name
log
.
Println
(
url
)
log
.
Println
(
url
)
req
,
_
=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
req
,
err
=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
def
.
ERR_HTTP_REQUEST
,
err
}
req
.
Header
.
Add
(
"token"
,
auth
.
GetToken
())
req
.
Header
.
Add
(
"token"
,
auth
.
GetToken
())
var
respAll
*
http
.
Response
var
respAll
*
http
.
Response
respAll
,
err
=
http
.
DefaultClient
.
Do
(
req
)
respAll
,
err
=
http
.
DefaultClient
.
Do
(
req
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Println
(
err
)
log
.
Println
(
err
)
return
def
.
ERR_HTTP_REQUEST
,
err
}
}
defer
respAll
.
Body
.
Close
()
defer
respAll
.
Body
.
Close
()
bodyAll
,
_
:=
ioutil
.
ReadAll
(
respAll
.
Body
)
bodyAll
,
err
:=
ioutil
.
ReadAll
(
respAll
.
Body
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
def
.
ERR_SYSTEM
,
err
}
var
jsonResAll
nodetree
.
DataRemot
var
jsonResAll
nodetree
.
DataRemot
json
.
Unmarshal
(
bodyAll
,
&
jsonResAll
)
json
.
Unmarshal
(
bodyAll
,
&
jsonResAll
)
...
@@ -133,5 +138,5 @@ func exploreRecursive(node *nodetree.NodeRemot, option *nodetree.OptionRemot) {
...
@@ -133,5 +138,5 @@ func exploreRecursive(node *nodetree.NodeRemot, option *nodetree.OptionRemot) {
node
.
Children
=
append
(
node
.
Children
,
&
child
)
node
.
Children
=
append
(
node
.
Children
,
&
child
)
}
}
}
}
return
def
.
SUCCESS
,
nil
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment