-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.go
More file actions
43 lines (36 loc) · 1.01 KB
/
format.go
File metadata and controls
43 lines (36 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package flashduty
import (
"encoding/json"
"strings"
toon "github.com/toon-format/toon-go"
)
// OutputFormat defines the serialization format for tool results
type OutputFormat string
const (
// OutputFormatJSON uses standard JSON serialization (default)
OutputFormatJSON OutputFormat = "json"
// OutputFormatTOON uses Token-Oriented Object Notation for reduced token usage
OutputFormatTOON OutputFormat = "toon"
)
// ParseOutputFormat converts a string to OutputFormat, defaulting to JSON
func ParseOutputFormat(s string) OutputFormat {
switch strings.ToLower(strings.TrimSpace(s)) {
case "toon":
return OutputFormatTOON
default:
return OutputFormatJSON
}
}
// String returns the string representation of OutputFormat
func (f OutputFormat) String() string {
return string(f)
}
// Marshal serializes the given value using the specified format
func Marshal(v any, format OutputFormat) ([]byte, error) {
switch format {
case OutputFormatTOON:
return toon.Marshal(v)
default:
return json.Marshal(v)
}
}