package protocol import ( "encoding/json" "io" ) type Success struct { OK bool `json:"ok"` Command string `json:"command"` Data map[string]any `json:"data,omitempty"` } type Error struct { OK bool `json:"ok"` Error ErrorPayload `json:"error"` } type ErrorPayload struct { Code string `json:"code"` Message string `json:"message"` } func WriteJSON(w io.Writer, v any) error { enc := json.NewEncoder(w) enc.SetIndent("", " ") return enc.Encode(v) }