lib/events: Fix unmarshaling of EventType

skip-check: authors

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4540
This commit is contained in:
Thomas Hipp
2017-11-22 23:25:55 +00:00
committed by Audrius Butkevicius
parent 67c39b2512
commit b2af8f135b
2 changed files with 31 additions and 0 deletions

View File

@@ -8,6 +8,7 @@
package events
import (
"encoding/json"
"errors"
"runtime"
"time"
@@ -118,6 +119,18 @@ func (t EventType) MarshalText() ([]byte, error) {
return []byte(t.String()), nil
}
func (t *EventType) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
*t = UnmarshalEventType(s)
return nil
}
func UnmarshalEventType(s string) EventType {
switch s {
case "Starting":