mtgbot/modules/schema/schema.go

45 lines
733 B
Go
Raw Normal View History

2018-12-24 09:34:24 +00:00
package schema
import (
"encoding/json"
"errors"
"fmt"
)
// DBVersion -
type DBVersion struct {
Versions []VersionInfo `json:"versions"`
Test []VersionInfo `json:"test"`
}
// VersionInfo -
type VersionInfo struct {
File string `json:"file"`
Version int `json:"version"`
}
// ReadVersions -
func ReadVersions() (dbver DBVersion, err error) {
f, err := Asset("schema/dbVersion.db")
if err != nil {
return dbver, err
}
err = json.Unmarshal(f, &dbver)
return
}
// ReadSchema -
func ReadSchema(name string) (q string, err error) {
if len(name) == 0 {
return "", errors.New("name is empty")
}
f, err := Asset(fmt.Sprintf("schema/%s", name))
if err != nil {
return "", err
}
q = string(f)
return
}