https://github.com/ttab/darknut
Darknut can be used to unmarshal a NewsDoc into a specialised struct.
https://github.com/ttab/darknut
Last synced: about 1 month ago
JSON representation
Darknut can be used to unmarshal a NewsDoc into a specialised struct.
- Host: GitHub
- URL: https://github.com/ttab/darknut
- Owner: ttab
- License: mit
- Created: 2023-08-21T12:58:52.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-08T14:39:33.000Z (about 2 years ago)
- Last Synced: 2024-04-14T09:08:35.625Z (about 2 years ago)
- Language: Go
- Size: 324 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Darknut
[][godev]
[][actions]
Darknut can be used to unmarshal a NewsDoc into a specialised struct. Mostly useful for getting strict typing of data attributes and flattening the data structure.
Slices of blocks and fields that are pointers will be treated as optional, all others will result in an error. External types, like UUIDs, are supported through [TextUnmarshaler](https://pkg.go.dev/encoding#TextUnmarshaler).
``` go
type planningItem struct {
UUID uuid.UUID `newsdoc:"uuid"`
Title string `newsdoc:"title"`
Meta planningItemBlock `newsdoc:"meta,type=core/planning-item"`
InternalDescription *descriptionBlock `newsdoc:"meta,type=core/description,role=internal"`
PublicDescription *descriptionBlock `newsdoc:"meta,type=core/description,role=public"`
Assignments []assignmentBlock `newsdoc:"meta,type=core/assignment"`
}
type descriptionBlock struct {
Role string `newsdoc:"role"`
Text string `newsdoc:"data.text"`
}
type planningItemBlock struct {
Date *time.Time `newsdoc:"data.date,format=2006-01-02"`
Publish time.Time `newsdoc:"data.publish"`
PublishSlot *int `newsdoc:"data.publish_slot"`
Public bool `newsdoc:"data.public"`
Tentative bool `newsdoc:"data.tentative"`
Urgency int `newsdoc:"data.urgency"`
}
type assignmentBlock struct {
Starts time.Time `newsdoc:"data.starts"`
Ends *time.Time `newsdoc:"data.ends"`
Status string `newsdoc:"data.status"`
FullDay bool `newsdoc:"data.full_day"`
Kind []assignmentKind `newsdoc:"meta,type=core/assignment-kind"`
Assignees []assigneeLink `newsdoc:"links,rel=assignee"`
}
type assignmentKind struct {
Value string `newsdoc:"value"`
}
type assigneeLink struct {
UUID uuid.UUID `newsdoc:"uuid"`
}
```
See the [documentation][godev] for more information.
[godev]: https://pkg.go.dev/github.com/ttab/darknut
[actions]: https://github.com/ttab/darknut/actions