]> git.lizzy.rs Git - micro.git/blob - runtime/runtime.go
normalize path - force slash separator to access embed FS (#2197)
[micro.git] / runtime / runtime.go
1 package config
2
3 import (
4         "embed"
5         "path/filepath"
6         "strings"
7 )
8
9 //go:generate go run syntax/make_headers.go syntax
10
11 //go:embed colorschemes help plugins syntax
12 var runtime embed.FS
13
14 func fixPath(name string) string {
15         return strings.TrimLeft(filepath.ToSlash(name), "runtime/")
16 }
17
18 // AssetDir lists file names in folder
19 func AssetDir(name string) ([]string, error) {
20         name = fixPath(name)
21         entries, err := runtime.ReadDir(name)
22         if err != nil {
23                 return nil, err
24         }
25         names := make([]string, len(entries), len(entries))
26         for i, entry := range entries {
27                 names[i] = entry.Name()
28         }
29         return names, nil
30 }
31
32 // Asset returns a file content
33 func Asset(name string) ([]byte, error) {
34         name = fixPath(name)
35         return runtime.ReadFile(name)
36 }