🎨 用户目录

This commit is contained in:
Liang Ding 2019-05-16 12:13:11 +08:00
parent f1cc112a52
commit 318f453125
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
2 changed files with 16 additions and 9 deletions

View File

@ -120,7 +120,7 @@ func (u *User) Save() bool {
return false return false
} }
if err = ioutil.WriteFile("conf/users/"+u.Name+".json", bytes, 0644); nil != err { if err = ioutil.WriteFile(filepath.Join(Wide.Users, u.Name+".json"), bytes, 0644); nil != err {
logger.Error(err) logger.Error(err)
return false return false

View File

@ -69,6 +69,7 @@ type conf struct {
WD string // current working direcitory, ${pwd} WD string // current working direcitory, ${pwd}
Locale string // default locale Locale string // default locale
Playground string // playground directory Playground string // playground directory
Users string // users directory
UsersWorkspaces string // users' workspaces directory (admin defaults to ${GOPATH}, others using this) UsersWorkspaces string // users' workspaces directory (admin defaults to ${GOPATH}, others using this)
AllowRegister bool // allow register or not AllowRegister bool // allow register or not
Autocomplete bool // default autocomplete Autocomplete bool // default autocomplete
@ -88,8 +89,8 @@ var Docker bool
// Load loads the Wide configurations from wide.json and users' configurations from users/{username}.json. // Load loads the Wide configurations from wide.json and users' configurations from users/{username}.json.
func Load(confPath, confUsers, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground string, confUsersWorkspaces string) { func Load(confPath, confUsers, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground string, confUsersWorkspaces string) {
initWide(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground, confUsersWorkspaces) initWide(confPath, confUsers, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground, confUsersWorkspaces)
initUsers(confUsers) initUsers()
cmd := exec.Command("docker", "version") cmd := exec.Command("docker", "version")
_, err := cmd.CombinedOutput() _, err := cmd.CombinedOutput()
@ -98,8 +99,8 @@ func Load(confPath, confUsers, confIP, confPort, confServer, confLogLevel, confS
} }
} }
func initUsers(confUsers string) { func initUsers() {
f, err := os.Open(confUsers) f, err := os.Open(Wide.Users)
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
@ -125,7 +126,7 @@ func initUsers(confUsers string) {
user := &User{} user := &User{}
bytes, _ := ioutil.ReadFile(filepath.Join(confUsers, name)) bytes, _ := ioutil.ReadFile(filepath.Join(Wide.Users, name))
err := json.Unmarshal(bytes, user) err := json.Unmarshal(bytes, user)
if err != nil { if err != nil {
logger.Errorf("Parses [%s] error: %v, skip loading this user", name, err) logger.Errorf("Parses [%s] error: %v, skip loading this user", name, err)
@ -156,7 +157,7 @@ func initUsers(confUsers string) {
initCustomizedConfs() initCustomizedConfs()
} }
func initWide(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground string, confUsersWorkspaces string) { func initWide(confPath, confUsers, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground string, confUsersWorkspaces string) {
bytes, err := ioutil.ReadFile(confPath) bytes, err := ioutil.ReadFile(confPath)
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
@ -196,13 +197,19 @@ func initWide(confPath, confIP, confPort, confServer, confLogLevel, confStaticSe
logger.Debugf("${user.home} [%s]", home) logger.Debugf("${user.home} [%s]", home)
// Playground Directory // Users directory
if "" != confUsers {
Wide.Users = confUsers
}
Wide.Users = filepath.Clean(Wide.Users)
// Playground directory
Wide.Playground = strings.Replace(Wide.Playground, "${home}", home, 1) Wide.Playground = strings.Replace(Wide.Playground, "${home}", home, 1)
if "" != confPlayground { if "" != confPlayground {
Wide.Playground = confPlayground Wide.Playground = confPlayground
} }
// Users' workspaces Directory // Users' workspaces directory
Wide.UsersWorkspaces = strings.Replace(Wide.UsersWorkspaces, "${WD}", Wide.WD, 1) Wide.UsersWorkspaces = strings.Replace(Wide.UsersWorkspaces, "${WD}", Wide.WD, 1)
Wide.UsersWorkspaces = strings.Replace(Wide.UsersWorkspaces, "${home}", home, 1) Wide.UsersWorkspaces = strings.Replace(Wide.UsersWorkspaces, "${home}", home, 1)
if "" != confUsersWorkspaces { if "" != confUsersWorkspaces {