Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mstmdev committed Dec 24, 2021
1 parent c7d83ac commit aee1ab1
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 13 deletions.
6 changes: 1 addition & 5 deletions cmd/gofs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ func main() {
log.Error(err, "create the instance of Monitor error")
return
}
defer func() {
if err = monitor.Close(); err != nil {
log.Error(err, "close monitor error")
}
}()
defer monitor.Close()

// start monitor
log.Log("monitor is starting...")
Expand Down
2 changes: 1 addition & 1 deletion monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewMonitor(syncer sync.Sync, retry retry.Retry, syncOnce bool, enableTLS bo
} else if src.Is(core.RemoteDisk) && src.Server() {
return NewFsNotifyMonitor(syncer, retry, syncOnce)
} else if src.Is(core.RemoteDisk) && !src.Server() {
return NewRemoteClientMonitor(syncer, retry, syncOnce, src.Host(), src.Port(), enableTLS, certFile, keyFile, users)
return NewRemoteClientMonitor(syncer, retry, syncOnce, src.Host(), src.Port(), enableTLS, users)
}
return nil, fmt.Errorf("file system unsupported ! src=>%s", src.Type().String())

Expand Down
2 changes: 1 addition & 1 deletion monitor/remote_client_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type message struct {
}

// NewRemoteClientMonitor create an instance of remoteClientMonitor to monitor the remote file change
func NewRemoteClientMonitor(syncer sync.Sync, retry retry.Retry, syncOnce bool, host string, port int, enableTLS bool, certFile string, keyFile string, users []*auth.User) (Monitor, error) {
func NewRemoteClientMonitor(syncer sync.Sync, retry retry.Retry, syncOnce bool, host string, port int, enableTLS bool, users []*auth.User) (Monitor, error) {
if syncer == nil {
err := errors.New("syncer can't be nil")
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions server/middleware/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ func NewLoginHandler(users []*auth.User) handler.GinHandler {

func (h *loginHandler) Handle(c *gin.Context) {
defer func() {
e := recover()
if e != nil {
if e := recover(); e != nil {
log.Error(fmt.Errorf("%v", e), "user login error")
c.String(http.StatusOK, "user login error")
}
Expand Down
3 changes: 1 addition & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ func ReleaseTemplate(releasePath string, serverTemplateOverride bool) error {
if err != nil {
return err
}
err = os.MkdirAll(filepath.ToSlash(releasePath), os.ModePerm)
if err != nil {
if err = os.MkdirAll(filepath.ToSlash(releasePath), os.ModePerm); err != nil {
return err
}
for _, f := range files {
Expand Down
2 changes: 0 additions & 2 deletions tran/tcpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ func NewServer(ip string, port int, enableTLS bool, certFile string, keyFile str
}
if len(srv.users) == 0 {
log.Warn("the tcp server allows anonymous access, you should set some server users by the -users or -rand_user_count flag for security reasons")
} else {

}
return srv
}
Expand Down
1 change: 1 addition & 0 deletions util/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

// MD5FromFile calculate the hash value of the file
// If you reuse the file reader, please set its offset to start position first, like os.File.Seek
func MD5FromFile(file io.Reader, bufSize int) (hash string, err error) {
if file == nil {
err = errors.New("file is nil")
Expand Down

0 comments on commit aee1ab1

Please sign in to comment.