当前位置: 首页>>代码示例>>Golang>>正文


Golang loghttp.E函数代码示例

本文整理汇总了Golang中github.com/pbberlin/tools/net/http/loghttp.E函数的典型用法代码示例。如果您正苦于以下问题:Golang E函数的具体用法?Golang E怎么用?Golang E使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了E函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: imagefileAsBase64

// output static file as base64 string
//   image must exist as file in /static
func imagefileAsBase64(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	c := appengine.NewContext(r)

	p := r.FormValue("p")
	if p == "" {
		p = "static/chartbg_400x960__480x1040__12x10.png"
	}

	f, err := os.Open(p)
	loghttp.E(w, r, err, false)
	defer f.Close()

	img, whichFormat, err := image.Decode(f)
	loghttp.E(w, r, err, false)
	aelog.Infof(c, "format %v - subtype %T\n", whichFormat, img)

	imgRGBA, ok := img.(*image.RGBA)
	loghttp.E(w, r, ok, true, "source image was not convertible to image.RGBA - gifs or jpeg?")

	// => header with mime prefix always prepended
	//   and its always image/PNG
	str_b64 := conv.Rgba_img_to_base64_str(imgRGBA)

	w.Header().Set("Content-Type", "text/html")
	io.WriteString(w, "<p>Image embedded in HTML as Base64:</p><img width=200px src=\"")
	io.WriteString(w, str_b64)
	io.WriteString(w, "\"> ")

}
开发者ID:aarzilli,项目名称:tools,代码行数:32,代码来源:img+direct+or+base64.go

示例2: SaveEntry

func SaveEntry(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	contnt, ok := m["content"].(string)
	loghttp.E(w, r, ok, false, "need a key 'content' with a string")

	c := appengine.NewContext(r)

	g := GbsaveEntry{
		Content:           contnt,
		Date:              time.Now(),
		TypeShiftingField: 2,
	}
	if u := user.Current(c); u != nil {
		g.Author = u.String()
	}
	g.Comment1 = "comment"

	/* We set the same parent key on every GB entry entity
	   to ensure each GB entry is in the same entity group.

	   Queries across the single entity group will be consistent.
	   However, we should limit write rate to single entity group ~1/sec.

		NewIncompleteKey(appengine.Context, kind string , parent *Key)
			has neither a string key, nor an integer key
		 	only a "kind" (classname) and a parent
		Upon usage the datastore generates an integer key
	*/

	incomplete := ds.NewIncompleteKey(c, GbEntryKind, keyParent(c))
	concreteNewKey, err := ds.Put(c, incomplete, &g)
	loghttp.E(w, r, err, false)
	_ = concreteNewKey // we query entries via keyParent - via parent

}
开发者ID:aarzilli,项目名称:tools,代码行数:35,代码来源:persistence.go

示例3: makeRequest

func makeRequest(w http.ResponseWriter, r *http.Request, path string) CGI_Result {

	c := appengine.NewContext(r)
	client := urlfetch.Client(c)

	url_exe := spf(`http://%s%s%s&ts=%s`, dns_cam, path, credentials, urlParamTS())
	url_dis := spf(`http://%s%s&ts=%s`, dns_cam, path, urlParamTS())
	wpf(w, "<div style='font-size:10px; line-height:11px;'>requesting %v<br></div>\n", url_dis)
	resp1, err := client.Get(url_exe)
	loghttp.E(w, r, err, false)

	bcont, err := ioutil.ReadAll(resp1.Body)
	defer resp1.Body.Close()
	loghttp.E(w, r, err, false)

	cgiRes := CGI_Result{}
	xmlerr := xml.Unmarshal(bcont, &cgiRes)
	loghttp.E(w, r, xmlerr, false)

	if cgiRes.Result != "0" {
		wpf(w, "<b>RESPONSE shows bad mood:</b><br>\n")
		psXml := stringspb.IndentedDump(cgiRes)
		dis := strings.Trim(psXml, "{}")
		wpf(w, "<pre style='font-size:10px;line-height:11px;'>%v</pre>", dis)
	}

	if debug {
		scont := string(bcont)
		wpf(w, "<pre style='font-size:10px;line-height:11px;'>%v</pre>", scont)
	}

	return cgiRes

}
开发者ID:aarzilli,项目名称:tools,代码行数:34,代码来源:foscam.go

