Skip to content

Commit

Permalink
metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
LovroG05 committed Jul 25, 2022
1 parent fb157e9 commit ecab4b2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
10 changes: 8 additions & 2 deletions example-1.0.ottf
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"version": "1.0",
"metadata": {
"version": "1.0",
"timezone": "UTC",
"author": "Doc Author",
"timestamp": 123456
},
"cues": {
"periods": {
"1": {
Expand Down Expand Up @@ -144,4 +149,5 @@
]
}
}
}
}

8 changes: 5 additions & 3 deletions gottf.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ import (
)

func getVersionFromString(s string) string {
var result parsers.TimetableVersion
var result map[string]interface{}
err := json.Unmarshal([]byte(s), &result)
if err != nil {
return ""
}
return result.Version

meta := result["metadata"].(map[string]interface{})

return meta["version"].(string)
}

func ParseTimetable(s string) (parsers.Timetable, error) {
version := getVersionFromString(s)

result := parsers.Timetable{}
var err error

Expand Down
8 changes: 8 additions & 0 deletions objects/Metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package objects

type Metadata struct {
Version string `json:"version"`
Timezone string `json:"timezone"`
Author string `json:"author"`
Timestamp uint64 `json:"timestamp"`
}
6 changes: 1 addition & 5 deletions parsers/timetable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package parsers
import "github.com/OpenTimetable/GOTTF/objects"

type Timetable struct {
Version string `json:"version"`
Metadata objects.Metadata `json:"metadata"`
Cues objects.Cues `json:"cues"`
Days map[string]objects.Day `json:"days"`
}

type TimetableVersion struct {
Version string `json:"version"`
}

0 comments on commit ecab4b2

Please sign in to comment.