plugins

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EnvPlugin = api.Plugin{
	Name: "env",
	Setup: func(build api.PluginBuild) {
		build.OnResolve(api.OnResolveOptions{Filter: `^env$`},
			func(args api.OnResolveArgs) (api.OnResolveResult, error) {
				return api.OnResolveResult{
					Path:      args.Path,
					Namespace: "env-ns",
				}, nil
			})
		build.OnLoad(api.OnLoadOptions{Filter: `.*`, Namespace: "env-ns"},
			func(args api.OnLoadArgs) (api.OnLoadResult, error) {
				mappings := make(map[string]string)
				for _, item := range os.Environ() {
					if equals := strings.IndexByte(item, '='); equals != -1 {
						mappings[item[:equals]] = item[equals+1:]
					}
				}
				bytes, err := json.Marshal(mappings)
				if err != nil {
					return api.OnLoadResult{}, err
				}
				contents := string(bytes)
				return api.OnLoadResult{
					Contents: &contents,
					Loader:   api.LoaderJSON,
				}, nil
			})
	},
}

EnvPlugin reads environment variable

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL