• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang render.Renderer函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/martini-contrib/render.Renderer函数的典型用法代码示例。如果您正苦于以下问题:Golang Renderer函数的具体用法?Golang Renderer怎么用?Golang Renderer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Renderer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: http

func http() {
	server := martini.Classic()

	server.Use(martini.Static("public", martini.StaticOptions{
		Prefix: "public",
	}))

	server.Use(martini.Static("bower_components", martini.StaticOptions{
		Prefix: "bower_components",
	}))

	server.Use(render.Renderer(render.Options{
		Extensions: []string{".tmpl", ".html"},
		Delims:     render.Delims{"{[{", "}]}"},
	}))

	server.Get("/", func(r render.Render) {
		r.HTML(200, "index", nil)
	})

	//
	server.Get("/clients/:pid", func(params martini.Params, r render.Render) {
		r.HTML(200, "index", params["pid"])
	})

	type jd map[string]interface{}
	type ja []interface{}

	// json api
	server.Get("/api/clients", func(r render.Render) {
		client_info := ja{}

		for _, c := range compositors {
			var surfaces []Surface

			for _, s := range c.Surfaces {
				surfaces = append(surfaces, *s)
			}

			client_info = append(client_info, jd{
				"pid": c.Pid,
				"ss":  surfaces,
			})
		}

		r.JSON(200, client_info)
	})

	// websocket api

	server.Get("/api/clients", websocket.Handler(func(ws *websocket.Conn) {

	}).ServeHTTP)

	server.Get("/api/clients/:pid", websocket.Handler(func(ws *websocket.Conn) {

	}).ServeHTTP)

	server.Run()
}
开发者ID:fangyuanziti,项目名称:wayland-html,代码行数:60,代码来源:http-server.go


示例2: apiv1

func apiv1() {
	url := "/api/v1"
	m.Group(url+"/workplace", func(router martini.Router) {
		router.Post("/auth", binding.Json(controllers.InputWorkplaceAuth{}), controllers.WorkplaceAuth)
		//router.Post("/test", binding.Json(controllers.Test{}), controllers.WorkplacePing)
		//router.Post("/add", binding.Json(controllers.Add{}), controllers.WorkplaceAdd)
		//update
		//delete
		//import

	}, render.Renderer())

	m.Group(url+"/promocode", func(router martini.Router) {

		router.Post("/calc", binding.Json(controllers.InputPromocodeCalc{}), controllers.PromocodeCalc)
		//update
		//delete
		//import

	}, render.Renderer())

	m.Group(url+"/document", func(router martini.Router) {

		router.Post("/add", binding.Json(controllers.InputDocumentAdd{}), controllers.DocumentAdd)
		//update
		//delete
		//import

	}, render.Renderer())

}
开发者ID:Ch16uR,项目名称:go-cls,代码行数:31,代码来源:route.go


示例3: Start

// Entry point for running the application.
// It defines all routes and middleware used
// and starts the underlying server.
func Start() {
	// Set up our Martini instance
	m := martini.Classic()

	// Middleware
	// m.Use(gzip.All())
	m.Use(render.Renderer())

	// Routes
	m.Group("/admin", func(r martini.Router) {
		a := handlers.Admin{}

		r.Get("", a.Index)
		r.Get("/posts", a.Posts.Index)
		r.Get("/posts/new", a.Posts.New)
		r.Get("/posts/:id/edit", a.Posts.Edit)

	}, render.Renderer(render.Options{
		Layout: "admin/layout",
	}))

	m.Group("/api", func(r martini.Router) {
		a := handlers.Api{}

		r.Get("", a.Index)
		r.Get("/posts", a.Posts.Index)
		r.Post("/posts", a.Posts.Create)
		r.Get("/posts/:id", a.Posts.Show)
		r.Get("/render/markdown", a.Render.Markdown)
	})

	// Serve from static if possible
	m.Use(martini.Static(util.Config().App.SiteDir))
	m.Run()
}
开发者ID:supermouseno1,项目名称:b,代码行数:38,代码来源:b.go


示例4: Run

