//控制器处理方法: AttachController:this
type AttachController struct { beego.Controller } func (this *AttachController)Get(){ filePath,err:=url.QueryUnescape(this.Ctx.Request.RequestURI[1:]) beego.Info(this.Ctx.Request.RequestURI[1:]) if err!=nil{ this.Ctx.WriteString(err.Error()) return } f,err:=os.Open(filePath) if err!=nil{ this.Ctx.WriteString(err.Error()) return } defer f.Close() _,err=io.Copy(this.Ctx.ResponseWriter,f) if err!=nil{ this.Ctx.WriteString(err.Error()) return } }
router:url
//做为控制器处理文件 beego.Router("/attachment/:all",&controllers.AttachController{})
//做为静态文件处理方法code
//做为静态文件 //beego.SetStaticPath("/attachment","attachment")