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


Golang render.Renderer函數代碼示例

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


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

示例1: main

func main() {
	githubAccessToken := os.Getenv("GITHUB_ACCESS_TOKEN")
	if githubAccessToken == "" {
		fmt.Println("Create new tokens via https://github.com/settings/applications 'Personal Access Tokens' section")
		log.Fatalln("Please set environment variable $GITHUB_ACCESS_TOKEN")
	}
	t := &oauth.Transport{
		Token: &oauth.Token{AccessToken: githubAccessToken},
	}

	client = github.NewClient(t.Client())

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

	m.Get("/github/:org/:repo/pull/(?P<pull_id>\\d+).(?P<badge_type>(svg|png|json))", prBadgeHandler)
	m.Get("/github/:org/:repo/pull/:pull_id", prRedirectHandler)
	m.Get("/github/:org/:repo/issues/(?P<issue_id>\\d+).(?P<badge_type>(svg|png|json))", issueBadgeHandler)
	m.Get("/github/:org/:repo/issues/:issue_id", issueRedirectHandler)

	// Redirect to blog post for any other route (e.g. root route) until some human website implemented
	m.NotFound(func(render render.Render) {
		render.Redirect("https://blog.starkandwayne.com/2014/12/30/live-github-pr-status-in-your-blogs-docs/")
	})
	m.Run()
}
開發者ID:doct15,項目名稱:github-shields,代碼行數:26,代碼來源:main.go

示例2: main

func main() {

	siteMap = NewDefaultSiteMap()

	m := martini.Classic()
	m.Use(render.Renderer(render.Options{
		Layout: "master",
	}))

	m.Get("/favicon.ico", func() {})
	m.Get("/:lang/contact", contactHandler)
	m.Get("/:lang/search", searchHandler)
	// handler for atom and rss feeds.
	m.Get("/:lang/feed/:feed/**.xml", feedHandler)

	m.Get("/", markdownHandler)
	m.Get("/:lang", markdownHandler)
	m.Get("/:lang/**", markdownHandler)

	m.Post("", siteWebhookHandler)

	go RebuildSearchIndex(siteMap.GetPages())
	// RunEditor(siteMap, "3001")
	m.Run()
}
開發者ID:harboe,項目名稱:flsmidth,代碼行數:25,代碼來源:main.go

示例3: InitServer

func InitServer() *martini.ClassicMartini {
	envFileName := martini.Env + ".env"
	err := godotenv.Load(envFileName)
	if err != nil {
		log.Fatalf("Error loading: %s", envFileName)
	}

	m := martini.Classic()
	m.Map(db.Connect())

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

	m.Get("/", func(r render.Render) {
		r.HTML(200, "home", "")
	})
	m.Get("/api/projects", controllers.ProjectIndex)
	m.Get("/api/projects/new", controllers.ProjectNew)
	m.Get("/api/projects/:id", controllers.ProjectGet)
	m.Post("/api/projects", binding.Bind(models.Project{}), controllers.ProjectCreate)
	m.Put("/api/projects/:id", binding.Bind(models.Project{}), controllers.ProjectUpdate)
	m.Delete("/api/projects/:id", controllers.ProjectDelete)

	return m
}
開發者ID:jerryclinesmith,項目名稱:notabbble,代碼行數:26,代碼來源:server.go

示例4: main

func main() {
	fmt.Println("fmt included for debug. remove for production.")
	m := martini.Classic()
	m.Use(render.Renderer(render.Options{
		Directory:  "template",
		Layout:     "layout",
		Extensions: []string{".html"},
	}))

	m.Get("/", func(r render.Render) {
		random_string := RandomString(10, 30)
		r.HTML(200, "main", "/d/"+random_string)
	})

	/* Main route handles incoming ** from user */
	m.Get("/d/**", func(params martini.Params, r render.Render) {
		/* Execute ruby script to parse the command */
		cmd := exec.Command("ruby", "./interpreter/parser.rb", string(params["_1"]))
		translation, _ := cmd.Output()
		data := struct {
			URL_string string
			JS_string  string
		}{
			params["_1"],
			string(translation),
		}
		r.HTML(200, "d", data)
	})

	m.Run()
}
開發者ID:raymondjacobson,項目名稱:seedot,代碼行數:31,代碼來源:server.go

