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


Golang log.LogTrace函数代码示例

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


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

示例1: MailView

func MailView(w http.ResponseWriter, r *http.Request, ctx *Context) (err error) {
	id := ctx.Vars["id"]
	log.LogTrace("Loading Mail <%s> from Mongodb", id)

	//we need a user to sign to
	if ctx.User == nil {
		log.LogTrace("This page requires a login.")
		ctx.Session.AddFlash("This page requires a login.")
		return LoginForm(w, r, ctx)
	}

	m, err := ctx.Ds.Load(id)
	if err == nil {
		ctx.Ds.Messages.Update(
			bson.M{"id": m.Id},
			bson.M{"$set": bson.M{"unread": false}},
		)
		return RenderTemplate("mailbox/_show.html", w, map[string]interface{}{
			"ctx":     ctx,
			"title":   "Mail",
			"message": m,
		})
	} else {
		http.NotFound(w, r)
		return
	}
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:27,代码来源:handlers.go

示例2: MailAttachment

func MailAttachment(w http.ResponseWriter, r *http.Request, ctx *Context) (err error) {
	id := ctx.Vars["id"]
	log.LogTrace("Loading Attachment <%s> from Mongodb", id)

	//we need a user to sign to
	if ctx.User == nil {
		log.LogTrace("This page requires a login.")
		ctx.Session.AddFlash("This page requires a login.")
		return LoginForm(w, r, ctx)
	}

	m, err := ctx.Ds.LoadAttachment(id)
	if err != nil {
		return fmt.Errorf("ID provided is invalid: %v", err)
	}

	if len(m.Attachments) > 0 {
		at := m.Attachments[0]

		data, err := base64.StdEncoding.DecodeString(at.Body)
		if err != nil {
			return fmt.Errorf("Cannot decode attachment: %v", err)
		}

		reader := bytes.NewReader(data)
		w.Header().Set("Content-Type", at.ContentType)
		//w.Header().Set("Content-Disposition", "attachment; filename=\""+at.FileName+"\"")
		http.ServeContent(w, r, at.FileName, time.Now(), reader)
		return nil
	} else {
		http.NotFound(w, r)
		return
	}
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:34,代码来源:handlers.go

示例3: ParseSMTPMessage

// TODO support nested MIME content
func ParseSMTPMessage(m *config.SMTPMessage, hostname string, mimeParser bool) *Message {
	arr := make([]*Path, 0)
	for _, path := range m.To {
		arr = append(arr, PathFromString(path))
	}

	msg := &Message{
		Id:      bson.NewObjectId().Hex(),
		From:    PathFromString(m.From),
		To:      arr,
		Created: time.Now(),
		Ip:      m.Host,
		Unread:  true,
		Starred: false,
	}

	if mimeParser {
		msg.Content = &Content{Size: len(m.Data), Headers: make(map[string][]string, 0), Body: m.Data}
		// Read mail using standard mail package
		if rm, err := mail.ReadMessage(bytes.NewBufferString(m.Data)); err == nil {
			log.LogTrace("Reading Mail Message")
			msg.Content.Size = len(m.Data)
			msg.Content.Headers = rm.Header
			msg.Subject = MimeHeaderDecode(rm.Header.Get("Subject"))

			if mt, p, err := mime.ParseMediaType(rm.Header.Get("Content-Type")); err == nil {
				if strings.HasPrefix(mt, "multipart/") {
					log.LogTrace("Parsing MIME Message")
					MIMEBody := &MIMEBody{Parts: make([]*MIMEPart, 0)}
					if err := ParseMIME(MIMEBody, rm.Body, p["boundary"], msg); err == nil {
						log.LogTrace("Got multiparts %d", len(MIMEBody.Parts))
						msg.MIME = MIMEBody
					}
				} else {
					setMailBody(rm, msg)
				}
			} else {
				setMailBody(rm, msg)
			}
		} else {
			msg.Content.TextBody = m.Data
		}
	} else {
		msg.Content = ContentFromString(m.Data)
	}

	recd := fmt.Sprintf("from %s ([%s]) by %s (Smtpd)\r\n  for <%s>; %s\r\n", m.Helo, m.Host, hostname, msg.Id+"@"+hostname, time.Now().Format(time.RFC1123Z))
	//msg.Content.Headers["Delivered-To"]  = []string{msg.To}
	msg.Content.Headers["Message-ID"] = []string{msg.Id + "@" + hostname}
	msg.Content.Headers["Received"] = []string{recd}
	msg.Content.Headers["Return-Path"] = []string{"<" + m.From + ">"}
	return msg
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:54,代码来源:message.go

示例4: GreyMailFromAdd

func GreyMailFromAdd(w http.ResponseWriter, r *http.Request, ctx *Context) (err error) {
	id := ctx.Vars["id"]
	log.LogTrace("Greylist add mail %s", id)

	//we need a user to sign to
	if ctx.User == nil {
		log.LogWarn("Please login to add to grey list!")
		http.NotFound(w, r)
		return
	}

	// we need a user to be admin
	if ctx.User.IsSuperuser == false {
		http.NotFound(w, r)
		return
	}

	// we need to load email
	m, err := ctx.Ds.Load(id)
	if err != nil {
		log.LogTrace("Greylist mail Id not found %s", id)
		http.NotFound(w, r)
		return
	}

	e := fmt.Sprintf("%[email protected]%s", m.From.Mailbox, m.From.Domain)
	if to, _ := ctx.Ds.IsGreyMail(e, "from"); to == 0 {
		log.LogTrace("Greylist inserting mail %s", e)
		gm := data.GreyMail{
			Id:        bson.NewObjectId(),
			CreatedBy: ctx.User.Id.Hex(),
			CreatedAt: time.Now(),
			IsActive:  true,
			Email:     e,
			Local:     m.From.Mailbox,
			Domain:    m.From.Domain,
			Type:      "from",
		}

		if err = ctx.Ds.Emails.Insert(gm); err != nil {
			log.LogError("Error inserting grey list: %s", err)
			http.NotFound(w, r)
			return
		}

		return
	}

	http.NotFound(w, r)
	return
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:51,代码来源:handlers.go

示例5: Start

// Start() the web server
func Start() {
	addr := fmt.Sprintf("%v:%v", webConfig.Ip4address, webConfig.Ip4port)
	server := &http.Server{
		Addr:         addr,
		Handler:      nil,
		ReadTimeout:  60 * time.Second,
		WriteTimeout: 60 * time.Second,
	}

	// We don't use ListenAndServe because it lacks a way to close the listener
	log.LogInfo("HTTP listening on TCP4 %v", addr)
	var err error
	listener, err = net.Listen("tcp", addr)
	if err != nil {
		log.LogError("HTTP failed to start TCP4 listener: %v", err)
		// TODO More graceful early-shutdown procedure
		panic(err)
	}

	err = server.Serve(listener)
	if shutdown {
		log.LogTrace("HTTP server shutting down on request")
	} else if err != nil {
		log.LogError("HTTP server failed: %v", err)
	}
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:27,代码来源:server.go

示例6: ServeHTTP

// ServeHTTP builds the context and passes onto the real handler
func (h handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	// Create the context
	ctx, err := NewContext(req)
	if err != nil {
		log.LogError("Failed to create context: %v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	defer ctx.Close()

	// Run the handler, grab the error, and report it
	buf := new(httpbuf.Buffer)
	log.LogTrace("Web: %v %v %v %v", parseRemoteAddr(req), req.Proto, req.Method, req.RequestURI)
	err = h(buf, req, ctx)
	if err != nil {
		log.LogError("Error handling %v: %v", req.RequestURI, err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	// Save the session
	if err = ctx.Session.Save(req, buf); err != nil {
		log.LogError("Failed to save session: %v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	// Apply the buffered response to the writer
	buf.Apply(w)
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:31,代码来源:server.go

示例7: Stop

func Stop() {
	log.LogTrace("HTTP shutdown requested")
	shutdown = true
	if listener != nil {
		listener.Close()
	} else {
		log.LogError("HTTP listener was nil during shutdown")
	}
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:9,代码来源:server.go

示例8: openLogFile

// openLogFile creates or appends to the logfile passed on commandline
func openLogFile() error {
	// use specified log file
	var err error
	logf, err = os.OpenFile(*logfile, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
	if err != nil {
		return fmt.Errorf("Failed to create %v: %v\n", *logfile, err)
	}
	golog.SetOutput(logf)
	log.LogTrace("Opened new logfile")
	return nil
}
开发者ID:hiteshjoshi,项目名称:smtpd,代码行数:12,代码来源:main.go

示例9: Register

func Register(w http.ResponseWriter, req *http.Request, ctx *Context) error {
	if ctx.User != nil {
		ctx.Session.AddFlash("Already logged in")
		http.Redirect(w, req, reverse("Mails"), http.StatusSeeOther)
	}

	r := &data.LoginForm{
		Username: req.FormValue("username"),
		Password: req.FormValue("password"),
	}

	if r.Validate() {
		result := &data.User{}
		err := ctx.Ds.Users.Find(bson.M{"username": r.Username}).One(&result)
		if err == nil {
			ctx.Session.AddFlash("User already exists!")
			return RegisterForm(w, req, ctx)
		}

		u := &data.User{
			Id:          bson.NewObjectId(),
			Firstname:   req.FormValue("firstname"),
			Lastname:    req.FormValue("lastname"),
			Email:       req.FormValue("email"),
			Username:    r.Username,
			IsActive:    false,
			JoinedAt:    time.Now(),
			LastLoginIp: ctx.ClientIp,
		}
		u.SetPassword(r.Password)

		if err := ctx.Ds.Users.Insert(u); err != nil {
			ctx.Session.AddFlash("Problem registering user.")
			return RegisterForm(w, req, ctx)
		}

		if u.IsActive {
			//store the user id in the values and redirect to index
			ctx.Session.Values["user"] = u.Id.Hex()
			ctx.Session.AddFlash("Registration successful")
			http.Redirect(w, req, reverse("Mails"), http.StatusSeeOther)
			return nil
		} else {
			log.LogTrace("Registration successful")
			ctx.Session.AddFlash("Registration successful")
			return LoginForm(w, req, ctx)
		}
	} else {
		ctx.Session.AddFlash("Please fill all fields!")
		return RegisterForm(w, req, ctx)
	}

	return fmt.Errorf("Failed to register!")
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:54,代码来源:handlers.go

示例10: ParseTemplate

// ParseTemplate loads the requested template along with _base.html, caching
// the result (if configured to do so)
func ParseTemplate(name string, partial bool) (*template.Template, error) {
	cachedMutex.Lock()
	defer cachedMutex.Unlock()

	if t, ok := cachedTemplates[name]; ok {
		return t, nil
	}

	tempPath := strings.Replace(name, "/", string(filepath.Separator), -1)
	tempFile := filepath.Join(webConfig.TemplateDir, tempPath)
	log.LogTrace("Parsing template %v", tempFile)

	var err error
	var t *template.Template
	if partial {
		// Need to get basename of file to make it root template w/ funcs
		base := path.Base(name)
		t = template.New(base).Funcs(TemplateFuncs)
		t, err = t.ParseFiles(tempFile)
	} else {
		t = template.New("layout.html").Funcs(TemplateFuncs)
		// Note that the layout file must be the first parameter in ParseFiles
		t, err = t.ParseFiles(filepath.Join(webConfig.TemplateDir, "layout.html"), tempFile)
	}
	if err != nil {
		return nil, err
	}

	// Allows us to disable caching for theme development
	if webConfig.TemplateCache {
		if partial {
			log.LogTrace("Caching partial %v", name)
			cachedTemplates[name] = t
		} else {
			log.LogTrace("Caching template %v", name)
			cachedTemplates[name] = t
		}
	}

	return t, nil
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:43,代码来源:template.go

示例11: NginxHTTPAuth

// If running Nginx as a proxy, give Nginx the IP address and port for the SMTP server
// Primary use of Nginx is to terminate TLS so that Go doesn't need to deal with it.
// This could perform auth and load balancing too
// See http://wiki.nginx.org/MailCoreModule
func NginxHTTPAuth(w http.ResponseWriter, r *http.Request, ctx *Context) error {
	//log.LogTrace("Nginx Auth Client: %s", parseRemoteAddr(r))
	log.LogTrace("Nginx Auth Client IP <%s> (%s)", r.Header.Get("Client-IP"), r.Header.Get("Client-Host"))

	cfg := config.GetSmtpConfig()

	w.Header().Add("Auth-Status", "OK")
	w.Header().Add("Auth-Server", cfg.Ip4address.String())
	w.Header().Add("Auth-Port", strconv.Itoa(cfg.Ip4port))
	fmt.Fprint(w, "")
	return nil
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:16,代码来源:handlers.go

示例12: MailList

func MailList(w http.ResponseWriter, r *http.Request, ctx *Context) (err error) {
	log.LogTrace("Loading Mails from Mongodb")

	page, _ := strconv.Atoi(ctx.Vars["page"])
	limit := 25

	//we need a user to sign to
	if ctx.User == nil {
		log.LogTrace("This page requires a login.")
		ctx.Session.AddFlash("This page requires a login.")
		return LoginForm(w, r, ctx)
	}

	t, err := ctx.Ds.Total()
	if err != nil {
		http.NotFound(w, r)
		return
	}

	p := NewPagination(t, limit, page, "/mails")
	if page > p.Pages() {
		http.NotFound(w, r)
		return
	}

	messages, err := ctx.Ds.List(p.Offset(), p.Limit())
	if err == nil {
		return RenderTemplate("mailbox/_list.html", w, map[string]interface{}{
			"ctx":        ctx,
			"title":      "Mails",
			"messages":   messages,
			"end":        p.Offset() + p.Limit(),
			"pagination": p,
		})
	} else {
		http.NotFound(w, r)
		return
	}
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:39,代码来源:handlers.go

示例13: Login

func Login(w http.ResponseWriter, req *http.Request, ctx *Context) error {
	l := &data.LoginForm{
		Username: req.FormValue("username"),
		Password: req.FormValue("password"),
	}

	if l.Validate() {
		u, err := ctx.Ds.Login(l.Username, l.Password)

		if err == nil {
			//store the user id in the values and redirect to index
			log.LogTrace("Login successful for session <%v>", u.Id)
			ctx.Ds.Users.Update(
				bson.M{"_id": u.Id},
				bson.M{"$set": bson.M{"lastlogintime": time.Now(), "lastloginip": ctx.ClientIp}, "$inc": bson.M{"logincount": 1}},
			)

			if u.IsActive {
				ctx.Session.Values["user"] = u.Id.Hex()
				http.Redirect(w, req, reverse("Mails"), http.StatusSeeOther)
				return nil
			} else {
				log.LogTrace("The user is not activated")
				ctx.Session.AddFlash("Username is not activated")
				return LoginForm(w, req, ctx)
			}
		} else {
			log.LogTrace("Invalid Username/Password")
			ctx.Session.AddFlash("Invalid Username/Password")
			return LoginForm(w, req, ctx)
		}
	} else {
		ctx.Session.AddFlash("Please fill all fields!")
		return LoginForm(w, req, ctx)
	}

	return fmt.Errorf("Failed to login!")
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:38,代码来源:handlers.go

示例14: MailDelete

func MailDelete(w http.ResponseWriter, r *http.Request, ctx *Context) (err error) {
	id := ctx.Vars["id"]
	log.LogTrace("Delete Mail <%s> from Mongodb", id)

	//we need a user to sign to
	if ctx.User == nil {
		log.LogTrace("This page requires a login.")
		ctx.Session.AddFlash("This page requires a login.")
		return LoginForm(w, r, ctx)
	}

	err = ctx.Ds.DeleteOne(id)
	if err == nil {
		log.LogTrace("Deleted mail id: %s", id)
		ctx.Session.AddFlash("Successfuly deleted mail id:" + id)
		http.Redirect(w, r, reverse("Mails"), http.StatusSeeOther)
		return nil
	} else {
		http.NotFound(w, r)
		return err
	}

}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:23,代码来源:handlers.go

示例15: Status

func Status(w http.ResponseWriter, r *http.Request, ctx *Context) (err error) {
	//we need a user to sign to
	if ctx.User == nil {
		log.LogTrace("This page requires a login.")
		ctx.Session.AddFlash("This page requires a login.")
		return LoginForm(w, r, ctx)
	}

	updateSystemStatus()

	return RenderTemplate("root/status.html", w, map[string]interface{}{
		"ctx":       ctx,
		"SysStatus": sysStatus,
	})
}
开发者ID:jmcarbo,项目名称:smtpd-1,代码行数:15,代码来源:handlers.go


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