mirror of
https://github.com/TECHNOFAB11/docsonnet.git
synced 2025-12-13 23:03:59 +01:00
feat: jsonnet interface
This commit is contained in:
parent
5977373772
commit
a63ddd1061
5 changed files with 166 additions and 83 deletions
24
main.go
24
main.go
|
|
@ -13,7 +13,7 @@ type Doc struct {
|
|||
Import string `json:"import"`
|
||||
Help string `json:"help"`
|
||||
|
||||
API Object `json:"api"`
|
||||
API Fields `json:"api"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
@ -78,6 +78,28 @@ type Field struct {
|
|||
Value *Value `json:"value,omitempty"`
|
||||
}
|
||||
|
||||
func (o *Field) UnmarshalJSON(data []byte) error {
|
||||
type fake Field
|
||||
|
||||
var f fake
|
||||
if err := json.Unmarshal(data, &f); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch {
|
||||
case f.Function != nil:
|
||||
o.Function = f.Function
|
||||
case f.Object != nil:
|
||||
o.Object = f.Object
|
||||
case f.Value != nil:
|
||||
o.Value = f.Value
|
||||
default:
|
||||
return errors.New("field has no value")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o Field) MarshalJSON() ([]byte, error) {
|
||||
if o.Function == nil && o.Object == nil && o.Value == nil {
|
||||
return nil, errors.New("field has no value")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue