mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 12:19:38 +08:00
Make linuxdb.yaml an embedded resource
This commit is contained in:
parent
84b67a8f53
commit
451b357e40
10
cmd/fs.go
10
cmd/fs.go
@ -148,16 +148,6 @@ func (fs *FSHelper) LocalDir(dir string) (*Dir, error) {
|
|||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadRelativeFile loads the given file relative to the caller's directory
|
|
||||||
func (fs *FSHelper) LoadRelativeFile(relativePath string) ([]byte, error) {
|
|
||||||
_, filename, _, _ := runtime.Caller(0)
|
|
||||||
fullPath, err := filepath.Abs(filepath.Join(path.Dir(filename), relativePath))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return os.ReadFile(fullPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetSubdirs will return a list of FQPs to subdirectories in the given directory
|
// GetSubdirs will return a list of FQPs to subdirectories in the given directory
|
||||||
func (d *Dir) GetSubdirs() (map[string]string, error) {
|
func (d *Dir) GetSubdirs() (map[string]string, error) {
|
||||||
|
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
_ "embed"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed linuxdb.yaml
|
||||||
|
var LinuxDBYaml []byte
|
||||||
|
|
||||||
// LinuxDB is the database for linux distribution data.
|
// LinuxDB is the database for linux distribution data.
|
||||||
type LinuxDB struct {
|
type LinuxDB struct {
|
||||||
Distributions map[string]*Distribution `yaml:"distributions"`
|
Distributions map[string]*Distribution `yaml:"distributions"`
|
||||||
@ -78,14 +82,10 @@ func (l *LinuxDB) GetDistro(distro string) *Distribution {
|
|||||||
// NewLinuxDB creates a new LinuxDB instance from the bundled
|
// NewLinuxDB creates a new LinuxDB instance from the bundled
|
||||||
// linuxdb.yaml file.
|
// linuxdb.yaml file.
|
||||||
func NewLinuxDB() *LinuxDB {
|
func NewLinuxDB() *LinuxDB {
|
||||||
data, err := fs.LoadRelativeFile("./linuxdb.yaml")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Could not load linuxdb.yaml")
|
|
||||||
}
|
|
||||||
result := LinuxDB{
|
result := LinuxDB{
|
||||||
Distributions: make(map[string]*Distribution),
|
Distributions: make(map[string]*Distribution),
|
||||||
}
|
}
|
||||||
err = result.ImportData(data)
|
err := result.ImportData(LinuxDBYaml)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user