OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package prpc | 5 package prpc |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "net/http" | 9 "net/http" |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 return err | 50 return err |
51 } | 51 } |
52 | 52 |
53 c, rawErr := parseHeader(c, r.Header) | 53 c, rawErr := parseHeader(c, r.Header) |
54 if rawErr != nil { | 54 if rawErr != nil { |
55 return withStatus(rawErr, http.StatusBadRequest) | 55 return withStatus(rawErr, http.StatusBadRequest) |
56 } | 56 } |
57 | 57 |
58 res, rawErr := m.desc.Handler(m.service.impl, c, func(msg interface{}) e
rror { | 58 res, rawErr := m.desc.Handler(m.service.impl, c, func(msg interface{}) e
rror { |
59 if msg == nil { | 59 if msg == nil { |
60 » » » panicf("cannot decode to nil") | 60 » » » panicf("msg is nil") |
61 } | 61 } |
62 // Do not collapse it to one line. There is implicit err type co
nversion. | 62 // Do not collapse it to one line. There is implicit err type co
nversion. |
63 if err := readMessage(r, msg.(proto.Message)); err != nil { | 63 if err := readMessage(r, msg.(proto.Message)); err != nil { |
64 return err | 64 return err |
65 } | 65 } |
66 return nil | 66 return nil |
67 }) | 67 }) |
68 if rawErr != nil { | 68 if rawErr != nil { |
69 if err, ok := rawErr.(*httpError); ok { | 69 if err, ok := rawErr.(*httpError); ok { |
70 return err | 70 return err |
(...skipping 12 matching lines...) Expand all Loading... |
83 // InstallHandlers installs a POST HTTP handlers at /prpc/{service_name}/{method
_name}. | 83 // InstallHandlers installs a POST HTTP handlers at /prpc/{service_name}/{method
_name}. |
84 func (m *method) InstallHandlers(r *httprouter.Router, base middleware.Base) { | 84 func (m *method) InstallHandlers(r *httprouter.Router, base middleware.Base) { |
85 path := fmt.Sprintf("/prpc/%s/%s", m.service.Name(), m.Name()) | 85 path := fmt.Sprintf("/prpc/%s/%s", m.service.Name(), m.Name()) |
86 r.POST(path, base(m.Handle)) | 86 r.POST(path, base(m.Handle)) |
87 } | 87 } |
88 | 88 |
89 func (m *method) internalServerError(format string, a ...interface{}) *httpError
{ | 89 func (m *method) internalServerError(format string, a ...interface{}) *httpError
{ |
90 format = fmt.Sprintf("%s.%s: ", m.service.Name(), m.Name()) + format | 90 format = fmt.Sprintf("%s.%s: ", m.service.Name(), m.Name()) + format |
91 return errorf(http.StatusInternalServerError, format, a...) | 91 return errorf(http.StatusInternalServerError, format, a...) |
92 } | 92 } |
OLD | NEW |