コード例 #1
0
ファイル: tasks.go プロジェクト: automateship/goaut
func Tasks(w http.ResponseWriter, r *http.Request, s *GoautSession) {
	name := r.URL.Path[len("/tasks/"):]
	//TODO: task names should not let you get out of task dir (no "/" or "..")
	if len(name) != 0 {
		r.ParseForm()
		if len(r.Form["cmd"]) == 1 {
			switch r.Form["cmd"][0] {
			case "read":
				fmt.Fprintf(w, "%s", s.GetTask(name))
			case "delete":
				//TODO: add delete method
				fmt.Fprintf(w, "Running %s on %s task.", r.Form["cmd"][0], name)
			case "update":
				//TODO: add update method
				fmt.Fprintf(w, "Running %s on %s task.", r.Form["cmd"][0], name)
			default:
				fmt.Fprintf(w, "{ \"Success\": false, \"Message\": \"Unknown command '%s'.\" }", r.Form["cmd"][0])
			}
		} else {
			var list TaskBriefList
			brief := task.GetTaskBrief(filepath.Join(s.Conf.TaskDir, name+".json"))
			list.Tasks = append(list.Tasks, brief)
			list.Success = true
			response, err := json.MarshalIndent(list, "", "  ")
			if err == nil {
				fmt.Fprintf(w, string(response))
			} else {
				fmt.Fprintf(w, "{ \"Success\": false, \"Message\": \"%q\" }", err)
			}
		}
	} else {
		r.ParseForm()
		fmt.Fprintf(w, s.GetAllTasks())
	}
}
コード例 #2
0
ファイル: projects.go プロジェクト: automateship/goaut
func (g *GoautSession) GetProjectTasks(name string) string {
	var response []byte
	var err error
	var list TaskBriefList
	var project_data project.Data
	data_bytes, err := ioutil.ReadFile(filepath.Join(g.Conf.ProjectDir, name+".json"))
	if err != nil {
		return fmt.Sprintf("{ \"Success\": false, \"Message\": \"%s\" }", err)
	}
	err = json.Unmarshal(data_bytes, &project_data)
	if err != nil {
		return fmt.Sprintf("{ \"Success\": false, \"Message\": \"%s\" }", err)
	}
	for _, task_data := range project_data.Tasks {
		brief := task.GetTaskBrief(filepath.Join(g.Conf.TaskDir, task_data.Name+".json"))
		list.Tasks = append(list.Tasks, brief)
	}
	if err == nil {
		list.Success = true
		response, err = json.MarshalIndent(list, "", "  ")
		if err == nil {
			return string(response)
		}
	}
	return fmt.Sprintf("{ \"Success\": false, \"Message\": \"%q\" }", err)
}
コード例 #3
0
ファイル: tasks.go プロジェクト: automateship/goaut
func (g *GoautSession) GetAllTasks() string {
	var response []byte
	var err error
	var list TaskBriefList
	files, _ := ioutil.ReadDir(g.Conf.TaskDir)
	for _, f := range files {
		if utils.ExtFromFile(f.Name()) == ".json" {
			brief := task.GetTaskBrief(filepath.Join(g.Conf.TaskDir, f.Name()))
			list.Tasks = append(list.Tasks, brief)
		}
	}
	if err == nil {
		list.Success = true
		response, err = json.MarshalIndent(list, "", "  ")
		if err == nil {
			return string(response)
		}
	}
	return fmt.Sprintf("{ \"Success\": false, \"Message\": \"%q\" }", err)
}