本文整理汇总了Golang中github.com/oxtoacart/bpool.NewBufferPool函数的典型用法代码示例。如果您正苦于以下问题:Golang NewBufferPool函数的具体用法?Golang NewBufferPool怎么用?Golang NewBufferPool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewBufferPool函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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))
}
}
示例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
}
}
示例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))
}
示例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
}
示例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...))
}
}
示例6: init
func init() {
bufpool = bpool.NewBufferPool(64)
templatesDir = Dir_Templates
initTemplate()
go reloadTemplate()
}
示例7: New
func New(dir string) *Templates {
t := make_templates(dir)
return &Templates{
bpool.NewBufferPool(512),
t,
}
}
示例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
}
示例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
}
示例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))
}
}
示例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
}
示例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))
}
}
示例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")
}
}
示例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)
}
示例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)
}
}