func (this *Server) Run(withRandomPort ...bool) {
	this.Martini.Use(cors.Allow(&cors.Options{
		AllowAllOrigins:  true,
		AllowMethods:     []string{"PUT", "PATCH", "DELETE", "GET", "OPTIONS", "POST"},
		AllowCredentials: true,
	}))
	this.Martini.Use(render.Renderer())

	this.Martini.Group("/eureka", func(r martini.Router) {
		for _, request := range this.getRequestsEureka() {
			request.SetRoutes(r)
		}
	})
	this.registerJobsRoutes()
	if len(withRandomPort) > 0 && withRandomPort[0] {
		listener, err := net.Listen("tcp", "127.0.0.1:0")
		if err != nil {
			loggerServer.Severe("Error when getting a free random port: %v", err.Error())
		}
		host := listener.Addr().String()
		listener.Close()
		this.Martini.RunOnAddr(host)
	} else if config.GetConfig().Host != "" {
		this.Martini.RunOnAddr(config.GetConfig().Host)
	} else {
		this.Martini.Run()
	}

}
开发者ID:ArthurHlt,项目名称:microcos,代码行数:29,代码来源:server.go


示例5: Start

func Start(port string, onStart func()) {

	// Logging init
	flag.Set("log_dir", utils.GetRuntimeDir(config.GetString("log_dir")))
	flag.Set("alsologtostderr", "true")
	flag.Parse()
	defer glog.Flush()

	m := martini.Classic()
	m.Use(render.Renderer(render.Options{
		Charset:   "UTF-8", // Sets encoding for json and html content-types. Default is "UTF-8".
		Delims:    render.Delims{"${", "}"},
		Directory: utils.GetRuntimeDir("resources/views"),
	}))

	m.Use(martini.Static(utils.GetRuntimeDir("public")))
	controller.MappingController(m)

	http.Handle("/rpc", rpc.GetServer())
	http.Handle("/", m)

	if db.IsConnected() {
		defer db.Close()
	}

	onStart()

	for _, fn := range methods {
		go fn()
	}

	http.ListenAndServe(":"+port, nil)
}
开发者ID:sdgdsffdsfff,项目名称:svnmanager,代码行数:33,代码来源:bootstrap.go


示例6: main

func main() {
	defer clean()

	mck := shardmaster.MakeClerk(smh)
	mck.Join(gids[0], ha[0])

	ck.Subscribe("a")
	ck.Subscribe("b")
	ck.Subscribe("c")
	ck.Subscribe("d")
	ck.Subscribe("e")
	defer cleanupClerk(ck)

	go listener(ck)
	go h.run()

	m := martini.Classic()
	m.Use(render.Renderer())

	m.Get("/", func(r render.Render) {
		r.HTML(200, "index", "")
	})

	m.Get("/ws", wsHandler)

	m.Run()
}
开发者ID:jeffchan,项目名称:pushydb,代码行数:27,代码来源:server.go


示例7: main

func main() {
	log.Println("server start11")
	fmt.Printf("access_token:%s", ACCESS_TOKEN)
	m := martini.Classic()
	m.Handlers(martini.Recovery())
	m.Use(render.Renderer(render.Options{
		Extensions: []string{".html", ".shtml"},
	}))

	m.Get("/", checkSignatureHandler)
	m.Post("/", transceiverMsgHandler)
	m.Get("/createMenu", createMenuHandler)
	m.Get("/hi", func() string {
		return "Hello world!"
	})

	http.Handle("/", m)
	if martini.Env == martini.Dev {
		HOST = ":8080"
	} else {
		HOST = ":80"
	}
	log.Printf("start web server on %s", HOST)
	http.ListenAndServe(HOST, nil)
}
开发者ID:sugeladi,项目名称:goWeb,代码行数:25,代码来源:main.go


示例8: Routes

