• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang json.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/bborbe/http_handler/json.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了New函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	content, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return err
	}
	glog.V(2).Infof("date create: %s", string(content))
	var f booking_date.Date
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	if len(f.UserIds) == 0 {
		return fmt.Errorf("at least one user required")
	}
	obj, err := h.create(&f)
	if err != nil {
		return err
	}
	err = h.updateDateUser(obj.Id, f.UserIds)
	if err != nil {
		return err
	}
	go h.protocol(request, "date/create", obj)
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:27,代码来源:booking_date_handler_create_with_user.go


示例2: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	content, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return err
	}
	glog.V(2).Infof("shooting book: %s", string(content))
	var f booking_shooting.Shooting
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	if len(f.UserIds) == 0 {
		return fmt.Errorf("at least one user required")
	}
	obj, err := h.update(&f)
	if err != nil {
		return err
	}
	glog.V(2).Infof("update users %v of shooting %d", f.UserIds, obj.Id)
	err = h.updateShootingUser(obj.Id, f.UserIds)
	if err != nil {
		return err
	}
	go h.protocol(request, "shooting/update", obj)
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:28,代码来源:booking_shooting_handler_update.go


示例3: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	err := request.ParseForm()
	if err != nil {
		return err
	}
	values := request.Form["Id"]
	if len(values) != 1 {
		return fmt.Errorf("param Id missing")
	}
	dateId, err := strconv.Atoi(values[0])
	if err != nil {
		return err
	}
	glog.V(2).Infof("get date with user %d", dateId)
	obj, err := h.getDate(int64(dateId))
	if err != nil {
		return err
	}
	userIds, err := h.getUserIdsForDate(int64(dateId))
	if err != nil {
		return err
	}
	if len(userIds) > 0 {
		obj.UserIds = userIds
	}
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:29,代码来源:booking_date_handler_get_with_user.go


示例4: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	glog.V(2).Infof("get model")
	authentication, err := h.httpRequestToAuthentication(request)
	if err != nil {
		return err
	}
	var model *booking_model.Model
	if h.isParticipant(authentication) {
		model, err = h.getByToken(authentication.Token)
		if err != nil {
			return err
		}
	} else {
		id, err := server_idparser.ParseIdFormRequest(request)
		if err != nil {
			return err
		}
		model, err = h.get(int64(id))
		if err != nil {
			return err
		}
	}
	j := json_handler.New(model)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:26,代码来源:booking_model_handler_get.go


示例5: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	authentication, err := h.httpRequestToAuthentication(request)
	if err != nil {
		return err
	}
	var list []booking_shooting.Shooting
	if h.isParticipant(authentication) {
		glog.V(2).Infof("isParticipant = true")
		model, err := h.getByToken(authentication.Token)
		if err != nil {
			return err
		}
		if list, err = h.findByModelId(model.Id); err != nil {
			glog.V(2).Infof("list shootings failed: %v", err)
			return err
		}
	} else {
		glog.V(2).Infof("isParticipant = false")
		if list, err = h.list(); err != nil {
			glog.V(2).Infof("list shootings failed: %v", err)
			return err
		}
	}
	glog.V(2).Infof("found %d shootings", len(list))
	j := json_handler.New(list)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:28,代码来源:booking_shooting_handler_list.go


示例6: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	err := request.ParseForm()
	if err != nil {
		return err
	}
	values := request.Form["Id"]
	if len(values) != 1 {
		return fmt.Errorf("param Id missing")
	}
	id, err := strconv.Atoi(values[0])
	if err != nil {
		return err
	}
	glog.V(2).Infof("get shooting with users for id: %d", id)
	obj, err := h.get(int64(id))
	if err != nil {
		return err
	}
	userIds, err := h.getUserIdForShooting(int64(id))
	if err != nil {
		return err
	}
	obj.UserIds = userIds
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:27,代码来源:booking_shooting_handler_get.go


示例7: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	glog.V(2).Infof("list config")
	var err error
	var list []booking_config.Config
	if list, err = h.list(); err != nil {
		glog.V(2).Infof("list configs failed: %v", err)
		return err
	}
	glog.V(2).Infof("found %d configs", len(list))
	j := json_handler.New(list)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:13,代码来源:booking_config_handler_list.go


示例8: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	glog.V(2).Infof("get current model")
	authentication, err := h.httpRequestToAuthentication(request)
	if err != nil {
		return err
	}
	obj, err := h.getByToken(authentication.Token)
	if err != nil {
		return err
	}
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:14,代码来源:booking_model_handler_current.go


示例9: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	id, err := server_idparser.ParseIdFormRequest(request)
	if err != nil {
		return err
	}
	obj, err := h.delete(int64(id))
	if err != nil {
		return err
	}
	go h.protocol(request, "shooting/delete", obj)
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:14,代码来源:booking_shooting_handler_delete.go


