Пример #1
0
Файл: api.go Проект: wuxu92/snp
func (ctl *ApiController) Get() {
	model := ctl.Ctx.Input.Param(":model")
	action := ctl.Ctx.Input.Param(":action")
	id := ctl.Ctx.Input.Param(":id")
	fmt.Println("model:", model, " action: ", action, "id: ", id)

	if strings.Compare(model, "pkg") == 0 &&
		strings.Compare(action, "get") == 0 {

		if id == "" {
			id = "default"
		}
		fmt.Println("getting pkg:", id)
		ctl.Data["json"] = models.GetPkgFullInfo(id)
		ctl.Ctx.ResponseWriter.Header().Set("Content-Type", "application/json; charset=utf8")
		ctl.ServeJSON()
	} else {
		ctl.ServeJSON()
	}
}
Пример #2
0
Файл: pkg.go Проект: wuxu92/snp
func (this *PkgController) Get() {
	action := this.Ctx.Input.Param(":action")
	id := this.Ctx.Input.Param(":id")
	utils.GetLogger().Info("model: pkg, action: %s, id: %s", action, id)

	data := ResObj{}
	switch action {
	case "get":
		if id == "d" {
			id = "default"
		}
		utils.GetConsole().Info("-getting pkg: %s", id)
		data.code = 0
		data.message = ""
		data.data = models.GetPkgFullInfo(id)
		this.Data["json"] = data.Json()
	case "new":
	case "fork":
		utils.GetConsole().Info("forking; %s", id)
		if id == "" {
			this.Data["json"] = false
		} else {
			name := this.GetString("name", "pkg-"+time.Now().Format(time.Stamp))
			pkg, err := forkPkg(id, name)
			if err != nil {
				data.code = -1
				data.message = err.Error()
			} else {
				data.code = 0
				data.message = pkg.Name
			}
		}
	}
	this.Ctx.ResponseWriter.Header().Set("Content-Type", "application/json; charset=utf8")
	this.ServeJSON()
}