本文整理汇总了Golang中github.com/oxtoacart/bpool.NewBufferPool函数的典型用法代码示例。如果您正苦于以下问题:Golang NewBufferPool函数的具体用法?Golang NewBufferPool怎么用?Golang NewBufferPool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewBufferPool函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Renderer
// Renderer is a Middleware that maps a render.Render service into the Martini handler chain. An single variadic render.Options
// struct can be optionally provided to configure HTML rendering. The default directory for templates is "templates" and the default
// file extension is ".tmpl".
//
// If MARTINI_ENV is set to "" or "development" then templates will be recompiled on every request. For more performance, set the
// MARTINI_ENV environment variable to "production"
func Renderer(options ...Options) martini.Handler {
opt := prepareOptions(options)
cs := prepareCharset(opt.Charset)
t := compile(opt)
compiledAmberFiles, err := compileAmberFiles(opt)
if err != nil {
panic(err)
}
// Check no name conflicts between template and amber
for n := range compiledAmberFiles {
found := t.Lookup(n)
if found != nil {
panic(fmt.Errorf("Template name conflict: \"%s\"", n))
}
}
bufpool = bpool.NewBufferPool(64)
return func(res http.ResponseWriter, req *http.Request, c martini.Context) {
var tc *template.Template
var at map[string]*template.Template
if martini.Env == martini.Dev {
// recompile for easy development
tc = compile(opt)
at, _ = compileAmberFiles(opt)
} else {
// use a clone of the initial template
tc, _ = t.Clone()
at = compiledAmberFiles
}
c.MapTo(&renderer{res, req, tc, opt, cs, at}, (*Render)(nil))
}
}
开发者ID:tobyjwebb,项目名称:render,代码行数:39,代码来源:render.go
示例2: init
func init() {
// Create buffer pool
bufpool = bpool.NewBufferPool(64)
// Get the contents of all layouts.
layoutData := make(map[string]string)
for _, lname := range layouts.AssetNames() {
d, _ := layouts.Asset(lname)
layoutData[lname] = string(d)
}
// For each template, we parse it.
templatesMap = make(map[string]*template.Template)
for _, aname := range templates.AssetNames() {
tname := filepath.Base(aname)
// Create new template with functions
tmpl := template.New(tname).Funcs(templateFuncs)
// Get the template's data
d, _ := templates.Asset(aname)
// Parse the main template, then all the layouts.
tmpl = template.Must(tmpl.Parse(string(d)))
for _, layout := range layouts.AssetNames() {
tmpl = template.Must(tmpl.Parse(layoutData[layout]))
}
// Insert
templatesMap[tname] = tmpl
}
}
开发者ID:jmptrader,项目名称:go-webapp-skeleton,代码行数:32,代码来源:util.go
示例3: main
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
bufpool = bpool.NewBufferPool(64)
if templates == nil {
templates = make(map[string]*template.Template)
}
templateFiles, err := filepath.Glob("templates/*.tmpl")
if err != nil {
log.Fatal(err)
}
for _, t := range templateFiles {
fmt.Println(filepath.Base(t))
templates[filepath.Base(t)] = template.Must(template.ParseFiles("templates/base.ghtml", t))
}
http.HandleFunc("/", homeHandler)
http.HandleFunc("/cats", catsHandler)
http.HandleFunc("/favicon.ico", faviconHandler)
http.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, r.URL.Path[1:])
})
log.Fatal(http.ListenAndServe(":9000", nil))
}
开发者ID:nicorevin,项目名称:nicorevin-ru,代码行数:27,代码来源:app.go
示例4: loadTemplates
func loadTemplates() {
if loaded {
return
}
templates = make(map[string]*template.Template)
bufpool = bpool.NewBufferPool(64)
layoutTemplates := map[string][]string{
"web/layouts/outside.html": []string{
"./web/includes/register.html",
"./web/includes/login.html",
},
"web/layouts/inside.html": []string{
"./web/includes/authorize.html",
},
}
for layout, includes := range layoutTemplates {
for _, include := range includes {
files := []string{include, layout}
templates[filepath.Base(include)] = template.Must(template.ParseFiles(files...))
}
}
loaded = true
}
开发者ID:RichardKnop,项目名称:go-oauth2-server,代码行数:28,代码来源:render.go
示例5: init
// Load templates on program initialisation
func init() {
bufpool = bpool.NewBufferPool(64)
if templates == nil {
templates = make(map[string]*template.Template)
}
templatesDir := config.Config.TemplatePath
layouts, err := filepath.Glob(templatesDir + "layouts/*.tmpl")
if err != nil {
log.Fatal(err)
}
includes, err := filepath.Glob(templatesDir + "includes/*.tmpl")
if err != nil {
log.Fatal(err)
}
// Generate our templates map from our layouts/ and includes/ directories
for _, layout := range layouts {
files := append(includes, layout)
templates[filepath.Base(layout)] = template.Must(template.ParseFiles(files...))
}
}
开发者ID:atamis,项目名称:wt3,代码行数:27,代码来源:template.go
示例6: init
func init() {
bufpool = bpool.NewBufferPool(64)
templatesDir = Dir_Templates
initTemplate()
go reloadTemplate()
}
开发者ID:shenshouer,项目名称:k8s-ui,代码行数:8,代码来源:templates.go
示例7: New
func New(dir string) *Templates {
t := make_templates(dir)
return &Templates{
bpool.NewBufferPool(512),
t,
}
}
开发者ID:zeroactual,项目名称:templates,代码行数:9,代码来源:templates.go
示例8: newAlbumJob
func newAlbumJob(album *zing.Album, out io.Writer) (*albumJob, error) {
return &albumJob{
album: album,
downloadQueue: make(chan zing.AlbumItem),
downloadSync: &sync.WaitGroup{},
zipQueue: make(chan zipFile, 2),
zipSync: &sync.WaitGroup{},
zipWriter: out,
bufferPool: bpool.NewBufferPool(12),
}, nil
}
开发者ID:Taik,项目名称:zing-mp3,代码行数:11,代码来源:main.go
示例9: newQueue
func newQueue(name string, store *Store, cfHandle *rocks.ColumnFamilyHandle, useTailing bool) *Queue {
q := &Queue{
name: name,
useTailing: useTailing,
store: store,
cfHandle: cfHandle,
bufPool: bpool.NewBufferPool(64),
}
q.initQueue()
return q
}
开发者ID:mijia,项目名称:rocksq,代码行数:11,代码来源:queue.go
示例10: Renderer
func Renderer(options ...Options) macaron.Handler {
opt := prepareOptions(options)
cs := prepareCharset(opt.Charset)
bufpool = bpool.NewBufferPool(64)
return func(res http.ResponseWriter, req *http.Request, c *macaron.Context) {
if macaron.Env == macaron.DEV {
// recompile for easy development
compile(opt)
}
c.MapTo(&renderer{res, req, templates, opt, cs}, (*Render)(nil))
}
}
开发者ID:chilts,项目名称:renders,代码行数:12,代码来源:macaron.go
示例11: New
// New a renderer with given template sets and options.
func New(opt Options, tSets []*TemplateSet) *Render {
r := &Render{
opt: opt,
templates: make(map[string]*TemplateSet),
}
if opt.UseBufPool {
r.bufPool = bpool.NewBufferPool(64)
}
for _, ts := range tSets {
r.templates[ts.name] = ts
}
r.compile()
return r
}
开发者ID:haobaozhong,项目名称:sweb,代码行数:15,代码来源:render.go
示例12: Renderer
// Renderer is a Middleware that maps a render.Render service into the Martini handler chain. An single variadic render.Options
// struct can be optionally provided to configure HTML rendering. The default directory for templates is "templates" and the default
// file extension is ".tmpl".
//
// If MARTINI_ENV is set to "" or "development" then templates will be recompiled on every request. For more performance, set the
// MARTINI_ENV environment variable to "production"
func Renderer(options ...Options) martini.Handler {
opt := prepareOptions(options)
cs := prepareCharset(opt.Charset)
t := compile(opt)
bufpool = bpool.NewBufferPool(64)
return func(res http.ResponseWriter, req *http.Request, c martini.Context) {
var tc *template.Template
if martini.Env == martini.Dev {
// recompile for easy development
tc = compile(opt)
} else {
// use a clone of the initial template
tc, _ = t.Clone()
}
c.MapTo(&renderer{res, req, tc, opt, cs}, (*Render)(nil))
}
}
开发者ID:Comdex,项目名称:render,代码行数:23,代码来源:render.go
示例13: bufmillion
// send a million documents
func bufmillion(w http.ResponseWriter, r *http.Request) {
bufpool := bpool.NewBufferPool(1024)
for i := 0; i < 10000000; i++ {
docId := i % docs.number
item := docs.docMap[docs.docList[docId]]
pw := bufpool.Get()
err := json.NewEncoder(pw).Encode(&item)
if err != nil {
log.Fatalf("Error %v", err)
}
fmt.Fprintf(w, string(pw.Bytes())) // send data to client side
bufpool.Put(pw)
fmt.Fprintf(w, "\n\n")
}
}
开发者ID:maniktaneja,项目名称:perf,代码行数:20,代码来源:server.go
示例14: init
// Get started with AppEngine
func init() {
// Buffers are used to hold page content while we build, and then release all at once
bufpool = bpool.NewBufferPool(32)
// Load the various .html templates into memory
initTemplates()
r := new(mux.Router)
r.Handle("/login/", NewAppHandler(LoginHandler))
r.Handle("/share/{id}/{urltitle}", NewAppHandler(ItemHandler))
r.Handle("/user/{username}", NewAppHandler(UserHandler))
r.Handle("/dummy", NewAppHandler(DummyHandler))
r.Handle("/comments/new", NewAppHandler(AddComment)).Methods("POST")
r.Handle("/vote", NewAppHandler(VoteHandler)).Methods("POST")
r.Handle("/", NewAppHandler(RootHandler))
http.Handle("/", r)
}
开发者ID:jwhardcastle,项目名称:trypup,代码行数:21,代码来源:app.go
示例15: main
func main() {
// Init bufferpool, used for rendering templates
bufpool = bpool.NewBufferPool(48)
// Load config file
if _, err := toml.DecodeFile("config.ini", &conf); err != nil {
log.Fatal("Couldn't parse config file: ", err)
}
// Setup remote repository
repo = newRepo(
conf.QuadStore.Endpoint,
time.Duration(conf.QuadStore.OpenTimeout)*time.Millisecond,
time.Duration(conf.QuadStore.ReadTimeout)*time.Millisecond,
)
// Parse Query bank
qBank = sparql.LoadBank(bytes.NewBufferString(queries))
// Register metrics
status = registerMetrics()
// HTTP routing
mux := http.NewServeMux()
var handler mainHandler
mux.HandleFunc("/robots.txt", serveFile("data/robots.txt"))
mux.HandleFunc("/css/styles.css", serveFile("data/css/styles.css"))
mux.HandleFunc("/favicon.ico", serveFile("data/favicon.ico"))
mux.HandleFunc("/.status", statusHandler)
mux.HandleFunc("/literals", literalsHandler)
mux.Handle("/", Timed(CountedByStatusXX(handler, "status", metrics.DefaultRegistry),
"responseTime",
metrics.DefaultRegistry))
fmt.Printf("Listening on port %d ...\n", conf.ServePort)
err := http.ListenAndServe(fmt.Sprintf(":%d", conf.ServePort), handlers.CompressHandler(mux))
if err != nil {
log.Println(err)
}
}
开发者ID:knakk,项目名称:fenster,代码行数:40,代码来源:fenster.go
示例16: NewTemplateManager
func NewTemplateManager(rootDir string) *TemplateManager {
tm := &TemplateManager{}
tm.bufpool = bpool.NewBufferPool(64)
tm.rootDir = rootDir
tm.functions = template.FuncMap{
"time": func(value string) template.HTML {
t, err := time.ParseInLocation("2006-01-02 15:04:05", value, time.Local)
if err != nil {
return template.HTML("(invalid date given)")
}
// get timezone information
iso := t.Format("2006-01-02T15:04:05-0700")
pretty := t.Format("Mon, Jan 2 2006 15:04")
return template.HTML("<time class=\"rel\" datetime=\"" + iso + "\">" + pretty + "</time>")
},
"shorten": func(value string, maxlen int) string {
length := len(value)
if length <= maxlen {
return value
}
halfs := maxlen / 2
runes := []rune(value)
return fmt.Sprintf("%s…%s", string(runes[:halfs]), string(runes[(length-halfs):]))
},
}
tm.Init()
return tm
}
开发者ID:xrstf,项目名称:raziel,代码行数:37,代码来源:templates.go
示例17: NewBaseHandler
//NewBaseHandler is the BaseHandler constructor
func NewBaseHandler(l *logrus.Logger, c *app.Config, tpls map[string]*template.Template, cookieHandler *securecookie.SecureCookie) *BaseHandler {
return &BaseHandler{Logr: l, Config: c, Templates: tpls, bufpool: bpool.NewBufferPool(64), cookieH: cookieHandler}
}
开发者ID:PayPal-OpportunityHack-BLR-2015,项目名称:bloodcare-hifx,代码行数:4,代码来源:base.go
示例18:
package app
import (
"html/template"
"log"
"net/http"
"github.com/oxtoacart/bpool"
)
var bufpool = bpool.NewBufferPool(64)
var templateMap = map[string]*template.Template{
"url-index": createTemplate("templates/base.html", "templates/url-index.html"),
"url-new": createTemplate("templates/base.html", "templates/url-new.html"),
"url-view": createTemplate("templates/base.html", "templates/url-view.html"),
"url-edit": createTemplate("templates/base.html", "templates/url-edit.html"),
"tag-index": createTemplate("templates/base.html", "templates/tag-index.html"),
"settings": createTemplate("templates/base.html", "templates/settings.html"),
"shitbucket-import": createTemplate("templates/base.html", "templates/shitbucket-import.html"),
"registration": createTemplate("templates/config-base.html", "templates/register.html"),
"login": createTemplate("templates/config-base.html", "templates/login.html"),
"404": createTemplate("templates/config-base.html", "templates/404.html"),
}
var templateFuncs = template.FuncMap{
"reverse": reverse,
"isyoutube": isYoutube,
"youtubevid": youtubevid,
"newcontext": newcontext,
}
开发者ID:kyleterry,项目名称:sufr,代码行数:31,代码来源:template.go
示例19: testServer
"github.com/Unknwon/com"
"github.com/gernest/zedlist/modules/tmpl"
userAuth "github.com/gernest/zedlist/middlewares/auth"
"github.com/gernest/zedlist/middlewares/flash"
"github.com/gernest/zedlist/middlewares/i18n"
"github.com/gernest/zedlist/routes/auth"
"github.com/labstack/echo"
"github.com/oxtoacart/bpool"
)
var ts = testServer()
var client = &http.Client{Jar: getJar()}
var dashPath = fmt.Sprintf("%s/dash", ts.URL)
var bufPool = bpool.NewBufferPool(10)
func testServer() *httptest.Server {
e := echo.New()
e.SetRenderer(tmpl.NewRenderer())
// middlewares
e.Use(i18n.Langs()) // languages
e.Use(flash.Flash()) // flash messages
e.Use(userAuth.Normal()) // adding user context data
// BASE
// DASHBOARD
d := e.Group("/dash")
d.Get("/", Home)
开发者ID:jwulf,项目名称:zedlist,代码行数:30,代码来源:dashboard_test.go
示例20: NewBaseHandler
//NewBaseHandler is the BaseHandler constructor
func NewBaseHandler(l *logrus.Logger, c *app.Config) *BaseHandler {
return &BaseHandler{Logr: l, Config: c, bufpool: bpool.NewBufferPool(64)}
}
开发者ID:PayPal-OpportunityHack-BLR-2015,项目名称:bloodcare-hifx,代码行数:4,代码来源:base.go
注:本文中的github.com/oxtoacart/bpool.NewBufferPool函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论