func Routes() http.Handler {
	// Middlewares are setup and run before each incoming request
	// the ones named like *Provider provide singleton instances
	// of injectable objects. For instance appx, logger, appengine context
	// can be injected in our routes handlers (a.k.a controllers)
	router := martini.Classic()

	router.Use(render.Renderer())
	router.Use(middlewares.AppengineContextProvider)
	router.Use(middlewares.LoggerProvider)
	router.Use(middlewares.AppxProvider)

	router.Post("/login", binding.Bind(controllers.LoginForm{}), controllers.Login)

	router.Group("/account", func(r martini.Router) {
		r.Post("/registerDropbox", binding.Bind(controllers.RegisterDropboxForm{}), controllers.RegisterDropbox)
		r.Post("/update", binding.Bind(controllers.AccountUpdateForm{}), controllers.UpdateAccount)

		r.Group("/dropbox", func(r martini.Router) {
			r.Post("/init", controllers.DropboxInit)
			r.Post("/delta", controllers.DropboxDelta)
		}, middlewares.ExternalServiceAuthorizationProvider)

		r.Group("/trails", func(r martini.Router) {
			r.Get("/next_evaluation", controllers.TrailNextEvaluation)
			r.Patch("/:trail_id/like", controllers.TrailLike)
			r.Patch("/:trail_id/dislike", controllers.TrailDislike)
			r.Get("/tags", controllers.Tags)
			r.Get("/tags/:tag_id", controllers.TagTrails)
		})
	}, middlewares.AuthorizationAccountProvider)

	return router
}
开发者ID:BearchInc,项目名称:trails-api,代码行数:34,代码来源:routes.go


示例9: main

func main() {
	m := martini.Classic()
	m.Map(SetupDB())
	m.Use(martini.Logger())
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))

	store := sessions.NewCookieStore([]byte(CookieSecret))
	m.Use(sessions.Sessions("bunkaisession", store))
	log.Println("env is", martini.Env)
	m.Map(martini.Env)

	m.Group("/", func(m martini.Router) {
		m.Get("", Home)
	}, AssetMap)

	m.Group("/api", func(m martini.Router) {
		m.Post("/login", PostLogin)
		m.Post("/users", UserCreate)

		m.Group("/sentences", func(m martini.Router) {
			m.Post("", SentenceCreate)
			m.Get("", SentenceList)
			m.Delete("/:id", SentenceDelete)
		}, RequireLogin)

		m.Group("/users", func(m martini.Router) {
			m.Post("/logout", Logout)
			m.Get("/me", UserGet)
		}, RequireLogin)
	})

	m.Run()
}
开发者ID:ukitazume,项目名称:bunkai,代码行数:35,代码来源:server.go


示例10: App

func App() *martini.ClassicMartini {
	m := martini.Classic()

	m.Use(gzip.All())

	m.Use(render.Renderer(render.Options{
		Directory: "templates",
	}))

	m.Use(cors.Allow(&cors.Options{
		AllowAllOrigins: true,
	}))

	m.Get("", Index)

	m.Group("/repos", func(r martini.Router) {
		r.Get("", ReposIndex)
		r.Get("/:name", ReposShow)
	})

	m.Group("/orgs", func(r martini.Router) {
		r.Get("", OrgsIndex)
		r.Get("/:id", OrgsShow)
	})

	m.Group("/users", func(r martini.Router) {
		r.Get("", UserIndex)
		r.Get("/:id", UserShow)
	})

	m.Get("/stats", StatsIndex)
	m.Get("/issues", IssuesIndex)

	return m
}
开发者ID:jakeporter,项目名称:govcode.org,代码行数:35,代码来源:main.go


示例11: main

func main() {
	log.Info("启动")
	//读取配置文件
	base.BaseConfig.Read("config.json")
	// 初始化数据库
	base.InitDb()
	// 检查文件完整性
	//err := base.CheckFiles()
	//if(err!=nil){
	//  log.Error(err)
	//  return
	//}
	m := martini.Classic()
	// gzip支持
	m.Use(gzip.All())
	// 模板支持
	m.Use(render.Renderer())
	//
	m.Get("/meta.js", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/javascript")
		w.Write([]byte(base.GetMetaJs()))
	})
	// websocket 支持
	m.Get("/ws", websocket.Handler(base.WsHandler).ServeHTTP)
	m.NotFound(func(r render.Render) {
		r.HTML(404, "404", nil)
	})
	log.Info(fmt.Sprintf("访问地址 http://localhost:%d", base.BaseConfig.Web.Port))
	// 端口号
	http.ListenAndServe(fmt.Sprintf(":%d", base.BaseConfig.Web.Port), m)
	// m.Run()
	log.Info("退出")
}
开发者ID:xuender,项目名称:pen,代码行数:33,代码来源:main.go


示例12: main

