This repository was archived by the owner on Dec 11, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -30,9 +30,10 @@ import (
30
30
)
31
31
32
32
type message struct {
33
- id string
34
- deadline int64
35
- data []byte
33
+ id string
34
+ deadline int64
35
+ data []byte
36
+ statusCode int
36
37
}
37
38
38
39
type responseWrapper struct {
@@ -114,8 +115,8 @@ func newTask(w http.ResponseWriter, r *http.Request) {
114
115
w .WriteHeader (http .StatusGone )
115
116
w .Write ([]byte (fmt .Sprintf ("Deadline is reached, data %s" , task .data )))
116
117
case result := <- resultsChannel :
117
- fmt .Printf ("-> %s %s\n " , result .id , result .data )
118
- w .WriteHeader (http . StatusOK )
118
+ fmt .Printf ("-> %s %d % s\n " , result .id , result . statusCode , result .data )
119
+ w .WriteHeader (result . statusCode )
119
120
w .Write (result .data )
120
121
}
121
122
mutex .Lock ()
@@ -182,18 +183,21 @@ func responseHandler(w http.ResponseWriter, r *http.Request) {
182
183
return
183
184
}
184
185
186
+ statusCode := 200
187
+
185
188
switch kind {
186
189
case "response" :
187
190
case "error" :
188
- fmt . Printf ( "! Error: %s \n " , data )
191
+ statusCode = 500
189
192
default :
190
193
w .WriteHeader (http .StatusNotFound )
191
194
w .Write ([]byte (fmt .Sprintf ("Unknown endpoint: %s" , kind )))
192
195
return
193
196
}
194
197
resultsChannel <- message {
195
- id : id ,
196
- data : data ,
198
+ id : id ,
199
+ data : data ,
200
+ statusCode : statusCode ,
197
201
}
198
202
w .WriteHeader (http .StatusAccepted )
199
203
return
You can’t perform that action at this time.
0 commit comments