The new logbot, not committed from the wrong terminal window this time.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package models
import ( "encoding/json" "errors" "time" )
// A Change is a change in the timeline.
type Change struct { ID string `json:"id"` Model string `json:"model"` Op string `json:"op"` Author string `json:"author"` Date time.Time `json:"date"` Objects []ChangeObject `json:"objects"` }
// A ChangeObject is an object affected by the change.
type ChangeObject struct { Data json.RawMessage `json:"-"` TypeName string `json:"__typename"` }
// Channel parses the ChangeObject as a channel.
func (co *ChangeObject) Channel() (Channel, error) { if co.TypeName != "Channel" { return Channel{}, errors.New("Incorrect Type Name") }
channel := Channel{} err := json.Unmarshal(co.Data, &channel)
return channel, err }
// UnmarshalJSON implements json.Unmarshaller
func (co *ChangeObject) UnmarshalJSON(b []byte) error { data := make([]byte, len(b)) copy(data, b) co.Data = data
err := json.Unmarshal(data, co) if err != nil { return err }
return nil }
|