Пример #1
0
// Build injects a script for loading the environment.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error {
	if fn.Runtime != RuntimeCanonical || len(fn.Environment) == 0 {
		return nil
	}

	fn.Log.Debug("injecting prelude")

	var buf bytes.Buffer
	file := strings.Split(fn.Handler, ".")[0]
	method := strings.Split(fn.Handler, ".")[1]

	err := prelude.Execute(&buf, struct {
		EnvFile      string
		HandleFile   string
		HandleMethod string
	}{
		EnvFile:      env.FileName,
		HandleFile:   file,
		HandleMethod: method,
	})

	if err != nil {
		return err
	}

	fn.Handler = "_apex_main.handle"

	return zip.AddBytesMTime("_apex_main.py", buf.Bytes(), time.Unix(0, 0))
}
Пример #2
0
Файл: env.go Проект: elizar/apex
// Build hook adds .env.json populate with Function.Enironment.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error {
	if len(fn.Environment) == 0 {
		return nil
	}

	fn.Log.WithField("env", fn.Environment).Debug("adding env")

	env, err := json.Marshal(fn.Environment)
	if err != nil {
		return err
	}

	return zip.AddBytesMTime(FileName, env, time.Unix(0, 0))
}
Пример #3
0
// Build adds the nodejs shim files.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error {
	if fn.Shim {
		fn.Log.Debug("add shim")

		if err := zip.AddBytesMTime("index.js", shim.MustAsset("index.js"), time.Unix(0, 0)); err != nil {
			return err
		}

		if err := zip.AddBytesMTime("byline.js", shim.MustAsset("byline.js"), time.Unix(0, 0)); err != nil {
			return err
		}
	}

	return nil
}