Ejemplo n.º 1
0
// Open the function.json file and prime the config.
func (f *Function) Open() error {
	p, err := os.Open(filepath.Join(f.Path, "function.json"))
	if err == nil {
		if err := json.NewDecoder(p).Decode(&f.Config); err != nil {
			return err
		}
	}

	if f.Runtime == "" {
		if runtimeName, err := runtime.Detect(f.Path); err == nil {
			f.Runtime = runtimeName
		}
	}

	if err := validator.Validate(&f.Config); err != nil {
		return fmt.Errorf("error opening function %s: %s", f.Name, err.Error())
	}

	r, err := runtime.ByName(f.Runtime)
	if err != nil {
		return err
	}
	f.runtime = r

	f.Log = f.Log.WithField("function", f.Name)

	return nil
}
Ejemplo n.º 2
0
// Open the function.json file and prime the config.
func (f *Function) Open() error {
	p, err := os.Open(filepath.Join(f.Path, "function.json"))
	if err == nil {
		if err := json.NewDecoder(p).Decode(&f.Config); err != nil {
			return err
		}
	}

	if f.Runtime == "" {
		if runtimeName, err := runtime.Detect(f.Path); err == nil {
			f.Runtime = runtimeName
		}
	}

	if err := validator.Validate(&f.Config); err != nil {
		return fmt.Errorf("error opening function %s: %s", f.Name, err.Error())
	}

	r, err := runtime.ByName(f.Runtime)
	if err != nil {
		return err
	}
	f.runtime = r

	patterns, err := utils.ReadIgnoreFile(f.Path)
	if err != nil {
		return err
	}
	f.IgnoredPatterns = append(f.IgnoredPatterns, patterns...)

	f.files, err = utils.LoadFiles(f.Path, f.IgnoredPatterns)
	if err != nil {
		return err
	}

	f.Log = f.Log.WithField("function", f.Name)

	return nil
}