示例4: templatesExtend

// m contains defaults or overwritten template contents
func templatesExtend(w http.ResponseWriter, r *http.Request, subtemplates map[string]string) *tt.Template {

	var err error = nil
	tder := cloneFromBase(w, r)

	//for k,v := range furtherDefinitions{
	//	tder, err = tder.Parse( `{{define "` + k  +`"}}`   + v + `{{end}}` )
	//	loghttp.E(w,r,err,false)
	//}

	for k, v := range subtemplates {

		if len(v) > lenLff && v[0:lenLff] == PrefixLff {
			fileName := v[lenLff:]
			fcontent, err := ioutil.ReadFile("templates/" + fileName + ".html")
			loghttp.E(w, r, err, false, "could not open static template file")
			v = string(fcontent)
		}

		tder, err = tder.Parse(`{{define "` + k + `"}}` + v + `{{end}}`)
		loghttp.E(w, r, err, false)

	}

	return tder
}
开发者ID:aarzilli,项目名称:tools,代码行数:27,代码来源:tpl.go

示例5: submitUpload

func submitUpload(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	c := appengine.NewContext(r)
	uploadURL, err := blobstore.UploadURL(c, "/blob2/processing-new-upload", nil)
	loghttp.E(w, r, err, false)

	w.Header().Set("Content-type", "text/html; charset=utf-8")
	err = upload2.Execute(w, uploadURL)
	loghttp.E(w, r, err, false)
}
开发者ID:aarzilli,项目名称:tools,代码行数:10,代码来源:upload2.go

示例6: ListEntries

func ListEntries(w http.ResponseWriter,
	r *http.Request) (gbEntries []GbEntryRetr, report string) {

	c := appengine.NewContext(r)
	/* High Replication Datastore:
	Ancestor queries are strongly consistent.
	Queries spanning MULTIPLE entity groups are EVENTUALLY consistent.
	If .Ancestor was omitted from this query, there would be slight chance
	that recent GB entry would not show up in a query.
	*/
	q := ds.NewQuery(GbEntryKind).Ancestor(keyParent(c)).Order("-Date").Limit(10)
	gbEntries = make([]GbEntryRetr, 0, 10)
	keys, err := q.GetAll(c, &gbEntries)

	if fmt.Sprintf("%T", err) == fmt.Sprintf("%T", new(ds.ErrFieldMismatch)) {
		//s := fmt.Sprintf("%v %T  vs %v %T <br>\n",err,err,ds.ErrFieldMismatch{},ds.ErrFieldMismatch{})
		loghttp.E(w, r, err, true)
		err = nil // ignore this one - it's caused by our deliberate differences between gbsaveEntry and gbEntrieRetr
	}
	loghttp.E(w, r, err, false)

	// for investigative purposes,
	// we
	var b1 bytes.Buffer
	var sw string
	var descrip []string = []string{"class", "path", "key_int_guestbk"}
	for i0, v0 := range keys {
		sKey := fmt.Sprintf("%v", v0)
		v1 := strings.Split(sKey, ",")
		sw = fmt.Sprintf("key %v", i0)
		b1.WriteString(sw)
		for i2, v2 := range v1 {
			d := descrip[i2]
			sw = fmt.Sprintf(" \t %v:  %q ", d, v2)
			b1.WriteString(sw)
		}
		b1.WriteString("\n")
	}
	report = b1.String()

	for _, gbe := range gbEntries {
		s := gbe.Comment1
		if len(s) > 0 {
			if pos := strings.Index(s, "0300"); pos > 1 {
				i1 := util.Max(pos-4, 0)
				i2 := util.Min(pos+24, len(s))
				s1 := s[i1:i2]
				s1 = strings.Replace(s1, "3", "E", -1)
				report = fmt.Sprintf("%v -%v", report, s1)
			}
		}
	}

	return
}
开发者ID:aarzilli,项目名称:tools,代码行数:55,代码来源:persistence.go

