refactor(monorepo): extract coord-core
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package protocol
|
||||
|
||||
type CLIError struct {
|
||||
Code string
|
||||
ExitCode int
|
||||
Message string
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *CLIError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
func (e *CLIError) Unwrap() error {
|
||||
return e.Err
|
||||
}
|
||||
|
||||
func NewCLIError(code string, exitCode int, message string, err error) error {
|
||||
return &CLIError{
|
||||
Code: code,
|
||||
ExitCode: exitCode,
|
||||
Message: message,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
|
||||
func InvalidInput(message string, err error) error {
|
||||
return NewCLIError("invalid_input", 30, message, err)
|
||||
}
|
||||
|
||||
func NoMatchingWork(message string) error {
|
||||
return NewCLIError("no_matching_work", 10, message, nil)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user