1
0
mirror of https://github.com/newnius/YAO-scheduler.git synced 2025-12-13 07:46:43 +00:00
This commit is contained in:
2019-08-01 09:54:38 +08:00
parent 463b04d9d0
commit 8d6383592c
2 changed files with 5 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ func InstanceOfGroupManager() *GroupManager {
if groupManagerInstance == nil { if groupManagerInstance == nil {
groupManagerInstance = &GroupManager{groups: map[string]Group{}} groupManagerInstance = &GroupManager{groups: map[string]Group{}}
groupManagerInstance.groups["default"] = Group{Name: "default", Weight: 10, Reserved: false}
} }
return groupManagerInstance return groupManagerInstance
} }
@@ -53,7 +54,8 @@ func (gm *GroupManager) Remove(group Group) MsgGroupCreate {
func (gm *GroupManager) List() MsgGroupList { func (gm *GroupManager) List() MsgGroupList {
defer gm.mu.Unlock() defer gm.mu.Unlock()
gm.mu.Lock() gm.mu.Lock()
var result []Group // cannot change to `var`, since it would be json_encoded to null
result := []Group{}
for _, v := range gm.groups { for _, v := range gm.groups {
result = append(result, v) result = append(result, v)
} }

View File

@@ -113,7 +113,7 @@ func serverAPI(w http.ResponseWriter, r *http.Request) {
log.Debug("group_update") log.Debug("group_update")
var group Group var group Group
msg := MsgGroupCreate{Code: 0} msg := MsgGroupCreate{Code: 0}
err := json.Unmarshal([]byte(string(r.PostFormValue("job"))), &group) err := json.Unmarshal([]byte(string(r.PostFormValue("group"))), &group)
if err != nil { if err != nil {
msg.Code = 1 msg.Code = 1
msg.Error = err.Error() msg.Error = err.Error()
@@ -129,7 +129,7 @@ func serverAPI(w http.ResponseWriter, r *http.Request) {
log.Debug("group_remove") log.Debug("group_remove")
var group Group var group Group
msg := MsgGroupCreate{Code: 0} msg := MsgGroupCreate{Code: 0}
err := json.Unmarshal([]byte(string(r.PostFormValue("job"))), &group) err := json.Unmarshal([]byte(string(r.PostFormValue("group"))), &group)
if err != nil { if err != nil {
msg.Code = 1 msg.Code = 1
msg.Error = err.Error() msg.Error = err.Error()