Added: downloading and returning wikipedia articles
This commit is contained in:
21
api/httpio/response.go
Normal file
21
api/httpio/response.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package httpio
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ResponseIO map[string]any
|
||||
|
||||
func (r ResponseIO) Return(w http.ResponseWriter, statusCode int) error {
|
||||
jsonBytes, err := json.Marshal(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(statusCode)
|
||||
w.Write(jsonBytes)
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user