本文整理汇总了Golang中github.com/zhuharev/smoljanin/ru/modules/middleware.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Submit
func Submit(c *middleware.Context) {
if c.Req.Method == "POST" {
submitPost(c)
return
}
c.HTML(200, "catalog/submit")
}
示例2: Upload
func Upload(c *middleware.Context) {
c.Req.ParseMultipartForm(32 << 20)
file, _, err := c.Req.FormFile("uploadfile")
if err != nil {
fmt.Println(err)
return
}
defer file.Close()
name := uuid.NewV4().String()
//.fmt.Fprintf(w, "%v", handler.Header)
err = os.MkdirAll("data/uploads/"+makePaths(name), 0777)
if err != nil {
return
}
f, err := os.OpenFile("data/uploads/"+makePaths(name)+"/"+name, os.O_WRONLY|os.O_CREATE, 0777)
if err != nil {
fmt.Println(err)
return
}
defer f.Close()
io.Copy(f, file)
c.JSON(200, makePaths(name))
}
示例3: Screen
func Screen(c *middleware.Context) {
id := c.ParamsInt64(":id")
name, e := screen(id)
if e != nil {
color.Red("%s", e)
}
c.Redirect("/" + makePaths(name) + "/" + name)
}
示例4: Show
func Show(c *middleware.Context) {
site, e := models.GetSite(c.ParamsInt64(":id"))
if e != nil {
color.Red("%s", e)
}
go models.SiteFetchNewFeed(site.Id)
c.Data["site"] = site
c.Data["Title"] = site.Title
c.HTML(200, "catalog/show")
}
示例5: SetFeed
func SetFeed(c *middleware.Context) {
id := c.ParamsInt64(":id")
val := c.Query("hf")
hf := false
if val == "1" {
hf = true
}
e := models.SiteSetHasFeed(id, hf)
if e != nil {
c.Flash.Error(e.Error())
}
c.Redirect(c.URLFor("cat_item", ":id", c.Params(":id")))
}
示例6: FeedShow
func FeedShow(c *middleware.Context) {
sf, e := models.GetSiteFeedItem(c.ParamsInt64(":feedId"))
if e != nil {
color.Red("%s", e)
}
a, e := linkpreview.Articler.ParseArticle(sf.Source, []byte(sf.Body))
if e != nil {
color.Red("%s", e)
}
if !sf.Published.Equal(a.Published.In(time.Now().Location())) {
sf.Published = a.Published.In(time.Now().Location())
models.SaveSiteFeed(sf)
}
sf.Body = a.Text
c.Data["feed"] = sf
c.HTML(200, "catalog/feedshow")
}
示例7: Resize
func Resize(c *middleware.Context) {
w := c.QueryInt("width")
p := c.Req.URL.Path
color.Green("[path] %s", p)
target := strings.TrimPrefix(p, "/resize")
if strings.HasPrefix(target, "/cat/screen/") {
var id int64
fmt.Sscanf(target, "/cat/screen/%d?width=", &id)
name, e := screen(id)
if e != nil {
color.Red("%s", e)
return
}
target = name
}
savePath := "data/public/resize/" + com.ToStr(w) + "/" + target + ".jpg"
if com.IsFile(savePath) {
f, e := os.Open(savePath)
if e != nil {
color.Red("%s", e)
}
c.Resp.Header().Set("Content-Type", "image/jpeg")
io.Copy(c.Resp, f)
return
}
img, e := imaging.Open(filepath.Join("data/uploads", target))
if e != nil {
color.Red("%s", e)
return
}
i := resize.Resize(uint(w), uint(w/2), img, resize.Bilinear)
dir := filepath.Dir(target)
os.MkdirAll(filepath.Join("data/public/resize/"+com.ToStr(w)+"/", dir), 0777)
e = imaging.Save(i, savePath)
if e != nil {
color.Red("%s", e)
}
c.Resp.Header().Set("Content-Type", "image/jpeg")
e = jpeg.Encode(c.Resp, i, nil)
if e != nil {
color.Red("%s", e)
}
//c.Redirect("/public/resize/" + com.ToStr(w) + "/" + target + ".jpg")
}
示例8: AllFeedJSON
func AllFeedJSON(c *middleware.Context) {
p := c.QueryInt("p")
if p < 1 {
p = 1
}
feed, e := models.GetFeed(p)
if e != nil {
color.Red("%s", e)
}
/*cnt, e := models.FeedCount()
if e != nil {
color.Red("%s", e)
}*/
c.Data["feed"] = feed
//c.Data["paginater"] = paginater.New(int(cnt), 10, p, 5)
c.JSON(200, feed)
}
示例9: AllFeed
func AllFeed(c *middleware.Context) {
p := c.ParamsInt(":p")
if p < 1 {
p = 1
}
feed, e := models.GetFeed(p)
if e != nil {
color.Red("%s", e)
}
cnt, e := models.FeedCount()
if e != nil {
color.Red("%s", e)
}
c.Data["feed"] = feed
c.Data["paginater"] = paginater.New(int(cnt), 10, p, 5)
c.HTML(200, "catalog/feed")
}
示例10: Index
func Index(c *middleware.Context) {
var (
p = c.ParamsInt(":p")
)
sites, e := models.SiteList(p)
if e != nil {
color.Red("%s", e)
}
cnt, e := models.SiteCount()
if e != nil {
color.Red("%s", e)
}
c.Data["sites"] = sites
c.Data["sites_count"] = cnt
c.Data["paginater"] = paginater.New(int(cnt), 10, p, 5)
c.HTML(200, "catalog/index")
}
示例11: Feed
func Feed(c *middleware.Context) {
sid := c.ParamsInt64(":id")
p := c.ParamsInt(":p")
if p < 1 {
p = 1
}
feed, e := models.GetSiteFeed(sid, p)
if e != nil {
color.Red("%s", e)
}
cnt, e := models.SiteFeedCount(sid)
if e != nil {
color.Red("%s", e)
}
c.Data["feed"] = feed
c.Data["paginater"] = paginater.New(int(cnt), 10, p, 5)
c.Data["SiteId"] = sid
c.HTML(200, "catalog/feed")
}
示例12: submitPost
func submitPost(c *middleware.Context) {
s, e := models.NewSite(c.Query("link"), c.Query("title"))
if e != nil {
c.Flash.Error(e.Error(), true)
if c.QueryInt("ajax") == 1 {
c.JSON(200, e.Error())
return
}
c.HTML(200, "catalog/submit")
return
}
c.Flash.Success(fmt.Sprintf("%d добавлен", s.Id), true)
if c.QueryInt("ajax") == 1 {
c.JSON(200, fmt.Sprintf("%d добавлен", s.Id))
return
}
c.HTML(200, "catalog/submit")
}
示例13: Home
func Home(c *middleware.Context) {
c.HTML(200, "home")
}