48 lines
642 B
Go
48 lines
642 B
Go
package workspace
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
type MetaType int
|
|
|
|
const (
|
|
TypeFile = iota
|
|
TypeRedirect
|
|
)
|
|
|
|
type Meta struct {
|
|
id string
|
|
Type MetaType `json:"type"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
func (m Meta) ID() string {
|
|
return m.id
|
|
}
|
|
|
|
func (m Meta) MarshalJSON() ([]byte, error) {
|
|
type meta Meta
|
|
return json.Marshal(struct {
|
|
ID string `json:"id"`
|
|
meta
|
|
}{
|
|
ID: m.ID(),
|
|
meta: meta(m),
|
|
})
|
|
}
|
|
|
|
func (m *Meta) UnmarshalJSON(data []byte) error {
|
|
type meta Meta
|
|
s := struct {
|
|
ID string `json:"id"`
|
|
meta
|
|
}{}
|
|
if err := json.Unmarshal(data, &s); err != nil {
|
|
return err
|
|
}
|
|
*m = Meta(s.meta)
|
|
m.id = s.ID
|
|
return nil
|
|
}
|