29 lines
505 B
Go
29 lines
505 B
Go
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)
|
|
}
|