gob fetcher for wasm example

This commit is contained in:
2026-07-13 02:24:06 -04:00
parent b02df48a66
commit 93e36c9abc
13 changed files with 339 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
package httputil
import (
"encoding/gob"
"encoding/json"
"net/http"
)
@@ -11,6 +12,12 @@ func RespondJSON(w http.ResponseWriter, statusCode int, data any) {
json.NewEncoder(w).Encode(data)
}
func RespondGob(w http.ResponseWriter, statusCode int, data any) {
w.Header().Set("Content-Type", "application/gob")
w.WriteHeader(statusCode)
gob.NewEncoder(w).Encode(data)
}
func RespondError(w http.ResponseWriter, statusCode int, message string) {
RespondJSON(w, statusCode, map[string]string{"error": message})
}