示例5: main

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

	// render middleware
	// https://github.com/codegangsta/martini-contrib/tree/master/render
	m.Use(render.Renderer(render.Options{
		Directory: ".",
	}))

	// This will set the Content-Type header to "text/html; charset=UTF-8"
	m.Get("/wishes", func(r render.Render) {
		r.HTML(200, "martini-02", nil)
	})

	// This will set the Content-Type header to "text/html; charset=UTF-8"
	m.Get("/text", func(r render.Render) {
		r.HTML(200, "hello", "world")
	})

	// This will set the Content-Type header to "application/json; charset=UTF-8"
	m.Get("/json", func(r render.Render) {
		r.JSON(200, map[string]interface{}{"hello": "world"})
	})

	m.Run()
}
開發者ID:jancarloviray,項目名稱:go-adventures,代碼行數:26,代碼來源:martini-02.go

示例6: init

func init() {
	cfg := new(config)
	in, err := ioutil.ReadFile("config.yaml")
	if err != nil {
		log.Fatal(err)
	}
	err = goyaml.Unmarshal(in, cfg)
	if err != nil {
		log.Fatal(err)
	}

	flag.Parse()
	log.SetOutputLevel(log.Ldebug)

	if *environment == "development" {
		opts = &cfg.Development
	} else {
		opts = &cfg.Production
	}

	fmt.Println("== environment:", *environment, "==")
	utils.Dump(opts)

	conf.ACCESS_KEY = opts.AccessKey
	conf.SECRET_KEY = opts.SecretKey

	// render html templates from templates directory
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))
	InitRouter()
}
開發者ID:matm,項目名稱:gobuild,代碼行數:32,代碼來源:main.go

示例7: Route

func Route(m *martini.ClassicMartini) {
	m.Use(render.Renderer())

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

	//post handlers
	Signup(m)
	Signin(m)

	m.Get("/inspect", func() string {
		return "Hello inspect!"
	})
	m.Get("/add", func() string {
		return "Hello add!"
	})

	m.Post("/inspect", func() string {
		return "Hello inspect!"
	})
	m.Post("/add", func() string {
		return "Hello add!"
	})
}
開發者ID:philsong,項目名稱:sublime_words,代碼行數:25,代碼來源:routes.go

示例8: main

func main() {
	var port int
	flag.IntVar(&port, "port", 3001, "server port")
	flag.Parse()
	fmt.Println("Port: ", port)

	endpoint := "unix:///var/run/docker.sock"
	var err error
	client, err = docker.NewClient(endpoint)
	if err != nil {
		panic(err)
	}

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

	m.Get("/", func(r render.Render) {
		r.JSON(http.StatusOK, getSystemMonitorSample())
	})

	m.Get("/:name", func(args martini.Params, r render.Render) {
		name := args["name"]
		sample, err := getContainerMonitorSample(name)
		if err == nil {
			r.JSON(http.StatusOK, sample)
		} else {
			r.JSON(http.StatusBadRequest, err)
		}
	})

	http.Handle("/", m)
	http.ListenAndServe(":"+strconv.Itoa(port), nil)
}
開發者ID:kjellski,項目名稱:platform-monitoring,代碼行數:33,代碼來源:monitoring.go

示例9: main

func main() {

	m := martini.Classic()
	// specify the layout to use when rendering HTML
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))
	// use the Mongo middleware
	m.Use(DB())

	// list of all cribs
	m.Get("/", func(r render.Render, db *mgo.Database) {
		r.HTML(200, "list", All(db))
	})

	/*
	   create a new crib the form submission. Contains some martini magic. The call
	   to binding.Form(Crib{}) parses out form data when the request comes in.
	   It binds the data to the struct, maps it to the request context  and
	   injects into our next handler function to insert into Mongodb.
	*/
	m.Post("/", binding.Form(Crib{}), func(crib Crib, r render.Render, db *mgo.Database) {
		db.C("cribs").Insert(crib)
		r.HTML(200, "list", All(db))
	})

	// display the crib for a specific user
	m.Get("/:handle", func(params martini.Params, r render.Render, db *mgo.Database) {
		r.HTML(200, "display", Fetch(db, params["handle"]))
	})

	http.ListenAndServe(":8080", m)

}
開發者ID:JC1738,項目名稱:cribs,代碼行數:34,代碼來源:server.go

示例10: main

func main() {
	m := martini.Classic()
	dbMap := initDb()
	m.Map(dbMap)
	store := sessions.NewCookieStore([]byte("nonotestetstsst"))
	m.Use(sessions.Sessions("gogonki", store))
	m.Use(render.Renderer())
	m.Get("/", Index)

	m.Get("/coords", Coords)
	m.Get("/move/:x/:y", Move) // ToDo: make this post request
	m.Get("/state", GetState)
	m.Get("/profile", ShowProfile)
	m.Get("/login", LoginForm)
	m.Post("/login", Login)
	m.Get("/logout", Logout)
	m.Post("/create", binding.Bind(User{}), CreateUser)
	m.Get("/signup", SignupForm)
	m.Post("/signup", Signup)
	m.Post("/create-room", CreateRoom)
	m.Post("/list-rooms", ListRooms)

	//m.Use(Auth)
	m.Run()
}
開發者ID:kilatev,項目名稱:GoGonki,代碼行數:25,代碼來源:server.go

