コード例 #1
0
ファイル: cmds.go プロジェクト: rainycape/gondola
func catFile(ctx *app.Context) {
	var id string
	ctx.MustParseIndexValue(0, &id)
	f, err := ctx.Blobstore().Open(id)
	if err != nil {
		panic(err)
	}
	defer f.Close()
	var meta bool
	ctx.ParseParamValue("meta", &meta)
	if meta {
		var m interface{}
		if err := f.GetMeta(&m); err != nil {
			panic(err)
		}
		fmt.Println(m)
	} else {
		io.Copy(os.Stdout, f)
	}
}
コード例 #2
0
ファイル: cmds.go プロジェクト: rainycape/gondola
func renderTemplate(ctx *app.Context) {
	var template string
	ctx.MustParseIndexValue(0, &template)
	tmpl, err := ctx.App().LoadTemplate(template)
	if err != nil {
		panic(err)
	}
	var buf bytes.Buffer
	if err := tmpl.ExecuteTo(&buf, ctx, nil); err != nil {
		panic(err)
	}
	var output string
	ctx.ParseParamValue("o", &output)
	if output == "" || output == "-" {
		fmt.Print(buf.String())
	} else {
		if err := ioutil.WriteFile(output, buf.Bytes(), 0644); err != nil {
			panic(err)
		}
	}
}