本文整理匯總了Golang中github.com/bborbe/http_handler/json.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}