/
meta.go
53 lines (44 loc) · 1.06 KB
/
meta.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package theme
import (
"io/ioutil"
"github.com/BurntSushi/toml"
)
// Meta is description of theme
type Meta struct {
Name string `toml:"name"`
Repo string `toml:"repo"`
URL string `toml:"url"`
Date string `toml:"date"`
Desc string `toml:"desc"`
Tags []string `toml:"tags"`
MinVersion string `toml:"min_version"`
// Authors []*model.Author `toml:"author" ini:"-"`
Refs []*Reference `toml:"ref"`
License string `toml:"license" `
LicenseURL string `toml:"license_url"`
}
// Reference is reference of user links
type Reference struct {
Name string `toml:"name"`
URL string `toml:"url"`
Repo string `toml:"repo"`
}
// NewMeta parses bytes to theme meta
func NewMeta(data []byte) (*Meta, error) {
meta := new(Meta)
if err := toml.Unmarshal(data, meta); err != nil {
return nil, err
}
if meta.Name == "" {
return nil, nil
}
return meta, nil
}
// NewMetaFromFile parses theme meta via file
func NewMetaFromFile(file string) (*Meta, error) {
data, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
return NewMeta(data)
}