當前位置: 首頁>>代碼示例>>Golang>>正文


Golang render.Renderer函數代碼示例

本文整理匯總了Golang中github.com/martini-contrib/render.Renderer函數的典型用法代碼示例。如果您正苦於以下問題:Golang Renderer函數的具體用法?Golang Renderer怎麽用?Golang Renderer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Renderer函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/martini-contrib/render.Renderer函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。