示例11: main

func main() {
	fs, err := filestore.New("s3")
	if err != nil {
		log.Fatal(err)
	}

	port := os.Getenv("PORT")
	m := martini.Classic()
	m.Map(fs)
	m.Use(martini.Static("../web/public"))
	m.Use(render.Renderer(render.Options{
		Directory: "../web/templates",
		Layout:    "layout",
	}))
	m.Get("/", func(fs *filestore.S3, r render.Render) {
		files, err := fs.List("builds")
		sort.Sort(ByTime(files))
		if err != nil {
			log.Fatal(err)
		}

		r.HTML(200, "home", files)
	})

	log.Printf("starting server at %s", port)
	err = http.ListenAndServe(":"+port, m)
	if err != nil {
		log.Fatal(err)
	}
}
開發者ID:jingweno,項目名稱:travisarchive,代碼行數:30,代碼來源:main.go

示例12: main

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

	m.Use(render.Renderer(render.Options{
		Directory:  "templates",
		Layout:     "layout",
		Extensions: []string{".html"},
		Delims:     render.Delims{"{[{", "}]}"},
		Funcs: []template.FuncMap{
			{
				"formatTime": func(args ...interface{}) string {
					t1 := time.Unix(args[0].(int64), 0)
					return t1.Format(time.Stamp)
				},
				"unescaped": func(args ...interface{}) template.HTML {
					return template.HTML(args[0].(string))
				},
			},
		},
	}))

	newmap := map[string]interface{}{}

	m.Use(martini.Static("assets"))
	m.Get("/", func(args martini.Params, r render.Render) string {
		r.HTML(200, "index", newmap)
		return ""
	})

	m.Run()
}
開發者ID:rgbchris,項目名稱:Farkle--Go-Angular-,代碼行數:31,代碼來源:server.go

示例13: main

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

	m.Use(render.Renderer(render.Options{
		Directory: "templates",
		Layout:    "layout",
		Funcs: []template.FuncMap{
			{
				"formatTime": func(args ...interface{}) string {
					t1 := time.Unix(args[0].(int64), 0)
					return t1.Format(time.Stamp)
				},
				"unescaped": func(args ...interface{}) template.HTML {
					return template.HTML(args[0].(string))
				},
			},
		},
	}))

	m.Get("/", func(r render.Render) {
		d := map[string]interface{}{"title": "Main", "message": "SUCCESS!"}
		r.HTML(200, "main", d)
	})

	m.Run()
}
開發者ID:mickep76,項目名稱:go-sampleapp-docker,代碼行數:26,代碼來源:main.go

示例14: main

func main() {
	m := martini.Classic()
	m.Use(render.Renderer())

	m.Get("/", func(r render.Render) {
		data := map[string]interface{}{}
		data["name"] = "Example Website"
		data["content"] = "Welcome home."
		data["title"] = "Home"
		r.HTML(200, "main", data)
	})
	m.Get("/about", func(r render.Render) {
		data := map[string]interface{}{}
		data["name"] = "Example Website"
		data["content"] = "About us."
		data["title"] = "About"
		r.HTML(200, "main", data)
	})
	m.Get("/contact", func(r render.Render) {
		data := map[string]interface{}{}
		data["name"] = "Example Website"
		data["content"] = "Contact us."
		data["title"] = "Contact"
		r.HTML(200, "main", data)
	})

	m.Run()
}
開發者ID:ctate,項目名稱:martini,代碼行數:28,代碼來源:server.go

示例15: main

func main() {
	//go ServeWebsocket()
	m := martini.Classic()
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))
	m.Use(martini.Static("assets"))

	m.Get("/", func(r render.Render) {
		r.HTML(200, "index", "index")
	})
	// api group
	m.Group("/api", func(r martini.Router) {
		r.Post("/log", binding.Bind(Log{}), NewLog)
		r.Get("/log/:appname", func(args martini.Params, r render.Render) {
			logs, err := GetLogForApp(args["appname"])
			if err != nil {
				r.JSON(200, map[string]interface{}{})
			}
			r.JSON(200, logs)
		})
	})

	//websocket
	m.Get("/sock/:appname", socketHandler)
	m.Run()
}
開發者ID:gnicod,項目名稱:rektEx,代碼行數:27,代碼來源:main.go


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