🎨 Cleanup code

This commit is contained in:
Liang Ding 2019-05-16 10:52:31 +08:00
parent 11dbe42c9a
commit efcceccac4
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
2 changed files with 15 additions and 14 deletions

View File

@ -83,14 +83,19 @@ var Wide *conf
// configurations of users. // configurations of users.
var Users []*User var Users []*User
// Load loads the Wide configurations from wide.json and users' configurations from users/{username}.json. // Indicates whether Docker is available.
func Load(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, var Docker bool
confPlayground string, confUsersWorkspaces string) {
// XXX: ugly args list....
initWide(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, // Load loads the Wide configurations from wide.json and users' configurations from users/{username}.json.
confPlayground, confUsersWorkspaces) func Load(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground string, confUsersWorkspaces string) {
initWide(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground, confUsersWorkspaces)
initUsers() initUsers()
cmd := exec.Command("docker", "version")
_, err := cmd.CombinedOutput()
if nil != err {
logger.Warn("Not found 'docker' installed, running user's code will cause security problem")
}
} }
func initUsers() { func initUsers() {

View File

@ -480,7 +480,7 @@ func (sessions *wSessions) new(httpSession *sessions.Session, sid string) *WideS
for { for {
ch := SessionWS[sid] ch := SessionWS[sid]
if nil == ch { if nil == ch {
return // release this gorutine return // release this goroutine
} }
select { select {
@ -506,17 +506,13 @@ func (sessions *wSessions) new(httpSession *sessions.Session, sid string) *WideS
} }
} }
cmd := map[string]interface{}{"path": path, "dir": dir, cmd := map[string]interface{}{"path": path, "dir": dir, "cmd": "create-file", "type": fileType}
"cmd": "create-file", "type": fileType}
ch.WriteJSON(&cmd) ch.WriteJSON(&cmd)
} else if event.Op&fsnotify.Remove == fsnotify.Remove { } else if event.Op&fsnotify.Remove == fsnotify.Remove {
cmd := map[string]interface{}{"path": path, "dir": dir, cmd := map[string]interface{}{"path": path, "dir": dir, "cmd": "remove-file", "type": ""}
"cmd": "remove-file", "type": ""}
ch.WriteJSON(&cmd) ch.WriteJSON(&cmd)
} else if event.Op&fsnotify.Rename == fsnotify.Rename { } else if event.Op&fsnotify.Rename == fsnotify.Rename {
cmd := map[string]interface{}{"path": path, "dir": dir, cmd := map[string]interface{}{"path": path, "dir": dir, "cmd": "rename-file", "type": ""}
"cmd": "rename-file", "type": ""}
ch.WriteJSON(&cmd) ch.WriteJSON(&cmd)
} }
case err := <-watcher.Errors: case err := <-watcher.Errors: