Показать сообщение отдельно

  #1  
Старый 02.11.2024, 12:55
chapo
Флудер
Регистрация: 10.10.2016
Сообщений: 9,228
С нами: 5046982

Репутация: 183


По умолчанию

Хай. Есть структура

Код:





Код:
type Item struct {
    Name      string     `json:"name"`
    Author    string     `json:"author"`
    SecretKey string     `json:"secretKey"`
    Model     uint16     `json:"model"`
    Bone      uint8      `json:"bone"`
    Position  [3]float64 `json:"position"`
    Rotation  [3]float64 `json:"rotation"`
    Scale     [3]float64 `json:"scale"`
}


так же есть

Go:





Код:
var items []Item


Сервер отправляет items в JSON формате. Как при отправке ответа удалить/изменить все поля "SecretKey" в срезе?

Код:





Код:
func listRequestHandler(w http.ResponseWriter, r *http.Request) {
    if r.Method != "GET" {
        w.WriteHeader(http.StatusMethodNotAllowed)
        return
    }
    jsonString, err := json.Marshal(items)
    if err != nil {
        w.WriteHeader(http.StatusInternalServerError)
        w.Write([]byte(err.Error()))
        return
    }
    w.WriteHeader(http.StatusOK)
    w.Write([]byte(string(jsonString)))
}
 
Ответить с цитированием