mtgbot/modules/schema/schema.go
Jay 5c997f554b update
1. fix module schema error
2. add schema to version
2019-01-09 11:59:50 +08:00

45 lines
735 B
Go

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.json")
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
}