Example #1
0
func (this *NewModelController) Post() {
	model := this.Ctx.Input.Param(":model")

	data := ResObj{}
	switch model {
	case "site":
		title := this.GetString("title")
		url := this.GetString("url")
		grp := this.GetString("grp")

		utils.GetLogger().Info("add site %s - %s to %s", title, url, grp)

		site, err := newSite(title, url, grp)
		if err == nil {
			data.code = 0

			// config data
			reSite := make(map[string]interface{})
			reSite["title"] = site.Title
			reSite["url"] = site.Url
			reSite["id"] = site.Id.Hex()
			data.data = reSite
		} else {
			data.code = 1
			data.message = err.Error()
		}
		this.Data["json"] = data.Json()
	case "grp":
	case "pkg":
	}

	this.ServeJSON()
}
Example #2
0
File: grp.go Project: wuxu92/snp
// add a site to this group
// add a site to mgo first, and then add id to
// this.sites
func (this *Group) AddSite(title, url string) (Site, error) {
	site := Site{
		bson.NewObjectId(),
		title,
		url,
		time.Now().Format(time.RFC3339),
		true,
	}
	err := utils.GetMgc().GetDB().C("site").Insert(site)
	if err != nil {
		return Site{}, err
	}
	utils.GetLogger().Info("insert site: %s", site.Id.Hex())
	this.Sites = append(this.Sites, site.Id)
	this.Update()
	return site, nil
}
Example #3
0
File: pkg.go Project: 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()
}