refactor(monorepo): extract coord-core

This commit is contained in:
2026-03-20 13:01:16 +08:00
parent 3cf7a15626
commit 1938eb8f07
65 changed files with 6586 additions and 85 deletions
+33
View File
@@ -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)
}
+28
View File
@@ -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)
}