Mercurial > gemma
annotate pkg/controllers/json.go @ 792:ce23a4192788
Removed dead code.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 27 Sep 2018 09:55:25 +0200 |
parents | 8bb2e48e2dfd |
children | 7934b5c1a910 |
rev | line source |
---|---|
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package controllers |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import ( |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 "database/sql" |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 "encoding/json" |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 "fmt" |
739
b800eb2a0846
JSON handler: if result is an io.Reader copyit through.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
536
diff
changeset
|
7 "io" |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 "log" |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 "net/http" |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
241
3b688fe04c39
No omitempty if JSON serialising PostgreSQL errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
240
diff
changeset
|
11 "github.com/jackc/pgx" |
3b688fe04c39
No omitempty if JSON serialising PostgreSQL errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
240
diff
changeset
|
12 |
414
c1047fd04a3a
Moved project specific Go packages to new pkg folder.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
341
diff
changeset
|
13 "gemma.intevation.de/gemma/pkg/auth" |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 ) |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 type JSONResult struct { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 Code int |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 Result interface{} |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 } |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 type JSONHandler struct { |
239
713234a04a87
Renamed JSONHandler.Process to JSONHandler.Handler as it sounds more symmetrical.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
238
diff
changeset
|
22 Input func() interface{} |
486
b2dc9c2f69e0
First stab to use the metamorphic db to do all database stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
414
diff
changeset
|
23 Handle func(interface{}, *http.Request, *sql.Conn) (JSONResult, error) |
b2dc9c2f69e0
First stab to use the metamorphic db to do all database stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
414
diff
changeset
|
24 NoConn bool |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 } |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 type JSONError struct { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 Code int |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 Message string |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 } |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 func (je JSONError) Error() string { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 return fmt.Sprintf("%d: %s", je.Code, je.Message) |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 } |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 func (j *JSONHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 var input interface{} |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 if j.Input != nil { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 input = j.Input() |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 defer req.Body.Close() |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 if err := json.NewDecoder(req.Body).Decode(input); err != nil { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 http.Error(rw, "error: "+err.Error(), http.StatusBadRequest) |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 return |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 } |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 } |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 var jr JSONResult |
302
0777aa6de45b
Password reset. Part I
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
257
diff
changeset
|
49 var err error |
0777aa6de45b
Password reset. Part I
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
257
diff
changeset
|
50 |
486
b2dc9c2f69e0
First stab to use the metamorphic db to do all database stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
414
diff
changeset
|
51 if token, ok := auth.GetToken(req); ok && !j.NoConn { |
498
22e1bf563a04
Throw away the connection level for sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
493
diff
changeset
|
52 if session := auth.Sessions.Session(token); session != nil { |
514
4a1db55a9920
Use auth.RunAs in JSON controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
508
diff
changeset
|
53 err = auth.RunAs(session.User, req.Context(), func(conn *sql.Conn) error { |
486
b2dc9c2f69e0
First stab to use the metamorphic db to do all database stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
414
diff
changeset
|
54 jr, err = j.Handle(input, req, conn) |
514
4a1db55a9920
Use auth.RunAs in JSON controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
508
diff
changeset
|
55 return err |
4a1db55a9920
Use auth.RunAs in JSON controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
508
diff
changeset
|
56 }) |
498
22e1bf563a04
Throw away the connection level for sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
493
diff
changeset
|
57 } else { |
22e1bf563a04
Throw away the connection level for sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
493
diff
changeset
|
58 err = auth.ErrNoSuchToken |
486
b2dc9c2f69e0
First stab to use the metamorphic db to do all database stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
414
diff
changeset
|
59 } |
302
0777aa6de45b
Password reset. Part I
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
257
diff
changeset
|
60 } else { |
0777aa6de45b
Password reset. Part I
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
257
diff
changeset
|
61 jr, err = j.Handle(input, req, nil) |
0777aa6de45b
Password reset. Part I
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
257
diff
changeset
|
62 } |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 if err != nil { |
536
d9dbb6139760
Log errors in JSON handler and login controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
65 log.Printf("error: %v\n", err) |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 switch e := err.(type) { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 case pgx.PgError: |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 var res = struct { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 Result string `json:"result"` |
241
3b688fe04c39
No omitempty if JSON serialising PostgreSQL errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
240
diff
changeset
|
70 Code string `json:"code"` |
3b688fe04c39
No omitempty if JSON serialising PostgreSQL errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
240
diff
changeset
|
71 Message string `json:"message"` |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 }{ |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 Result: "failure", |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 Code: e.Code, |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 Message: e.Message, |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 } |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 rw.Header().Set("Content-Type", "application/json") |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 rw.WriteHeader(http.StatusInternalServerError) |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 if err := json.NewEncoder(rw).Encode(&res); err != nil { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 log.Printf("error: %v\n", err) |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 } |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 case JSONError: |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 rw.Header().Set("Content-Type", "application/json") |
341
889517f254f5
Use code of JSONError as HTTP code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
302
diff
changeset
|
84 if e.Code == 0 { |
889517f254f5
Use code of JSONError as HTTP code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
302
diff
changeset
|
85 e.Code = http.StatusInternalServerError |
889517f254f5
Use code of JSONError as HTTP code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
302
diff
changeset
|
86 } |
889517f254f5
Use code of JSONError as HTTP code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
302
diff
changeset
|
87 rw.WriteHeader(e.Code) |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 var res = struct { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 Message string `json:"message"` |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 }{ |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 Message: e.Message, |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 } |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 if err := json.NewEncoder(rw).Encode(&res); err != nil { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 log.Printf("error: %v\n", err) |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 } |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 default: |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 http.Error(rw, |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 "error: "+err.Error(), |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 http.StatusInternalServerError) |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 } |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 return |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 } |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 |
238
2b39bf2bf1fd
If no error code was given in a JSONResult assume Status OK (200).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
104 if jr.Code == 0 { |
2b39bf2bf1fd
If no error code was given in a JSONResult assume Status OK (200).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
105 jr.Code = http.StatusOK |
2b39bf2bf1fd
If no error code was given in a JSONResult assume Status OK (200).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
106 } |
2b39bf2bf1fd
If no error code was given in a JSONResult assume Status OK (200).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
107 |
240
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
239
diff
changeset
|
108 if jr.Code != http.StatusNoContent { |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
239
diff
changeset
|
109 rw.Header().Set("Content-Type", "application/json") |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
239
diff
changeset
|
110 } |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 rw.WriteHeader(jr.Code) |
240
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
239
diff
changeset
|
112 if jr.Code != http.StatusNoContent { |
739
b800eb2a0846
JSON handler: if result is an io.Reader copyit through.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
536
diff
changeset
|
113 var err error |
741
8bb2e48e2dfd
Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
739
diff
changeset
|
114 if r, ok := jr.Result.(io.Reader); ok { |
739
b800eb2a0846
JSON handler: if result is an io.Reader copyit through.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
536
diff
changeset
|
115 _, err = io.Copy(rw, r) |
b800eb2a0846
JSON handler: if result is an io.Reader copyit through.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
536
diff
changeset
|
116 } else { |
b800eb2a0846
JSON handler: if result is an io.Reader copyit through.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
536
diff
changeset
|
117 err = json.NewEncoder(rw).Encode(jr.Result) |
b800eb2a0846
JSON handler: if result is an io.Reader copyit through.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
536
diff
changeset
|
118 } |
b800eb2a0846
JSON handler: if result is an io.Reader copyit through.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
536
diff
changeset
|
119 if err != nil { |
240
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
239
diff
changeset
|
120 log.Printf("error: %v\n", err) |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
239
diff
changeset
|
121 } |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 } |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 } |