示例7: templatesCompileDemo

func templatesCompileDemo(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	w.Header().Set("Content-Type", "text/html")

	funcMap := tt.FuncMap{
		"unescape": html.UnescapeString,
		"escape":   html.EscapeString,
	}

	var t_base *tt.Template
	var err error = nil

	// creating T0 - naming it - adding func map
	t_base = tt.Must(tt.New("str_T0_outmost").Funcs(funcMap).Parse(T0))
	loghttp.E(w, r, err, false)

	// adding the definition of T1 - introducing reference to T2 - undefined yet
	t_base, err = t_base.Parse(T1) // definitions must appear at top level - but not at the start
	loghttp.E(w, r, err, false)

	// create two clones
	// now both containing T0 and T1
	tc_1, err := t_base.Clone()
	loghttp.E(w, r, err, false)
	tc_2, err := t_base.Clone()
	loghttp.E(w, r, err, false)

	// adding different T2 definitions
	s_if := "{{if .}}{{.}}{{else}}no dyn data{{end}}"
	tc_1, err = tc_1.Parse("{{define `T2`}}T2-A  <br>--" + s_if + "--  {{end}}")
	loghttp.E(w, r, err, false)
	tc_2, err = tc_2.Parse("{{define `T2`}}T2-B  <br>--" + s_if + "--  {{end}}")
	loghttp.E(w, r, err, false)

	// writing both clones to the response writer
	err = tc_1.ExecuteTemplate(w, "str_T0_outmost", nil)
	loghttp.E(w, r, err, false)

	// second clone is written with dynamic data on two levels
	dyndata := map[string]string{"key1": "dyn val 1", "key2": "dyn val 2"}
	err = tc_2.ExecuteTemplate(w, "str_T0_outmost", dyndata)
	loghttp.E(w, r, err, false)

	// Note: it is important to pass the DOT
	//		 {{template "T1" .}}
	//		 {{template "T2" .key2 }}
	//						 ^
	// otherwise "dyndata" can not be accessed by the inner templates...

	// leaving T2 undefined => error
	tc_3, err := t_base.Clone()
	loghttp.E(w, r, err, false)
	err = tc_3.ExecuteTemplate(w, "str_T0_outmost", dyndata)
	// NOT logging the error:
	// loghttp.E(w, r, err, false)

}
开发者ID:aarzilli,项目名称:tools,代码行数:57,代码来源:tpl_demo1.go

示例8: cloneFromBase

// a clone factory
//  as t_base is a "app scope" variable
//  it will live as long as the application runs
func cloneFromBase(w http.ResponseWriter, r *http.Request) *tt.Template {

	// use INDEX to access certain elements
	funcMap := tt.FuncMap{
		"unescape":   html.UnescapeString,
		"escape":     html.EscapeString,
		"fMult":      fMult,
		"fAdd":       fAdd,
		"fChop":      fChop,
		"fMakeRange": fMakeRange,
		"fNumCols":   fNumCols,
		"df": func(g time.Time) string {
			return g.Format("2006-01-02 (Jan 02)")
		},
	}

	if t_base == nil {
		t_base = tt.Must(tt.New("n_page_scaffold_01").Funcs(funcMap).Parse(c_page_scaffold_01))
	}

	t_derived, err := t_base.Clone()
	loghttp.E(w, r, err, false)

	return t_derived
}
开发者ID:aarzilli,项目名称:tools,代码行数:28,代码来源:tpl.go

示例9: emailSend

