本文整理汇总了Golang中github.com/pbberlin/tools/net/http/loghttp.BuffLoggerUniversal函数的典型用法代码示例。如果您正苦于以下问题:Golang BuffLoggerUniversal函数的具体用法?Golang BuffLoggerUniversal怎么用?Golang BuffLoggerUniversal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BuffLoggerUniversal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: MimeFromBase64
// we want to extract the 'image/png' from
// "data:image/png;base64,..."
//func MimeFromBase64(b *bytes.Buffer)(mime string){
func MimeFromBase64(b io.Reader) (mime string) {
lg, b := loghttp.BuffLoggerUniversal(nil, nil)
_ = b
// to avoid huge string allocation
// we read the first 100 bytes
b1 := make([]byte, 100)
_, err := b.Read(b1)
lg(err)
s := string(b1)
pos := base64HeaderPosition(s)
if pos > 0 {
tmp1 := s[:pos]
tmp2 := strings.Split(tmp1, ";")
tmp3 := strings.Split(tmp2[0], ":")
mime = tmp3[1]
}
return
}
开发者ID:aarzilli,项目名称:tools,代码行数:28,代码来源:conv_img_str.go
示例2: rssDoc2DirTree
func rssDoc2DirTree(w http.ResponseWriter, r *http.Request, treeX *DirTree, rssDoc RSS, domain string) {
lg, lge := loghttp.Logger(w, r)
_ = lg
if treeX == nil {
treeX = &DirTree{Name: "root1", Dirs: map[string]DirTree{}, LastFound: time.Now().Truncate(time.Minute)}
}
articleList := []FullArticle{}
for _, lpItem := range rssDoc.Items.ItemList {
t, err := time.Parse(time.RFC1123Z, lpItem.Published)
// := time.Parse("Mon, 2 Jan 2006 15:04:05 -0700", lpItem.Published)
lge(err)
articleList = append(articleList, FullArticle{Url: lpItem.Link, Mod: t})
}
lg1, _ := loghttp.BuffLoggerUniversal(w, r)
path2DirTree(lg1, treeX, articleList, domain, true)
}
开发者ID:aarzilli,项目名称:tools,代码行数:26,代码来源:5_rss_fetch.go
示例3: GetHomeTpl
func GetHomeTpl(w http.ResponseWriter, r *http.Request, title, body string) *template.Template {
if body == "" {
body = IDCardHTML + UserInfoHTML
}
lg, _ := loghttp.BuffLoggerUniversal(w, r)
bstpl := tplx.TemplateFromHugoPage(w, r)
b := new(bytes.Buffer)
fmt.Fprintf(b, tplx.ExecTplHelper(bstpl, map[string]interface{}{
// "HtmlTitle": "{{ .HtmlTitle }}", // this seems to cause problems sometimes.
"HtmlTitle": title,
"HtmlDescription": "", // reminder
"HtmlHeaders": template.HTML(Headers),
"HtmlContent": template.HTML(body),
}))
intHomeTemplate, err := template.New("home").Parse(b.String())
lg(err)
return intHomeTemplate
}
开发者ID:aarzilli,项目名称:tools,代码行数:26,代码来源:tpl_creation.go
示例4: queuePush
func queuePush(w http.ResponseWriter, r *http.Request, mx map[string]interface{}) {
lg, b := loghttp.BuffLoggerUniversal(w, r)
_ = b
c := appengine.NewContext(r)
m := map[string][]string{"counter_name": []string{nscStringKey}}
t := taskqueue.NewPOSTTask("/_ah/namespaced-counters/queue-pop", m)
taskqueue.Add(c, t, "")
c, err := appengine.Namespace(c, altNamespace)
lg(err)
taskqueue.Add(c, t, "")
io.WriteString(w, "tasks enqueued\n")
io.WriteString(w, "\ncounter values now: \n")
readBothNamespaces(w, r, mx)
io.WriteString(w, "\n\n...sleeping... \n")
time.Sleep(time.Duration(400) * time.Millisecond)
readBothNamespaces(w, r, mx)
}
开发者ID:aarzilli,项目名称:tools,代码行数:26,代码来源:namespace+taskqueue+ioWriteString.go
示例5: StringToVByte
// unused
// probably efficient enough just to call
// var bEnc []byte = []byte(sEnc)
func StringToVByte(s string) (*bytes.Buffer, *bytes.Buffer) {
lg, b := loghttp.BuffLoggerUniversal(nil, nil)
_ = b
bMsg := new(bytes.Buffer)
bDst := new(bytes.Buffer)
const chunksize = 20
lb := make([]byte, chunksize) // loop buffer
rdr := strings.NewReader(s)
for {
n1, err := rdr.Read(lb)
if err == io.EOF {
break
}
lg(err)
if n1 < 1 {
break
}
independentCopy := make([]byte, n1)
copy(independentCopy, lb)
n2, err := bDst.Write(independentCopy)
lg(err)
bMsg.WriteString(fmt.Sprintln("reading", n1, "bytes - writing", n2, "bytes: \n"))
bMsg.WriteString(fmt.Sprint(" --", string(independentCopy), "--<br>\n"))
}
return bDst, bMsg
}
开发者ID:aarzilli,项目名称:tools,代码行数:37,代码来源:image+save+and+retrieve.go
示例6: readBothNamespaces
func readBothNamespaces(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {
lg, b := loghttp.BuffLoggerUniversal(w, r)
_ = b
var c1, c2 int64
var s1, s2 string
var err error
var reset bool = false
p := r.FormValue("reset")
if p != "" {
reset = true
}
c := appengine.NewContext(r)
c1, err = agnosticReadReset(c, reset)
lg(err)
{
c, err = appengine.Namespace(c, altNamespace)
lg(err)
c2, err = agnosticReadReset(c, reset)
lg(err)
}
s1 = fmt.Sprintf("%v", c1)
s2 = fmt.Sprintf("%v", c2)
io.WriteString(w, "|"+s1+"| |"+s2+"|")
if reset {
io.WriteString(w, " and reset")
}
}
开发者ID:aarzilli,项目名称:tools,代码行数:35,代码来源:namespace+taskqueue+ioWriteString.go
示例7: searchPut
func searchPut(w http.ResponseWriter, r *http.Request) {
lg, b := loghttp.BuffLoggerUniversal(w, r)
_ = b
id := "PA6-5001"
user := &User{
Customer: "Carl Corral",
Comment: "I am <em>riled up</em> text",
Visits: 1,
LastVisit: time.Now(),
Birthday: time.Date(1968, time.May, 19, 0, 0, 0, 0, time.UTC),
}
c := appengine.NewContext(r)
index, err := search.Open("users")
lg(err)
ret_id, err := index.Put(c, id, user)
lg(err)
fmt.Fprint(w, "OK, saved "+ret_id+"\n\n")
var u2 User
err = index.Get(c, ret_id, &u2)
lg(err)
fmt.Fprint(w, "Retrieved document: ", u2)
}
开发者ID:aarzilli,项目名称:tools,代码行数:30,代码来源:fulltext_search.go
示例8: paymentSuccess
/*
https://tec-news.appspot.com/coinbase-integr/redir-success1?
order[button][description]=When and how Bitcoin decline will start.&
order[button][id]=0025d69ea925b48ba2b7adeb2a911ca2&
order[button][name]=Bitcoin Analysis&
order[button][repeat]=&
order[button][resource_path]=/v2/checkouts/4f1e5ecc-c8fc-56fc-926c-15a7eebd8314&
order[button][subscription]=false&
order[button][type]=buy_now&
order[button][uuid]=4f1e5ecc-c8fc-56fc-926c-15a7eebd8314&
order[created_at]=2015-10-26 08:03:17 -0700&
order[custom]=productID=/member/tec-news/crypto-experts-neglect-one-vital-aspect&uID=14952300052240127534&
order[event]=&
order[id]=GAB5VN36&
order[metadata]=&
order[receive_address]=myL84ofiymQpzzmJ7Foc9F2wQ4GMuSuQ3f&
order[refund_address]=mwaz3wxMbnZrBZUSZpVHr51xjQ6Swx756b&
order[resource_path]=/v2/orders/9bbf6fde-530a-53a4-bf94-d54fc3f43d40&
order[status]=completed&
order[total_btc][cents]=5600.0&
order[total_btc][currency_iso]=BTC&
order[total_native][cents]=50.0&
order[total_native][currency_iso]=EUR&
order[total_payout][cents]=0.0&
order[total_payout][currency_iso]=USD&
order[transaction][confirmations]=0&
order[transaction][hash]=ada26d75ff1e16b4febf539433d5260441171560c57adfff2ac968be37108112&
order[transaction][id]=562e40dede472f26be000018&
order[uuid]=9bbf6fde-530a-53a4-bf94-d54fc3f43d40
*/
func paymentSuccess(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {
r.Header.Set("X-Custom-Header-Counter", "nocounter")
lg, _ := loghttp.BuffLoggerUniversal(w, r)
err := r.ParseForm()
if err != nil {
lg(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
custom := r.Form.Get("order[custom]")
// w.Write([]byte("custom=" + custom + "<br>\n"))
values, err := url.ParseQuery(custom)
if err != nil {
lg(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
productID := values.Get("productID")
uID := values.Get("uID")
if productID != "" {
lg("about to redirect to %v", productID)
http.Redirect(w, r, productID+"?redirected-from=paymentsucc", http.StatusFound)
return
}
w.Write([]byte("productID=" + productID + " uID=" + uID + "<br>\n"))
}
开发者ID:aarzilli,项目名称:tools,代码行数:64,代码来源:coinbase.go
示例9: Dom2File
// Dom2File writes DOM to file
func Dom2File(fn string, node *html.Node) {
lg, _ := loghttp.BuffLoggerUniversal(nil, nil)
var b bytes.Buffer
err := html.Render(&b, node)
lg(err)
Bytes2File(fn, b.Bytes())
}
开发者ID:aarzilli,项目名称:tools,代码行数:9,代码来源:file_io.go
示例10: queuePop
func queuePop(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {
lg, b := loghttp.BuffLoggerUniversal(w, r)
_ = b
c := appengine.NewContext(r)
err := agnosticIncrement(c)
c.Infof("qp")
lg(err)
}
开发者ID:aarzilli,项目名称:tools,代码行数:10,代码来源:namespace+taskqueue+ioWriteString.go
示例11: Base64_str_to_img
func Base64_str_to_img(base64_img string) (img image.Image, format string) {
lg, b := loghttp.BuffLoggerUniversal(nil, nil)
_ = b
pos := base64HeaderPosition(base64_img)
reader := base64.NewDecoder(base64.StdEncoding, strings.NewReader(base64_img[pos:]))
img, format, err := image.Decode(reader)
lg(err)
return
}
开发者ID:aarzilli,项目名称:tools,代码行数:12,代码来源:conv_img_str.go
示例12: deleteAll
func deleteAll(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {
lg, _ := loghttp.BuffLoggerUniversal(w, r)
err := r.ParseForm()
lg(err)
wpf(w, tplx.ExecTplHelper(tplx.Head, map[string]interface{}{"HtmlTitle": "Delete all filesystem data"}))
defer wpf(w, tplx.Foot)
confirm := r.FormValue("confirm")
if confirm != "yes" {
wpf(w, "All dsfs contents are deletes. All memfs contents are deleted<br>\n")
wpf(w, "Put a get param into the URL ?confirm - and set it to 'yes'<br>\n")
wpf(w, "Put a get param 'mountname' into url; i.e. mountname=mntftch<br>\n")
return
}
wpf(w, "<pre>\n")
defer wpf(w, "\n</pre>")
//
//
fs := dsfs.New(
dsfs.AeContext(appengine.NewContext(r)),
)
mountName := r.FormValue("mountname")
if mountName != "" {
wpf(w, "mountame = "+mountName+"\n")
fs = dsfs.New(
dsfs.AeContext(appengine.NewContext(r)),
dsfs.MountName(mountName),
)
}
wpf(w, "dsfs:\n")
msg, err := fs.DeleteAll()
if err != nil {
wpf(w, "err during delete %v\n", err)
}
wpf(w, msg)
memMapFileSys = memfs.New()
wpf(w, "\n")
wpf(w, "memMapFs new")
// cleanup must be manual
osFileSys = osfs.New()
}
开发者ID:aarzilli,项目名称:tools,代码行数:51,代码来源:spec_ops.go
示例13: Bytes2File
// Bytes2File writes bytes; creates path if neccessary
// and logs any errors even to appengine log
func Bytes2File(fn string, b []byte) {
lg, _ := loghttp.BuffLoggerUniversal(nil, nil)
var err error
err = ioutil.WriteFile(fn, b, 0)
if err != nil {
err = os.MkdirAll(filepath.Dir(fn), os.ModePerm)
lg(err, "directory creation failed: %v")
err = ioutil.WriteFile(fn, b, 0)
lg(err)
}
}
开发者ID:aarzilli,项目名称:tools,代码行数:17,代码来源:file_io.go
示例14: VVByte_to_string
// based on bytes.Buffer and Writing into it
func VVByte_to_string(m [][]byte) (*bytes.Buffer, *bytes.Buffer) {
lg, b := loghttp.BuffLoggerUniversal(nil, nil)
_ = b
bRet := new(bytes.Buffer)
bMsg := new(bytes.Buffer)
//for i,v := range m {
for i := 0; i < len(m); i++ {
n, err := bRet.Write(m[i])
lg(err)
bMsg.WriteString(" lp" + util.Itos(i) + ": writing " + util.Itos(n) + " bytes: \n")
}
return bRet, bMsg
}
开发者ID:aarzilli,项目名称:tools,代码行数:17,代码来源:conv_vvbyte.go
示例15: splitPort
func splitPort(hp string) string {
lg, b := loghttp.BuffLoggerUniversal(nil, nil)
_ = b
host, port, err := net.SplitHostPort(hp)
_ = port
if err != nil {
if strings.Contains(err.Error(), "missing port in address") {
// normal
} else {
lg(err)
}
host = hp
}
return host
}
开发者ID:aarzilli,项目名称:tools,代码行数:19,代码来源:util.go
示例16: String_to_VVByte
func String_to_VVByte(base64_img string) ([][]byte, *bytes.Buffer) {
lg, _ := loghttp.BuffLoggerUniversal(nil, nil)
bMsg := new(bytes.Buffer)
const chunksize = 400 //
var size_o int
if len(base64_img)%chunksize == 0 {
size_o = len(base64_img) / chunksize
} else {
size_o = len(base64_img)/chunksize + 1
}
VVByte := make([][]byte, size_o)
cntr := -1
b := make([]byte, chunksize)
rdr := strings.NewReader(base64_img)
for {
cntr++
n, err := rdr.Read(b)
if err == io.EOF {
break
}
lg(err)
if n < 1 {
break
}
indep_copy := make([]byte, n)
copy(indep_copy, b)
VVByte[cntr] = indep_copy
bMsg.WriteString("reading " + util.Itos(n) + " bytes:\n")
//bMsg.Write( VVByte[util.Itos(cntr)] )
}
return VVByte, bMsg
}
开发者ID:aarzilli,项目名称:tools,代码行数:42,代码来源:conv_vvbyte.go
示例17: incrementBothNamespaces
func incrementBothNamespaces(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {
lg, b := loghttp.BuffLoggerUniversal(w, r)
_ = b
c := appengine.NewContext(r)
err := agnosticIncrement(c)
lg(err)
{
c, err := appengine.Namespace(c, altNamespace)
lg(err)
err = agnosticIncrement(c)
lg(err)
}
s := `counters updates für ns='' and ns='ns01'.` + "\n"
io.WriteString(w, s)
readBothNamespaces(w, r, m)
}
开发者ID:aarzilli,项目名称:tools,代码行数:21,代码来源:namespace+taskqueue+ioWriteString.go
示例18: TemplateFromHugoPage
func TemplateFromHugoPage(w http.ResponseWriter, r *http.Request) string {
mp.Lock()
if tpl, ok := mp.mp[pathToTmpl]; ok {
mp.Unlock()
return tpl
}
mp.Unlock()
lg, _ := loghttp.BuffLoggerUniversal(w, r)
//
fs2 := dsfs.New(
dsfs.MountName(TplPrefix[1:]),
dsfs.AeContext(appengine.NewContext(r)),
)
fs1.SetOption(
memfs.ShadowFS(fs2),
)
bts, err := fs1.ReadFile(pathToTmpl)
if err != nil {
lg(err)
bts = hugoTplFallback
}
bts = bytes.Replace(bts, []byte("[REPLACE_TITLE]"), []byte("{{ .HtmlTitle }}"), -1)
bts = bytes.Replace(bts, []byte("[REPLACE_DESC]"), []byte("{{ .HtmlDescription }}"), -1)
bts = bytes.Replace(bts, []byte("</head>"), []byte("{{ .HtmlHeaders }}\n</head>"), -1)
bts = bytes.Replace(bts, []byte("<p>[REPLACE_CONTENT]</p>"), []byte("{{ .HtmlContent }}"), -1)
bts = bytes.Replace(bts, []byte("[REPLACE_CONTENT]"), []byte("{{ .HtmlContent }}"), -1)
bts = bytes.Replace(bts, []byte("<span id='REPLACE_FOOTER'></span>"), []byte("{{ .HtmlFooter }}"), -1)
mp.Lock()
mp.mp[pathToTmpl] = string(bts)
mp.Unlock()
return mp.mp[pathToTmpl]
}
开发者ID:aarzilli,项目名称:tools,代码行数:40,代码来源:tpl_from_dsfs.go
示例19: Test2
func Test2(t *testing.T) {
start := time.Now()
lg, b := loghttp.BuffLoggerUniversal(nil, nil)
_ = b
// closureOverBuf := func(bUnused *bytes.Buffer) {
// loghttp.Pf(nil, nil, b.String())
// }
// defer closureOverBuf(b) // the argument is ignored,
var c aetest.Context
if false {
var err error
c, err = aetest.NewContext(nil)
lg(err)
if err != nil {
return
}
defer c.Close()
}
fs := GetFS(c, 2)
lg("took1 %4.2v secs", time.Now().Sub(start).Seconds())
least3Files := FetchAndDecodeJSON(nil, URLs[0], "", lg, fs)
lg("took2 %4.2v secs", time.Now().Sub(start).Seconds())
doc := Dedup(least3Files, lg, fs)
fNamer := domclean2.FileNamer(logDir, 0)
fNamer() // first call yields key
fsPerm := GetFS(c, 2)
fileDump(lg, fsPerm, doc, fNamer, "_fin.html")
pf("MapSimiliarCompares: %v SimpleCompares: %v LevenstheinComp: %v\n", breakMapsTooDistinct, appliedLevenshtein, appliedCompare)
pf("Finish\n")
}
开发者ID:aarzilli,项目名称:tools,代码行数:40,代码来源:t2_dedup_test.go
示例20: Rgba_img_to_base64_str
// convert image to string, prepend mime header
// inspiration_1 http://stackoverflow.com/questions/22945486/golang-converting-image-image-to-byte
// inspiration_2 https://github.com/polds/imgbase64/blob/master/images.go
//
// mime type is always image/png
// because we only accept *image.RGBA and use image/png Encoder
func Rgba_img_to_base64_str(img *image.RGBA) string {
lg, b := loghttp.BuffLoggerUniversal(nil, nil)
_ = b
// img to bytes
buf := new(bytes.Buffer)
err := png.Encode(buf, img)
lg(err)
imgBytes := buf.Bytes()
// binary bytes to base64 bytes
e64 := base64.StdEncoding
maxEncLen := e64.EncodedLen(len(imgBytes))
imgEnc := make([]byte, maxEncLen)
e64.Encode(imgEnc, imgBytes)
// base64 bytes to string
mimeType := "image/png"
return fmt.Sprintf("data:%s;base64,%s", mimeType, imgEnc)
}
开发者ID:aarzilli,项目名称:tools,代码行数:28,代码来源:conv_img_str.go
注:本文中的github.com/pbberlin/tools/net/http/loghttp.BuffLoggerUniversal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论