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 (
3030)
3131
3232type message struct {
33- id string
34- deadline int64
35- data []byte
33+ id string
34+ deadline int64
35+ data []byte
36+ statusCode int
3637}
3738
3839type responseWrapper struct {
@@ -114,8 +115,8 @@ func newTask(w http.ResponseWriter, r *http.Request) {
114115 w .WriteHeader (http .StatusGone )
115116 w .Write ([]byte (fmt .Sprintf ("Deadline is reached, data %s" , task .data )))
116117 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 )
119120 w .Write (result .data )
120121 }
121122 mutex .Lock ()
@@ -182,18 +183,21 @@ func responseHandler(w http.ResponseWriter, r *http.Request) {
182183 return
183184 }
184185
186+ statusCode := 200
187+
185188 switch kind {
186189 case "response" :
187190 case "error" :
188- fmt . Printf ( "! Error: %s \n " , data )
191+ statusCode = 500
189192 default :
190193 w .WriteHeader (http .StatusNotFound )
191194 w .Write ([]byte (fmt .Sprintf ("Unknown endpoint: %s" , kind )))
192195 return
193196 }
194197 resultsChannel <- message {
195- id : id ,
196- data : data ,
198+ id : id ,
199+ data : data ,
200+ statusCode : statusCode ,
197201 }
198202 w .WriteHeader (http .StatusAccepted )
199203 return
You can’t perform that action at this time.
0 commit comments