func emailSend(w http.ResponseWriter, r *http.Request, m map[string]string) {

	c := appengine.NewContext(r)
	//addr := r.FormValue("email")

	if _, ok := m["subject"]; !ok {
		m["subject"] = "empty subject line"
	}

	email_thread_id := []string{"3223"}

	msg := &ae_mail.Message{
		//Sender:  "Peter Buchmann <[email protected]",
		//		Sender: "[email protected]",
		Sender: "[email protected]",
		//To:	   []string{addr},
		To: []string{"[email protected]"},

		Subject: m["subject"],
		Body:    "some_body some_body2",
		Headers: go_mail.Header{"References": email_thread_id},
	}
	err := ae_mail.Send(c, msg)
	loghttp.E(w, r, err, false, "could not send the email")

}
开发者ID:aarzilli,项目名称:tools,代码行数:26,代码来源:email_receive.go

示例10: imgServingExample3

func imgServingExample3(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	c := appengine.NewContext(r)

	p := r.FormValue("p")
	if p == "" {
		p = "static/chartbg_400x960__480x1040__12x10.png"
	}
	if p == "" {
		p = "static/pberg1.png"
	}
	// try p=static/unmodifiable_format.jpg

	// prepare a cutout rect
	var p1, p2 image.Point
	p1.X, p1.Y = 10, 60
	p2.X, p2.Y = 400, 255
	var rec image.Rectangle = image.Rectangle{Min: p1, Max: p2}

	f, err := os.Open(p)
	loghttp.E(w, r, err, false)
	defer f.Close()

	img, whichFormat, err := image.Decode(f)
	loghttp.E(w, r, err, false, "only jpeg and png are 'activated' ")
	c.Infof("serving format %v %T\n", whichFormat, img)

	switch t := img.(type) {

	default:
		loghttp.E(w, r, false, false, "internal color formats image.YCbCr and image.RGBA are understood")

	case *image.RGBA, *image.YCbCr:
		imgXFull, ok := t.(*image.RGBA)
		loghttp.E(w, r, ok, false, "image.YCbCr can not be typed to image.RGBA - this will panic")

		imgXCutout, ok := imgXFull.SubImage(rec).(*image.RGBA)
		loghttp.E(w, r, ok, false, "cutout operation failed")

		// we serve it as JPEG
		w.Header().Set("Content-Type", "image/jpeg")
		jpeg.Encode(w, imgXCutout, &jpeg.Options{Quality: jpeg.DefaultQuality})

	}

}
开发者ID:aarzilli,项目名称:tools,代码行数:46,代码来源:base+examples+3.go

示例11: GetChartDataFromDatastore

func GetChartDataFromDatastore(w http.ResponseWriter, r *http.Request, key string) *CData {

	c := appengine.NewContext(r)

	key_combi := "dsu.WrapBlob__" + key

	dsObj, err := dsu.BufGet(c, key_combi)
	loghttp.E(w, r, err, false)

	serializedStruct := bytes.NewBuffer(dsObj.VByte)
	dec := gob.NewDecoder(serializedStruct)
	newCData := new(CData) // hell, it was set to nil above - causing this "unassignable value" error
	err = dec.Decode(newCData)
	loghttp.E(w, r, err, false, "VByte was ", dsObj.VByte[:10])

	return newCData
}
开发者ID:aarzilli,项目名称:tools,代码行数:17,代码来源:chart_struct_save_and_retrieve.go

示例12: call

