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 c8f64d52
authored
Dec 22, 2021
by
shenyizhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* gofmt
1 parent
18bd56ba
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
238 additions
and
238 deletions
src/auth/auth.go
src/download/download.go
src/encrypt/encrypt.go
src/httpcli/httpcli.go
src/main.go
src/nodetree/nodetree.go
src/travloc/travloc.go
src/travloc/travloc_test.go
src/travremot/travremot.go
src/travremot/travremot_test.go
src/upload/upload.go
src/auth/auth.go
View file @
c8f64d5
package
auth
import
(
"fmt"
"os"
"fmt"
"log"
"os"
)
func
init
()
{
...
...
src/download/download.go
View file @
c8f64d5
package
download
import
(
"o
s"
"log"
"github.com/sirupsen/logrus
"
"minsync/nodetree
"
"github.com/sirupsen/logru
s"
"log"
"minsync/nodetree
"
"os
"
)
func
init
()
{
log
.
Println
(
"minsync.download.init() called"
)
log
.
Println
(
"minsync.download.init() called"
)
var
log01
=
logrus
.
New
()
log01
.
Formatter
=
new
(
logrus
.
JSONFormatter
)
log01
.
Formatter
=
new
(
logrus
.
TextFormatter
)
//default
log01
.
Formatter
.
(
*
logrus
.
TextFormatter
)
.
DisableColors
=
true
// remove colors
log01
.
Formatter
.
(
*
logrus
.
TextFormatter
)
.
DisableTimestamp
=
true
// remove timestamp from test output
log01
.
Level
=
logrus
.
TraceLevel
log01
.
Out
=
os
.
Stdout
var
log01
=
logrus
.
New
()
log01
.
Formatter
=
new
(
logrus
.
JSONFormatter
)
log01
.
Formatter
=
new
(
logrus
.
TextFormatter
)
//default
log01
.
Formatter
.
(
*
logrus
.
TextFormatter
)
.
DisableColors
=
true
// remove colors
log01
.
Formatter
.
(
*
logrus
.
TextFormatter
)
.
DisableTimestamp
=
true
// remove timestamp from test output
log01
.
Level
=
logrus
.
TraceLevel
log01
.
Out
=
os
.
Stdout
log01
.
Debug
(
"minsync.download.init() called, from logrus"
)
log01
.
Debug
(
"minsync.download.init() called, from logrus"
)
}
func
Download
(
src
string
,
dst
string
)
(
nodetree
.
Task
,
error
)
{
var
task
nodetree
.
Task
return
task
,
nil
var
task
nodetree
.
Task
return
task
,
nil
}
func
QueryProgress
(
task_id
string
)
(
nodetree
.
Task
,
error
)
{
var
task
nodetree
.
Task
return
task
,
nil
var
task
nodetree
.
Task
return
task
,
nil
}
src/encrypt/encrypt.go
View file @
c8f64d5
package
encrypt
import
(
_
"fmt"
"log"
_
"fmt"
"log"
)
func
init
()
{
log
.
Println
(
"minsync.encrypt.init() called"
)
log
.
Println
(
"minsync.encrypt.init() called"
)
}
src/httpcli/httpcli.go
View file @
c8f64d5
package
httpcli
import
(
"fmt"
"io/ioutil"
"net/http
"
"log
"
"fmt"
"io/ioutil"
"log
"
"net/http
"
)
func
init
()
{
log
.
Println
(
"minsync.httpcli.init() called"
)
log
.
Println
(
"minsync.httpcli.init() called"
)
}
func
Get
(
url
string
)
([]
byte
,
error
)
{
fmt
.
Println
(
url
)
resp
,
err
:=
http
.
Get
(
url
)
defer
resp
.
Body
.
Close
()
body
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
return
body
,
err
fmt
.
Println
(
url
)
resp
,
err
:=
http
.
Get
(
url
)
defer
resp
.
Body
.
Close
()
body
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
return
body
,
err
}
func
Post
(
postdata
string
)
([]
byte
,
error
)
{
return
nil
,
nil
return
nil
,
nil
}
func
Delete
(
postdata
string
)
([]
byte
,
error
)
{
return
nil
,
nil
return
nil
,
nil
}
func
Update
(
postdata
string
)
([]
byte
,
error
)
{
return
nil
,
nil
return
nil
,
nil
}
src/main.go
View file @
c8f64d5
...
...
@@ -2,7 +2,6 @@ package main
import
(
"bytes"
"os"
"encoding/json"
_
"fmt"
_
"io/ioutil"
...
...
@@ -16,6 +15,7 @@ import (
"minsync/travremot"
_
"minsync/upload"
_
"net/http"
"os"
"runtime"
)
...
...
src/nodetree/nodetree.go
View file @
c8f64d5
package
nodetree
import
(
_
"fmt"
"log"
_
"fmt"
"log"
)
type
NodeLoc
struct
{
Name
string
`json:"name"`
Path
string
`json:"path"`
Children
[]
*
NodeLoc
`json:"children"`
IsDir
bool
`json:"isDir"`
Name
string
`json:"name"`
Path
string
`json:"path"`
Children
[]
*
NodeLoc
`json:"children"`
IsDir
bool
`json:"isDir"`
}
type
OptionLoc
struct
{
RootPath
[]
string
`yaml:"rootPath"`
SubFlag
bool
`yaml:"subFlag"`
// if traverse sub dir
IgnorePath
[]
string
`yaml:"ignorePath"`
IgnoreFile
[]
string
`yaml:"ignoreFile"`
RootPath
[]
string
`yaml:"rootPath"`
SubFlag
bool
`yaml:"subFlag"`
// if traverse sub dir
IgnorePath
[]
string
`yaml:"ignorePath"`
IgnoreFile
[]
string
`yaml:"ignoreFile"`
}
type
NodeRemot
struct
{
Name
string
`json:"name"`
Type
string
`json:"type"`
UpdtDate
string
`json:"update_date"`
Creator
string
`json:"creator"`
Size
int
`json:"size"`
Children
[]
*
NodeRemot
`json:"children"`
Name
string
`json:"name"`
Type
string
`json:"type"`
UpdtDate
string
`json:"update_date"`
Creator
string
`json:"creator"`
Size
int
`json:"size"`
Children
[]
*
NodeRemot
`json:"children"`
}
type
ListRemot
struct
{
List
[]
*
NodeRemot
`json:"list"`
Total
int
`json:"total"`
PageSize
int
`json:"pagesize"`
Pages
int
`json:"pages"`
List
[]
*
NodeRemot
`json:"list"`
Total
int
`json:"total"`
PageSize
int
`json:"pagesize"`
Pages
int
`json:"pages"`
}
type
DataRemot
struct
{
Data
ListRemot
`json:"data"`
Msg
string
`json:"msg"`
Data
ListRemot
`json:"data"`
Msg
string
`json:"msg"`
}
type
OptionRemot
struct
{
RootPath
[]
string
`yaml:"rootPath"`
SubFlag
bool
`yaml:"subFlag"`
// if traverse sub dir
PageSize
int
`yaml:"pagesize"`
Pages
int
`yaml:"pages"`
Token
string
`yaml:"token"`
RootPath
[]
string
`yaml:"rootPath"`
SubFlag
bool
`yaml:"subFlag"`
// if traverse sub dir
PageSize
int
`yaml:"pagesize"`
Pages
int
`yaml:"pages"`
Token
string
`yaml:"token"`
}
type
Task
struct
{
Id
string
`json:"id"`
Progress
int
`json:"progress"`
State
int
`json:"state"`
Id
string
`json:"id"`
Progress
int
`json:"progress"`
State
int
`json:"state"`
}
func
init
()
{
log
.
Println
(
"minsync.nodetree init() called"
)
log
.
Println
(
"minsync.nodetree init() called"
)
}
src/travloc/travloc.go
View file @
c8f64d5
package
travloc
import
(
_
"fmt"
"strings
"
"os
"
"io/ioutil
"
"path
"
"log
"
"minsync/nodetree
"
_
"fmt"
"io/ioutil
"
"log
"
"minsync/nodetree
"
"os
"
"path
"
"strings
"
)
func
init
()
{
log
.
Println
(
"minsync.travloc.init() called"
)
log
.
Println
(
"minsync.travloc.init() called"
)
}
func
Explorer
(
option
nodetree
.
OptionLoc
)
(
nodetree
.
NodeLoc
,
error
)
{
var
root
nodetree
.
NodeLoc
var
root
nodetree
.
NodeLoc
for
_
,
p
:=
range
option
.
RootPath
{
if
strings
.
TrimSpace
(
p
)
==
""
{
continue
}
for
_
,
p
:=
range
option
.
RootPath
{
if
strings
.
TrimSpace
(
p
)
==
""
{
continue
}
var
child
nodetree
.
NodeLoc
var
child
nodetree
.
NodeLoc
child
.
Path
=
p
child
.
Path
=
p
exploreRecursive
(
&
child
,
&
option
)
exploreRecursive
(
&
child
,
&
option
)
root
.
Children
=
append
(
root
.
Children
,
&
child
)
}
root
.
Children
=
append
(
root
.
Children
,
&
child
)
}
return
root
,
nil
return
root
,
nil
}
func
exploreRecursive
(
node
*
nodetree
.
NodeLoc
,
option
*
nodetree
.
OptionLoc
)
{
p
,
err
:=
os
.
Stat
(
node
.
Path
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
}
node
.
Name
=
p
.
Name
()
node
.
IsDir
=
p
.
IsDir
()
if
!
p
.
IsDir
()
{
return
}
sub
,
err
:=
ioutil
.
ReadDir
(
node
.
Path
)
if
err
!=
nil
{
info
:=
"dir is not exist, or open failed"
log
.
Printf
(
"%v: %v"
,
info
,
err
)
return
}
for
_
,
f
:=
range
sub
{
tmp
:=
path
.
Join
(
node
.
Path
,
f
.
Name
())
var
child
nodetree
.
NodeLoc
child
.
Path
=
tmp
child
.
IsDir
=
f
.
IsDir
()
if
f
.
IsDir
()
{
if
option
.
SubFlag
{
if
!
IsInSlice
(
option
.
IgnorePath
,
f
.
Name
())
{
node
.
Children
=
append
(
node
.
Children
,
&
child
)
exploreRecursive
(
&
child
,
option
)
}
}
else
{
if
!
IsInSlice
(
option
.
IgnoreFile
,
f
.
Name
())
{
child
.
Name
=
f
.
Name
()
node
.
Children
=
append
(
node
.
Children
,
&
child
)
}
}
}
else
{
if
!
IsInSlice
(
option
.
IgnoreFile
,
f
.
Name
())
{
child
.
Name
=
f
.
Name
()
node
.
Children
=
append
(
node
.
Children
,
&
child
)
}
}
}
p
,
err
:=
os
.
Stat
(
node
.
Path
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
}
node
.
Name
=
p
.
Name
()
node
.
IsDir
=
p
.
IsDir
()
if
!
p
.
IsDir
()
{
return
}
sub
,
err
:=
ioutil
.
ReadDir
(
node
.
Path
)
if
err
!=
nil
{
info
:=
"dir is not exist, or open failed"
log
.
Printf
(
"%v: %v"
,
info
,
err
)
return
}
for
_
,
f
:=
range
sub
{
tmp
:=
path
.
Join
(
node
.
Path
,
f
.
Name
())
var
child
nodetree
.
NodeLoc
child
.
Path
=
tmp
child
.
IsDir
=
f
.
IsDir
()
if
f
.
IsDir
()
{
if
option
.
SubFlag
{
if
!
IsInSlice
(
option
.
IgnorePath
,
f
.
Name
())
{
node
.
Children
=
append
(
node
.
Children
,
&
child
)
exploreRecursive
(
&
child
,
option
)
}
}
else
{
if
!
IsInSlice
(
option
.
IgnoreFile
,
f
.
Name
())
{
child
.
Name
=
f
.
Name
()
node
.
Children
=
append
(
node
.
Children
,
&
child
)
}
}
}
else
{
if
!
IsInSlice
(
option
.
IgnoreFile
,
f
.
Name
())
{
child
.
Name
=
f
.
Name
()
node
.
Children
=
append
(
node
.
Children
,
&
child
)
}
}
}
}
func
IsInSlice
(
slice
[]
string
,
s
string
)
bool
{
if
len
(
slice
)
==
0
{
return
false
;
}
isIn
:=
false
for
_
,
f
:=
range
slice
{
if
f
==
s
{
isIn
=
true
break
}
}
return
isIn
if
len
(
slice
)
==
0
{
return
false
}
isIn
:=
false
for
_
,
f
:=
range
slice
{
if
f
==
s
{
isIn
=
true
break
}
}
return
isIn
}
src/travloc/travloc_test.go
View file @
c8f64d5
package
travloc
import
(
"fmt
"
"bytes
"
"encoding/json
"
"log"
"os
"
"runtime
"
"testing
"
"minsync/nodetree
"
"bytes
"
"encoding/json
"
"fmt
"
"log"
"minsync/nodetree
"
"os
"
"runtime
"
"testing
"
)
func
TestExplorer
(
t
*
testing
.
T
)
{
var
option
nodetree
.
Option
fmt
.
Println
(
runtime
.
GOOS
)
if
runtime
.
GOOS
==
"darwin"
||
runtime
.
GOOS
==
"linux"
{
option
.
RootPath
=
[]
string
{
`/home/syz/workshop/projects/minsync/src`
,
}
}
if
runtime
.
GOOS
==
"windows"
{
option
.
RootPath
=
[]
string
{
`C:\`
}
}
option
.
SubFlag
=
true
option
.
IgnorePath
=
[]
string
{
`.git`
,
`.svn`
}
option
.
IgnoreFile
=
[]
string
{
`.DS_Store`
,
`.gitignore`
}
result
,
err
:=
Explorer
(
option
)
if
err
!=
nil
{
panic
(
err
)
}
OutTerminal
(
result
)
var
option
nodetree
.
Option
fmt
.
Println
(
runtime
.
GOOS
)
if
runtime
.
GOOS
==
"darwin"
||
runtime
.
GOOS
==
"linux"
{
option
.
RootPath
=
[]
string
{
`/home/syz/workshop/projects/minsync/src`
,
}
}
if
runtime
.
GOOS
==
"windows"
{
option
.
RootPath
=
[]
string
{
`C:\`
}
}
option
.
SubFlag
=
true
option
.
IgnorePath
=
[]
string
{
`.git`
,
`.svn`
}
option
.
IgnoreFile
=
[]
string
{
`.DS_Store`
,
`.gitignore`
}
result
,
err
:=
Explorer
(
option
)
if
err
!=
nil
{
panic
(
err
)
}
OutTerminal
(
result
)
}
func
OutTerminal
(
obj
interface
{})
{
b
,
err
:=
json
.
Marshal
(
obj
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
b
,
err
:=
json
.
Marshal
(
obj
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
var
out
bytes
.
Buffer
err
=
json
.
Indent
(
&
out
,
b
,
""
,
" "
)
var
out
bytes
.
Buffer
err
=
json
.
Indent
(
&
out
,
b
,
""
,
" "
)
out
.
WriteTo
(
os
.
Stdout
)
out
.
WriteTo
(
os
.
Stdout
)
}
src/travremot/travremot.go
View file @
c8f64d5
package
travremot
import
(
"strings
"
"log
"
"encoding/json
"
"io/ioutil
"
"net/http
"
"minsync/auth
"
"minsync/nodetree
"
"encoding/json
"
"io/ioutil
"
"log
"
"minsync/auth
"
"minsync/nodetree
"
"net/http
"
"strings
"
)
func
init
()
{
log
.
Println
(
"minsync.travremot.init() called"
)
log
.
Println
(
"minsync.travremot.init() called"
)
}
func
Explorer
(
option
nodetree
.
OptionRemot
)
(
nodetree
.
NodeRemot
,
error
)
{
var
root
nodetree
.
NodeRemot
var
root
nodetree
.
NodeRemot
for
_
,
p
:=
range
option
.
RootPath
{
if
strings
.
TrimSpace
(
p
)
==
""
{
continue
}
for
_
,
p
:=
range
option
.
RootPath
{
if
strings
.
TrimSpace
(
p
)
==
""
{
continue
}
var
child
nodetree
.
NodeRemot
var
child
nodetree
.
NodeRemot
child
.
Name
=
p
child
.
Name
=
p
exploreRecursive
(
&
child
,
&
option
)
exploreRecursive
(
&
child
,
&
option
)
root
.
Children
=
append
(
root
.
Children
,
&
child
)
}
root
.
Children
=
append
(
root
.
Children
,
&
child
)
}
return
root
,
nil
return
root
,
nil
}
func
exploreRecursive
(
node
*
nodetree
.
NodeRemot
,
option
*
nodetree
.
OptionRemot
)
{
log
.
Printf
(
"travremot.exploreRecursive() node.Name: %s"
,
node
.
Name
)
log
.
Printf
(
"travremot.exploreRecursive() node.Name: %s"
,
node
.
Name
)
url
:=
"http://122.112.207.59:8989/front/data/query_list?pages=1&pagesize=20&prefix="
url
+=
node
.
Name
url
:=
"http://122.112.207.59:8989/front/data/query_list?pages=1&pagesize=20&prefix="
url
+=
node
.
Name
req
,
_
:=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
req
.
Header
.
Add
(
"token"
,
auth
.
GetToken
())
req
,
_
:=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
req
.
Header
.
Add
(
"token"
,
auth
.
GetToken
())
var
resp
*
http
.
Response
resp
,
err
:=
http
.
DefaultClient
.
Do
(
req
)
if
(
err
!=
nil
)
{
log
.
Println
(
err
)
}
var
resp
*
http
.
Response
resp
,
err
:=
http
.
DefaultClient
.
Do
(
req
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
body
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
body
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
var
jsonRes
nodetree
.
DataRemot
json
.
Unmarshal
(
body
,
&
jsonRes
)
var
jsonRes
nodetree
.
DataRemot
json
.
Unmarshal
(
body
,
&
jsonRes
)
for
_
,
f
:=
range
jsonRes
.
Data
.
List
{
tmp
:=
node
.
Name
+
f
.
Name
for
_
,
f
:=
range
jsonRes
.
Data
.
List
{
tmp
:=
node
.
Name
+
f
.
Name
var
child
nodetree
.
NodeRemot
child
.
Name
=
tmp
child
.
Type
=
f
.
Type
var
child
nodetree
.
NodeRemot
child
.
Name
=
tmp
child
.
Type
=
f
.
Type
if
f
.
Type
==
"folder"
{
child
.
Name
+=
"/"
node
.
Children
=
append
(
node
.
Children
,
&
child
)
exploreRecursive
(
&
child
,
option
)
}
else
if
f
.
Type
==
"file"
{
node
.
Children
=
append
(
node
.
Children
,
&
child
)
}
}
if
f
.
Type
==
"folder"
{
child
.
Name
+=
"/"
node
.
Children
=
append
(
node
.
Children
,
&
child
)
exploreRecursive
(
&
child
,
option
)
}
else
if
f
.
Type
==
"file"
{
node
.
Children
=
append
(
node
.
Children
,
&
child
)
}
}
defer
resp
.
Body
.
Close
()
defer
resp
.
Body
.
Close
()
}
src/travremot/travremot_test.go
View file @
c8f64d5
...
...
@@ -11,9 +11,9 @@ import (
func
TestExplorer
(
t
*
testing
.
T
)
{
var
option
nodetree
.
OptionRemot
option
.
RootPath
=
[]
string
{
`data/`
,
}
option
.
RootPath
=
[]
string
{
`data/`
,
}
option
.
SubFlag
=
true
...
...
src/upload/upload.go
View file @
c8f64d5
package
upload
import
(
_
"fmt"
"log"
"minsync/nodetree"
_
"fmt"
"log"
"minsync/nodetree"
)
func
init
()
{
log
.
Println
(
"minsync.upload.init() called"
)
log
.
Println
(
"minsync.upload.init() called"
)
}
func
Upload
(
src
string
,
dst
string
)
(
nodetree
.
Task
,
error
)
{
var
task
nodetree
.
Task
return
task
,
nil
var
task
nodetree
.
Task
return
task
,
nil
}
func
QueryProgress
(
task_id
string
)
(
nodetree
.
Task
,
error
)
{
var
task
nodetree
.
Task
return
task
,
nil
var
task
nodetree
.
Task
return
task
,
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