
Веб-разработка
- 1 ответ
- 0 вопросов
1
Вклад в тег
package main
import (
"encoding/json"
"net/http"
)
func main() {
http.HandleFunc("/api/data", func(w http.ResponseWriter, r *http.Request) {
data := struct {
Message string `json:"message"`
}{
Message: "Привет, мир!",
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
http.ListenAndServe(":3001", nil)
}