func main() {
	m := martini.Classic()

	store := sessions.NewCookieStore([]byte("secret-isucon"))
	m.Use(sessions.Sessions("isucon_go_session", store))

	m.Use(martini.Static("../public"))
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))

	m.Get("/", func(r render.Render, session sessions.Session) {
		r.HTML(200, "index", map[string]string{"Flash": getFlash(session, "notice")})
	})

	m.Post("/login", func(req *http.Request, r render.Render, session sessions.Session) {
		user, err := attemptLogin(req)

		notice := ""
		if err != nil || user == nil {
			switch err {
			case ErrBannedIP:
				notice = "You're banned."
			case ErrLockedUser:
				notice = "This account is locked."
			default:
				notice = "Wrong username or password"
			}

			session.Set("notice", notice)
			r.Redirect("/")
			return
		}

		session.Set("user_id", strconv.Itoa(user.ID))
		r.Redirect("/mypage")
	})

	m.Get("/mypage", func(r render.Render, session sessions.Session) {
		currentUser := getCurrentUser(session.Get("user_id"))

		if currentUser == nil {
			session.Set("notice", "You must be logged in")
			r.Redirect("/")
			return
		}

		currentUser.getLastLogin()
		r.HTML(200, "mypage", currentUser)
	})

	m.Get("/report", func(r render.Render) {
		r.JSON(200, map[string][]string{
			"banned_ips":   bannedIPs(),
			"locked_users": lockedUsers(),
		})
	})

	http.ListenAndServe(":8080", m)
}
开发者ID:shogo82148,项目名称:isucon4_powawa,代码行数:60,代码来源:main.go


示例13: main

func main() {
	m := martini.Classic()
	m.Map(SetupDB())
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))

	m.Get("/", func(ren render.Render, r *http.Request, db *sql.DB) {
		searchTerm := "%" + r.URL.Query().Get("search") + "%"
		rows, err := db.Query(`SELECT title, author, description FROM books
                           WHERE title ILIKE $1
                           OR author ILIKE $1
                           OR description ILIKE $1`, searchTerm)
		PanicIf(err)
		defer rows.Close()

		books := []Book{}
		for rows.Next() {
			book := Book{}
			err := rows.Scan(&book.Title, &book.Author, &book.Description)
			PanicIf(err)
			books = append(books, book)
		}

		ren.HTML(200, "books", books)
	})

	m.Run()
}
开发者ID:RajeshReddyM,项目名称:Lessons,代码行数:29,代码来源:main.go


示例14: main

func main() {

	autoUpdate()

	m := martini.Classic()
	m.Use(martini.Static("static"))
	m.Use(render.Renderer())

	m.Get("/", func(r render.Render) {
		r.HTML(200, "content", []interface{}{getPage(1)})
	})

	m.Get("/api/:id", func(params martini.Params, r render.Render) {
		s := strings.Trim(params["id"], " .)(")
		id := atoi(s)
		r.JSON(200, getPage(id))
	})

	m.Get("/page/:id", func(params martini.Params, r render.Render) {
		s := strings.Trim(params["id"], " .)(")
		id := atoi(s)
		r.HTML(200, "content", []interface{}{getPage(id)})
	})

	http.ListenAndServe("0.0.0.0:8000", m)
	m.Run()
}
开发者ID:kizure,项目名称:GO-ZhihuDaily,代码行数:27,代码来源:main.go


示例15: main

func main() {
	m := martini.Classic()

	//middleware
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))

	m.Get("/", func(r render.Render) {
		r.HTML(200, "index", "")
	})

	m.Get("/new", func(r render.Render) {
		var v map[string]interface{}

		values := url.Values{}
		res, err := http.PostForm("http://requestb.in/api/v1/bins", values)

		if err != nil {
			r.JSON(500, map[string]interface{}{"error": err})
		} else {
			defer res.Body.Close()

			err = json.NewDecoder(res.Body).Decode(&v)

			if err != nil {
				r.JSON(500, map[string]interface{}{"error": err})
			}
		}

		r.HTML(200, "new", v)
	})

	m.Run()
}
开发者ID:omtim,项目名称:disposable-email,代码行数:35,代码来源:app.go


示例16: main

