예제 #1
0
파일: view.go 프로젝트: sedzinreri/go-start
package media

import (
	"github.com/ungerik/go-start/utils"
	"github.com/ungerik/go-start/view"
	"io"
)

var View view.ViewWithURL = view.NewViewURLWrapper(view.RenderView(
	func(context *view.Context, writer *utils.XMLWriter) error {
		reader, contentType, err := Config.Backend.ImageVersionReader(context.PathArgs[0])
		if err != nil {
			if _, ok := err.(ErrInvalidImageID); ok {
				return view.NotFound(context.PathArgs[0] + "/" + context.PathArgs[1] + " not found")
			}
			return err
		}
		_, err = io.Copy(writer, reader)
		if err != nil {
			return err
		}
		err = reader.Close()
		if err != nil {
			return err
		}
		context.Header().Set("Content-Type", contentType)
		return nil
	},
))

func ViewPath(name string) view.ViewPath {
예제 #2
0
파일: view.go 프로젝트: SohoStudio/go-start
package media

import (
	"io"

	"github.com/ungerik/go-start/view"
)

var View = view.NewViewURLWrapper(view.RenderView(
	func(ctx *view.Context) error {
		reader, contentType, err := Config.Backend.ImageVersionReader(ctx.URLArgs[0])
		if err != nil {
			if _, ok := err.(ErrInvalidImageID); ok {
				return view.NotFound(ctx.URLArgs[0] + "/" + ctx.URLArgs[1] + " not found")
			}
			return err
		}
		_, err = io.Copy(ctx.Response, reader)
		if err != nil {
			return err
		}
		err = reader.Close()
		if err != nil {
			return err
		}
		ctx.Response.Header().Set("Content-Type", contentType)
		return nil
	},
))

func ViewPath(name string) view.ViewPath {