func call(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	// params trial: https://www.twilio.com/user/account/developer-tools/api-explorer/call-create
	// params docu:  https://www.twilio.com/docs/api/rest/making-calls
	v := url.Values{}
	v.Set("To", phoneTo)
	v.Set("From", phoneFrom)
	v.Set("Url", callbackUrl)
	v.Set("Method", "GET")
	v.Set("FallbackMethod", "GET")
	v.Set("StatusCallbackMethod", "GET")
	// v.Set("SendDigits", "32168")
	v.Set("Timeout", "4")
	v.Set("Record", "false")
	rb := *strings.NewReader(v.Encode())

	// Create Client
	// client := &http.Client{}  // local, not on appengine

	c := appengine.NewContext(r)
	// following appengine method, derived from big-query is non working:
	// config := oauth2_google.NewAppEngineConfig(c, []string{twilioURLPrefix})
	// client := &http.Client{Transport: config.NewTransport()}
	clientClassic := urlfetch.Client(c)
	//clientTwilio := twilio.NewClient(accountSid, authToken, clientClassic)  // not needed

	req, _ := http.NewRequest("POST", twilioFullURL, &rb)
	req.SetBasicAuth(accountSid, authToken)
	req.Header.Add("Accept", "application/json")
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

	resp, err := clientClassic.Do(req)
	loghttp.E(w, r, err, false, "something wrong with the http client")

	if resp.StatusCode >= 200 && resp.StatusCode < 300 {
		var data map[string]interface{}
		bodyBytes, _ := ioutil.ReadAll(resp.Body)
		err := json.Unmarshal(bodyBytes, &data)
		if err == nil {
			fmt.Println(data["sid"])
		}
		fmt.Fprintf(w, "%#v", resp)
	} else {
		loghttp.E(w, r, err, false, "twilio response not ok", resp.Status)
	}
}
开发者ID:aarzilli,项目名称:tools,代码行数:46,代码来源:twilio.go

示例13: GetImageFromDatastore

func GetImageFromDatastore(w http.ResponseWriter, r *http.Request, key string) *image.RGBA {

	c := appengine.NewContext(r)

	dsObj, err := dsu.BufGet(c, "dsu.WrapBlob__"+key)
	loghttp.E(w, r, err, false)

	s := string(dsObj.VByte)

	img, whichFormat := conv.Base64_str_to_img(s)
	aelog.Infof(c, "retrieved img from base64: format %v - subtype %T\n", whichFormat, img)

	i, ok := img.(*image.RGBA)
	loghttp.E(w, r, ok, false, "saved image needs to be reconstructible into a format png of subtype *image.RGBA")

	return i
}
开发者ID:aarzilli,项目名称:tools,代码行数:17,代码来源:image+save+and+retrieve.go

示例14: SaveChartDataToDatastore

func SaveChartDataToDatastore(w http.ResponseWriter, r *http.Request, cd CData, key string) string {

	c := appengine.NewContext(r)

	internalType := fmt.Sprintf("%T", cd)
	//buffBytes, _	 := StringToVByte(s)  // instead of []byte(s)

	// CData to []byte
	serializedStruct := new(bytes.Buffer)
	enc := gob.NewEncoder(serializedStruct)
	err := enc.Encode(cd)
	loghttp.E(w, r, err, false)

	key_combi, err := dsu.BufPut(c,
		dsu.WrapBlob{Name: key, VByte: serializedStruct.Bytes(), S: internalType}, key)
	loghttp.E(w, r, err, false)

	return key_combi
}
开发者ID:aarzilli,项目名称:tools,代码行数:19,代码来源:chart_struct_save_and_retrieve.go

示例15: imgServingExample1

func imgServingExample1(w http.ResponseWriter, r *http.Request) {

	c := appengine.NewContext(r)

	p := r.FormValue("p")
	if p == "" {
		p = "static/chartbg_400x960__480x1040__12x10.png"
	}
	if p == "" {
		p = "static/pberg1.png"
	}

	f, err := os.Open(p)
	loghttp.E(w, r, err, false)
	defer f.Close()

	mode := r.FormValue("mode")
	if mode == "" {
		mode = "direct"
	}

	if mode == "direct" {

		// file reader directly to http writer

		w.Header().Set("Content-Type", "image/png")
		c.Infof("serving directly %v \n", p)
		io.Copy(w, f)

	} else {

		// file to memory image - memory image to http writer

		img, whichFormat, err := image.Decode(f)
		loghttp.E(w, r, err, false)
		c.Infof("serving as memory image %v - format %v - type %T\n", p, whichFormat, img)

		// initially a png - we now encode it to jpg
		w.Header().Set("Content-Type", "image/jpeg")
		jpeg.Encode(w, img, &jpeg.Options{Quality: jpeg.DefaultQuality})
	}

}
开发者ID:aarzilli,项目名称:tools,代码行数:43,代码来源:base+examples+1.go


注:本文中的github.com/pbberlin/tools/net/http/loghttp.E函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。