示例10: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	glog.V(2).Infof("get config")
	key, err := server_idparser.ParseKeyFormRequest(request)
	if err != nil {
		return err
	}
	glog.V(2).Infof("get config %s", key)
	obj, err := h.get(key)
	if err != nil {
		return err
	}
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:15,代码来源:booking_config_handler_get.go


示例11: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	glog.V(2).Infof("delete config")
	key, err := server_idparser.ParseKeyFormRequest(request)
	if err != nil {
		return err
	}
	obj, err := h.delete(key)
	if err != nil {
		return err
	}
	go h.protocol(request, "config/delete", obj)
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:15,代码来源:booking_config_handler_delete.go


示例12: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	glog.V(2).Infof("list user")
	var err error
	var list []booking_user.User
	if list, err = h.list(); err != nil {
		glog.V(2).Infof("list users failed: %v", err)
		return err
	}

	list = removePassword(list)

	glog.V(2).Infof("found %d users", len(list))
	j := json_handler.New(list)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:16,代码来源:booking_user_handler_list.go


示例13: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	var err error
	var list []booking_model.Model
	glog.V(2).Infof("model list")
	err = request.ParseForm()
	if err != nil {
		return err
	}
	if list, err = h.list(); err != nil {
		glog.V(2).Infof("list models failed: %v", err)
		return err
	}
	glog.V(2).Infof("found %d models", len(list))
	j := json_handler.New(list)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:17,代码来源:booking_model_handler_list.go


示例14: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	content, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return err
	}
	glog.V(2).Infof("verifylogin authentication: %v", string(content))
	var f booking_authentication.Authentication
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	obj, err := h.verifyLogin(&f)
	if err != nil {
		return err
	}
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:19,代码来源:booking_authentication_handler_verifylogin.go


示例15: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	content, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return err
	}
	glog.V(2).Infof("model update: %s", string(content))
	var f booking_model.Model
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	obj, err := h.update(&f)
	if err != nil {
		return err
	}
	go h.protocol(request, "model/update", obj)
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:20,代码来源:booking_model_handler_update.go


示例16: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	shootingId, err := server_idparser.ParseIdFormRequest(request)
	if err != nil {
		return err
	}
	var list []booking_user.User
	glog.V(2).Infof("user list")
	err = request.ParseForm()
	if err != nil {
		return err
	}
	if list, err = h.listUserOfShooting(int64(shootingId)); err != nil {
		glog.V(2).Infof("list users failed: %v", err)
		return err
	}
	glog.V(2).Infof("found %d users for shooting %d", len(list), shootingId)
	j := json_handler.New(list)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:20,代码来源:booking_list_user_of_shooting_handler.go


示例17: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	content, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return err
	}
	glog.V(2).Infof("add user to shooting %s", string(content))
	var f booking_shooting_user.ShootingUser
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	obj, err := h.addUserToShooting(&f)
	if err != nil {
		return err
	}
	go h.protocol(request, "add_user_to_shooting", obj)
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:20,代码来源:booking_add_user_to_shooting_handler.go


示例18: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	content, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return err
	}
	glog.V(2).Infof("remove user from date %s", string(content))
	var f booking_date_user.DateUser
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	obj, err := h.removeUserToDate(&f)
	if err != nil {
		return err
	}
	go h.protocol(request, "remove_user_from_date", obj)
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:20,代码来源:booking_remove_user_from_date_handler.go


示例19: ServeHTTP

func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	authentication, err := h.httpRequestToAuthentication(request)
	if err != nil {
		return err
	}
	model, err := h.getByToken(authentication.Token)
	if err != nil {
		return err
	}
	content, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return err
	}
	glog.V(2).Infof("shooting book: %s", string(content))
	var f booking_shooting.Shooting
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	if h.isParticipant(authentication) {
		shooting, err := h.get(f.Id)
		if err != nil {
			return err
		}
		if shooting.ModelId.Valid && shooting.ModelId.Int64 != model.Id {
			glog.V(2).Infof("permission %d != %d", f.ModelId, model.Id)
			return fmt.Errorf("permission denied")
		}
	}
	obj, err := h.update(&f)
	if err != nil {
		return err
	}
	go h.protocol(request, "shooting/book", obj)
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
开发者ID:bborbe,项目名称:booking,代码行数:38,代码来源:booking_shooting_handler_book.go



注:本文中的github.com/bborbe/http_handler/json.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang testutils.Get函数代码示例发布时间:2022-05-24
下一篇:
Golang requestbuilder.NewHTTPRequestBuilderProvider函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap