Пример #1
0
func performGet(args []string) error {
	if len(args) > 1 {
		return errors.New("get takes only 1 argument")
	}
	path := args[0]
	data, err := wasp.Get(path)
	if err == nil {
		var container interface{}
		util.JsonDecode(data, &container)
		dataToString(container)
	}
	return err
}
Пример #2
0
func performLS(args []string) error {
	path := strings.Join(args, "")
	data, err := wasp.List(path)
	if err == nil {
		var keys []string
		util.JsonDecode(data, &keys)

		for _, key := range keys {
			fmt.Println(key)
		}
	}
	return err
}
Пример #3
0
func performGen(args []string) (err error) {
	if len(args) != 2 {
		return errors.New("gen takes exactly 2 arguments")
	}

	path := args[0]
	tmplFile := args[1]
	data, err := wasp.Get(path)
	if err == nil {
		var container interface{}
		util.JsonDecode(data, &container)

		// catch the template.Must's panic and return that as an error
		defer func() {
			if recovered := recover(); recovered != nil { //catch
				err = errors.New(fmt.Sprintf("Exception: %v\n", recovered))
			}
		}()
		return template.Must(template.ParseFiles(tmplFile)).Execute(os.Stdout, container)
	}

	return err
}