mirror of
https://github.com/anomalyco/opencode-sdk-go.git
synced 2026-05-18 23:53:40 +00:00
47 lines
840 B
Go
47 lines
840 B
Go
package apijson
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
)
|
|
|
|
const jsonStructTag = "json"
|
|
const formatStructTag = "format"
|
|
|
|
type parsedStructTag struct {
|
|
name string
|
|
required bool
|
|
extras bool
|
|
metadata bool
|
|
inline bool
|
|
}
|
|
|
|
func parseJSONStructTag(field reflect.StructField) (tag parsedStructTag, ok bool) {
|
|
raw, ok := field.Tag.Lookup(jsonStructTag)
|
|
if !ok {
|
|
return
|
|
}
|
|
parts := strings.Split(raw, ",")
|
|
if len(parts) == 0 {
|
|
return tag, false
|
|
}
|
|
tag.name = parts[0]
|
|
for _, part := range parts[1:] {
|
|
switch part {
|
|
case "required":
|
|
tag.required = true
|
|
case "extras":
|
|
tag.extras = true
|
|
case "metadata":
|
|
tag.metadata = true
|
|
case "inline":
|
|
tag.inline = true
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func parseFormatStructTag(field reflect.StructField) (format string, ok bool) {
|
|
format, ok = field.Tag.Lookup(formatStructTag)
|
|
return
|
|
}
|