File: runtime.go

package info (click to toggle)
micro 2.0.15-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,128 kB
  • sloc: sh: 265; makefile: 77; xml: 53
file content (36 lines) | stat: -rw-r--r-- 719 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package config

import (
	"embed"
	"path/filepath"
	"strings"
)

//go:generate go run syntax/make_headers.go syntax

//go:embed colorschemes help plugins syntax
var runtime embed.FS

func fixPath(name string) string {
	return strings.TrimLeft(filepath.ToSlash(name), "runtime/")
}

// AssetDir lists file names in folder
func AssetDir(name string) ([]string, error) {
	name = fixPath(name)
	entries, err := runtime.ReadDir(name)
	if err != nil {
		return nil, err
	}
	names := make([]string, len(entries))
	for i, entry := range entries {
		names[i] = entry.Name()
	}
	return names, nil
}

// Asset returns a file content
func Asset(name string) ([]byte, error) {
	name = fixPath(name)
	return runtime.ReadFile(name)
}