Пример #1
0
func (f *File) configureData(in core.Input) {

	t, err := in.Type("content")
	if err != nil {
		return
	}

	if t == "pipe" {
		val, _ := in.Data("content")
		f.data = val.(io.Reader)
	}

	if t == "data" {
		val, _ := in.Data("content")
		f.sum = sum(val.([]byte))
		f.data = bytes.NewReader(val.([]byte))
	}
}
Пример #2
0
// Configure configures an instance of a module
func (f *File) Configure(in core.Input) error {
	err := in.Validate(schema)
	if err != nil {
		return err
	}

	if val, err := in.Data("path"); err != nil {
		return errors.New("Path is required")
	} else {
		f.path = val.(string)
	}

	if val, err := in.Data("mode"); err != nil {
		f.mode = os.FileMode(0644)
	} else {
		f.mode, err = fileMode(val)
		if err != nil {
			return errors.New("Unable to parse mode")
		}
	}

	if val, err := in.Data("action"); err != nil {
		f.action = f.touch
	} else {
		switch val.(string) {
		case "touch":
			f.action = f.touch

		case "remove":
			f.action = f.remove

		case "set":
			f.configureData(in)
			f.action = f.set

		default:
			return errors.New("Unable to parse action")
		}
	}

	return err
}