func main() {
	m := martini.Classic()

	m.Use(gzip.All())

	// render html templates from templates directory
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))

	m.Use(DB())

	m.Get("/", func(r render.Render, db *mgo.Database) {
		data := map[string]interface{}{"quotes": GetAll(db)}
		r.HTML(200, "list", data)
	})

	m.Post("/", binding.Form(Quote{}), func(r render.Render, db *mgo.Database, quote Quote) {
		db.C("quotes").Insert(quote)
		data := map[string]interface{}{"quotes": GetAll(db)}
		r.HTML(200, "list", data)
	})

	m.Run()
}
开发者ID:aeyoll,项目名称:go-quotes,代码行数:25,代码来源:server.go


示例17: main

func main() {
	// init server
	err := server.Init("httpaccess")
	if err != nil {
		server.Log.Fatal(err)
		return
	}

	// martini setup
	martini.Env = martini.Prod
	handler := martini.Classic()
	handler.Use(render.Renderer())
	route(handler)

	// register a http handler
	err = server.RegisterHTTPHandler(handler)
	if err != nil {
		server.Log.Errorf("RegisterHTTPHandler Error: %s", err)
		return
	}

	// go
	err = server.Run()
	if err != nil {
		server.Log.Fatal(err)
	}
}
开发者ID:oskycar,项目名称:pando-cloud,代码行数:27,代码来源:main.go


示例18: InitSession

//InitSession - initializes authentication middleware for controllers
func InitSession(m *martini.ClassicMartini, rc redisCreds) {
	m.Use(render.Renderer())

	if rediStore, err := sessions.NewRediStore(10, "tcp", rc.Uri(), rc.Pass(), []byte(sessionSecret)); err == nil {
		m.Use(sessions.Sessions(sessionName, rediStore))
	}
}
开发者ID:malston,项目名称:pezauth,代码行数:8,代码来源:auth.go


示例19: StartServer

func StartServer() {

	m := martini.Classic()

	m.Use(render.Renderer())

	db_session := getSession()
	if db_session == nil {
		return
	}

	user, err := controllers.NewUserController(db_session.C("users"))
	if err != nil {
		log.Error("Error reading mongo db users collection: ", err)
		return
	}

	// m.GET("/", user.Home)
	//  dashboard or landing page for app   root_path  "/"

	m.Group("/users", func(r martini.Router) {
		r.Get("", user.GetAllUsers)
		r.Post("", user.CreateUser)
		// r.Get("/(?P<name>[a-zA-Z]+)", user.GetUser)    //get user's profile
		r.Get("/:id", user.GetUser)
		r.Delete("/:id", user.DeleteUser)
		r.Put("/:id", user.UpdateUser)
		// r.Delete("/(?P<name>[a-zA-Z]+)", user.DeleteUser) //delete user's profile and associations
		// r.Patch("/(?P<name>[a-zA-Z]+)", user.UpdateUser) //update user's profile
	})

	m.Run()

}
开发者ID:4nthem,项目名称:State,代码行数:34,代码来源:server.go


示例20: main

func main() {
	m := martini.Classic()
	m.Map(SetupDB())
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
		Funcs: []template.FuncMap{
			{
				"unescaped": func(args ...interface{}) template.HTML {
					return template.HTML(args[0].(string))
				},
			},
		},
	}))

	//Sessions
	store := sessions.NewCookieStore([]byte("secret123"))
	m.Use(sessions.Sessions("vsauth", store))

	m.Get("/", IndexArticles)
	m.Get("/create", CreateArticle)
	m.Get("/read", ReadArticle)
	m.Get("/update", UpdateArticle)
	m.Get("/delete", DeleteArticle)
	m.Post("/save", SaveArticle)
	m.Get("/login", LoginForm)
	m.Post("/login", UserLogin)
	m.Get("/signup", SignupForm)
	m.Post("/signup", UserSignup)
	m.Get("/logout", UserLogout)
	m.Get("/wrong", WrongLogin)

	m.Run()
}
开发者ID:qapi,项目名称:goblog-playground,代码行数:33,代码来源:main.go



注:本文中的github.com/martini-contrib/render.Renderer函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang render.Render类代码示例发布时间:2022-05-23
下一篇:
Golang oauth2.Tokens类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap