本文整理匯總了Golang中cms/utils.JsonMessage函數的典型用法代碼示例。如果您正苦於以下問題:Golang JsonMessage函數的具體用法?Golang JsonMessage怎麽用?Golang JsonMessage使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了JsonMessage函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Delete
/*
刪除用戶
method:post
params:ids
*/
func (this *Account) Delete() {
var data interface{}
id := this.getParamsString(":id")
//
ids := this.GetStrings("ids")
if id != "" {
ids = append(ids, id)
}
//不能自我重置
if utils.StringsContains(ids, fmt.Sprintf("%d", this.xm.Updator)) {
data = utils.JsonMessage(false, "denyOneself", this.lang("denyOneself"))
} else {
var err error
_, err = users.Delete(ids, this.xm)
if err == nil {
data = utils.JsonMessage(true, "", "")
} else {
data = utils.JsonMessage(false, "deleteFail", this.lang("deleteFail"))
}
}
this.renderJson(data)
}
示例2: Create
//新增圖片
func (this *Image) Create() {
//Get方法
if this.methodGet {
id, err := this.getParamsInt64(":id")
if err != nil {
this.errorHandle(utils.JsonMessage(false, "invalidRequestParams", this.lang("invalidRequestParams")))
return
}
this.Data["articleid"] = id
this.Data["token"] = this.token()
this.TplNames = this.getTplFileName("create")
this.Render()
return
}
//Post方法
//簽名錯誤,返回重複提交錯誤
if this.invalidToken() {
this.renderLoseToken()
return
}
//數據模型
m := new(models.Images)
models.Extend(m, this.xm)
m.Articleid, _ = this.GetInt("articleid")
m.Title = this.GetString("title")
m.Url = this.GetString("url")
if this.GetString("status") == "on" {
m.Status = 1
} else {
m.Status = 0
}
files, err := this.upload("file")
if err == nil {
m.Path = files[0].Path
m.Ext = files[0].Ext
m.Srcfilename = files[0].Name
m.Size = files[0].Size
}
//數據合法性檢驗
if data, inv := this.invalidModel(m); inv {
this.renderJson(data)
return
}
//提交DDL
var data interface{}
_, err = images.Add(m)
if err != nil {
data = utils.JsonMessage(false, "", err.Error())
} else {
data = utils.JsonResult(true, "", files)
}
this.renderJson(data)
}
示例3: Create
//新增頻道
func (this *Article) Create() {
//Get方法
if this.methodGet {
this.Data["token"] = this.token()
//所屬頻道選項
this.Data["chs"] = channels.GetChannelSelectItems(0 /*, utils.ChNews*/)
this.TplNames = this.getTplFileName("create")
this.Render()
return
}
//Post方法
//簽名錯誤,返回重複提交錯誤
if this.invalidToken() {
this.renderLoseToken()
return
}
//數據模型
m := new(models.Articles)
models.Extend(m, this.xm)
m.Channelid, _ = this.GetInt("channelid")
m.Title = this.GetString("title")
m.Subtitle = this.GetString("subtitle")
m.Intro = this.GetString("intro")
m.Content = this.GetString("content")
m.Keywords = this.GetString("keywords")
m.Description = this.GetString("description")
m.Author = this.GetString("author")
if this.GetString("status") == "on" {
m.Status = 1
} else {
m.Status = 0
}
if t, err := beego.DateParse(this.GetString("published"), "Y-n-j H:i:s"); err == nil {
m.Published = utils.Millisecond(t)
} else {
m.Published = utils.Millisecond(time.Now())
}
//數據合法性檢驗
if data, inv := this.invalidModel(m); inv {
this.renderJson(data)
return
}
//提交DDL
var data interface{}
_, err := articles.Add(m)
if err != nil {
data = utils.JsonMessage(false, "", err.Error())
} else {
data = utils.JsonMessage(true, "", "")
}
this.renderJson(data)
}
示例4: invalidModel
/*
數據對象合法性驗證
args:要檢驗的元素,長度為0,則檢驗全部元素
*/
func (this *base) invalidModel(m interface{}, args ...interface{}) (data interface{}, invalid bool) {
valid := validation.Validation{}
b, err := valid.Valid(m)
if err != nil {
data = utils.JsonMessage(false, "", err.Error())
invalid = true
return
}
if !b {
var errstr string
//檢驗元素
if n := len(args); n > 0 {
for _, err := range valid.Errors {
if utils.ListContains(args, err.Key[0:strings.Index(err.Key, ".")]) {
errstr += fmt.Sprintf("%s %s;", err.Key, err.Message)
}
}
} else {
for _, err := range valid.Errors {
errstr += fmt.Sprintf("%s %s;", err.Key, err.Message)
}
}
if errstr == "" {
invalid = false
} else {
data = utils.JsonMessage(false, "", errstr)
invalid = true
}
return
}
return
}
示例5: Edit
//修改賬戶信息
func (this *Account) Edit() {
//Get方法
if this.methodGet {
this.Data["token"] = this.token()
id, err := this.getParamsInt64(":id")
if err != nil {
this.errorHandle(utils.JsonMessage(false, "invalidRequestParams", this.lang("invalidRequestParams")))
return
}
u, err := users.Get(id)
if err != nil {
this.errorHandle(utils.JsonMessage(false, "", err.Error()))
return
}
this.Data["user"] = u
this.TplNames = this.getTplFileName("edit")
this.Render()
return
}
//Post方法
//簽名錯誤,返回重複提交錯誤
if this.invalidToken() {
this.renderLoseToken()
return
}
//數據模型
u := new(models.Users)
models.Extend(u, this.xm)
u.Id, _ = this.GetInt("id")
u.Loginname = this.GetString("loginname")
u.Relname = this.GetString("relname")
//數據合法性檢驗
// valid := validation.Validation
// valid.Required(u.Loginname, "loginname")
// valid.Required(u.Relname, "relname")
if data, inv := this.invalidModel(u, "Loginname", "Relname"); inv {
this.renderJson(data)
return
}
//提交DDL
var data interface{}
_, err := users.Update(u)
if err != nil {
data = utils.JsonMessage(false, "", err.Error())
} else {
data = utils.JsonMessage(true, "", "")
}
this.renderJson(data)
}
示例6: Create
//新增頻道
func (this *Channel) Create() {
//Get方法
if this.methodGet {
this.Data["token"] = this.token()
//所屬頻道選項
this.Data["chs"] = channels.GetChannelSelectItems(0, utils.ChNavigation)
//頻道類型
this.Data["types"] = channels.GetTypeSelectItems(0)
this.TplNames = this.getTplFileName("create")
this.Render()
return
}
//Post方法
//簽名錯誤,返回重複提交錯誤
if this.invalidToken() {
this.renderLoseToken()
return
}
//數據模型
m := new(models.Channels)
models.Extend(m, this.xm)
m.Pid, _ = this.GetInt("pid")
m.Name = this.GetString("name")
m.Enname = this.GetString("enname")
t, _ := this.GetInt("children")
m.Children = int(t)
t, _ = this.GetInt("type")
m.Type = int8(t)
if this.GetString("status") == "on" {
m.Status = 1
} else {
m.Status = 0
}
//數據合法性檢驗
if data, inv := this.invalidModel(m); inv {
this.renderJson(data)
return
}
//提交DDL
var data interface{}
_, err := channels.Add(m)
if err != nil {
data = utils.JsonMessage(false, "", err.Error())
} else {
data = utils.JsonMessage(true, "", "")
}
this.renderJson(data)
}
示例7: GetAll
//頻道列表
func (this *Article) GetAll() {
var data interface{}
//
page := new(models.Pagination)
if v, err := this.GetInt("index"); err == nil {
page.Index = int(v)
}
if v, err := this.GetInt("size"); err == nil {
page.Size = int(v)
}
//參數錯誤
if page.Index <= 0 {
page.Index = 1
}
if page.Size <= 0 {
//data = utils.JsonMessage(false, "invalidRequestParams", this.lang("invalidRequestParams"))
page.Size = 15
}
channelid, _ := this.GetInt("channelid")
//
us, err := articles.GetAll(channelid, page)
if err == nil {
data = utils.JsonResult(true, fmt.Sprintf("%d", page.Count), us)
} else {
data = utils.JsonMessage(false, "", "")
}
this.renderJson(data)
}
示例8: Reset
/*
重置圖片
method:post
params:id
*/
func (this *Image) Reset() {
var data interface{}
//
id, err := this.GetInt("id")
if err != nil {
data = utils.JsonMessage(false, "invalidRequestParams", err.Error())
} else {
//
_, err = images.Reset(id, this.xm)
if err == nil {
data = utils.JsonMessage(true, "", "")
} else {
data = utils.JsonMessage(false, "resetFail", err.Error())
}
}
this.renderJson(data)
}
示例9: Exist
/*
是否存在重名用戶
*/
func (this *Account) Exist() {
var data interface{}
name := this.GetString("loginname")
if len(name) > 0 {
if ok := users.Exist(name); ok {
data = utils.JsonMessage(true, "sameNameAccount", this.lang("sameNameAccount"))
} else {
data = utils.JsonMessage(false, "", "")
}
} else {
data = utils.JsonMessage(false, "invalidRequestParams", this.lang("invalidRequestParams"))
}
this.renderJson(data)
}
示例10: Sequence
//重新排列圖片順序
func (this *Image) Sequence() {
var data interface{}
//
id, err1 := this.GetInt("id")
sq, err2 := this.GetInt("sq")
if err1 != nil || err2 != nil {
data = utils.JsonMessage(false, "invalidRequestParams", err1.Error()+"\n"+err2.Error())
} else {
this.xm.Sequence = int(sq)
_, err := images.SetSequence(id, this.xm)
if err == nil {
data = utils.JsonMessage(true, "", "")
} else {
data = utils.JsonMessage(false, "resetFail", err.Error())
}
}
this.renderJson(data)
}
示例11: Delete
/*
刪除圖片
method:post
params:ids
*/
func (this *Image) Delete() {
var data interface{}
//
id := this.getParamsString(":id")
//
ids := this.GetStrings("ids")
if id != "" {
ids = append(ids, id)
}
_, err := images.Delete(ids, this.xm)
if err == nil {
data = utils.JsonMessage(true, "", "")
} else {
data = utils.JsonMessage(false, "deleteFail", this.lang("deleteFail"))
}
this.renderJson(data)
}
示例12: Create
//新增賬戶
func (this *Account) Create() {
//Get方法
if this.methodGet {
this.Data["token"] = this.token()
this.Data["password"] = beego.AppConfig.String("DefaultPassword")
this.TplNames = this.getTplFileName("create")
this.Render()
return
}
//Post方法
//簽名錯誤,返回重複提交錯誤
if this.invalidToken() {
this.renderLoseToken()
return
}
//數據模型
u := new(models.Users)
models.Extend(u, this.xm)
u.Loginname = this.GetString("loginname")
u.Password = this.GetString("password")
u.Relname = this.GetString("relname")
r, _ := this.GetInt("role")
u.Role = int8(r)
//數據合法性檢驗
if data, inv := this.invalidModel(u); inv {
this.renderJson(data)
return
}
//提交DDL
var data interface{}
_, err := users.Add(u)
if err != nil {
data = utils.JsonMessage(false, "", err.Error())
} else {
data = utils.JsonMessage(true, "", "")
}
this.renderJson(data)
}
示例13: GetAll
//圖片列表
func (this *Image) GetAll() {
us, err := images.GetAll()
var data interface{}
if err == nil {
data = utils.JsonResult(true, "", us)
} else {
data = utils.JsonMessage(false, "", "")
}
this.renderJson(data)
}
示例14: Reset
/*
重置用戶
method:post
params:id
*/
func (this *Account) Reset() {
var data interface{}
//
id, err := this.GetInt("id")
if err != nil {
data = utils.JsonMessage(false, "invalidRequestParams", err.Error())
} else {
//不能自我重置
if id == this.xm.Updator {
data = utils.JsonMessage(false, "denyOneself", this.lang("denyOneself"))
} else {
_, err = users.Reset(id, this.xm)
if err == nil {
data = utils.JsonMessage(true, "", "")
} else {
data = utils.JsonMessage(false, "resetFail", err.Error())
}
}
}
this.renderJson(data)
}
示例15: GetAll
//頻道列表
func (this *Channel) GetAll() {
t, err := this.GetInt("type")
if err != nil {
t = -1
}
us, err := channels.GetAll(int(t))
var data interface{}
if err == nil {
data = utils.JsonResult(true, "", us)
} else {
data = utils.JsonMessage(false, "", err.Error())
}
this.renderJson(data)
}