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


Golang config.Get函数代码示例

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


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

示例1: handleVerify

func (h *Handler) handleVerify(w http.ResponseWriter, r *http.Request) {
	segments := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
	vid := segments[2]

	u, err := user.Verify(vid)
	if err != nil {
		logger.Error(w, err)
		h.serveServerError(w, r)
		return
	}

	s, err := session.New(u)
	if err != nil {
		logger.Error(w, err)
		h.serveServerError(w, r)
		return
	}

	// Drop cookie
	err = s.Save(w, true)
	if err != nil {
		logger.Error(w, err)
		h.serveServerError(w, r)
		return
	}

	url := fmt.Sprintf("%s/u/%s", config.Get("baseurl"), u.Username)
	http.Redirect(w, r, url, http.StatusFound)
}
开发者ID:mehulsbhatt,项目名称:go-timesheet,代码行数:29,代码来源:handler.go

示例2: handleUserPassword

func (h *Handler) handleUserPassword(w http.ResponseWriter, r *http.Request) {
	segments := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
	username := segments[2]

	s, err := session.Parse(r)
	if err != nil {
		http.Redirect(w, r, fmt.Sprintf("%s/u/%s",
			config.Get("baseurl"), username), http.StatusFound)
		return
	}

	if s.User.Username != username {
		http.Redirect(w, r, fmt.Sprintf("%s/u/%s",
			config.Get("baseurl"), username), http.StatusFound)
		return
	}

	msg, _ := flashdata.Get(w, r)

	m := map[string]interface{}{
		"baseurl": config.Get("baseurl"),
		"session": s,
		"message": msg,
	}

	h.Templates.ExecuteTemplate(w, "user_update_password.html", m)
}
开发者ID:mehulsbhatt,项目名称:go-timesheet,代码行数:27,代码来源:handler.go

示例3: handleClientNew

func (h *Handler) handleClientNew(w http.ResponseWriter, r *http.Request) {
	segments := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
	username := segments[2]

	s, err := session.Parse(r)
	if err != nil {
		http.Redirect(w, r, fmt.Sprintf("%s/u/%s",
			config.Get("baseurl"), username), http.StatusFound)
		return
	}

	if s.User.Username != username {
		http.Redirect(w, r, fmt.Sprintf("%s/u/%s",
			config.Get("baseurl"), username), http.StatusFound)
		return
	}

	m := map[string]interface{}{
		"baseurl": config.Get("baseurl"),
		"session": s,
		"form": map[string]string{
			"email":    s.User.Email,
			"fullname": s.User.Fullname,
		},
	}

	h.Templates.ExecuteTemplate(w, "user_new_client.html", m)
}
开发者ID:mehulsbhatt,项目名称:go-timesheet,代码行数:28,代码来源:handler.go

示例4: allowed

func allowed() bool {
	if check {
		ok := strings.ToLower(config.Get("logging"))
		allow = (ok == "true" || ok == "on" || ok == "1")
		header = config.Get("response_header")
		check = false
	}
	return allow
}
开发者ID:mehulsbhatt,项目名称:go-timesheet,代码行数:9,代码来源:logger.go

示例5: handleNewPost

func (h *Handler) handleNewPost(w http.ResponseWriter, r *http.Request) {
	username := strings.TrimSpace(r.FormValue("username"))
	email := strings.TrimSpace(r.FormValue("email"))
	password := strings.TrimSpace(r.FormValue("password"))

	// Validate
	v := validation.New()
	if v.Required("username", username, "username is required") {
		v.Username("username", username, "invalid username")
	}
	if v.Required("email", email, "email is required") {
		v.Email("email", email, "invalid email")
	}
	v.Required("password", password, "password is required")

	if len(v.Errors) == 0 {
		err := user.Add(username, email, password)
		if err == nil {
			msg := `
                Account created.
                Please check your email for your verification link
            `

			flashdata.Set(w, msg)

			url := fmt.Sprintf("%s/message", config.Get("baseurl"))
			http.Redirect(w, r, url, http.StatusFound)

			return
		} else {
			if err.Error() == "UNIQUE constraint failed: user.username" {
				v.Errors["username"] = "username already exists"
			} else if err.Error() == "UNIQUE constraint failed: user.email" {
				v.Errors["email"] = "email already exists"
			} else {
				logger.Error(w, err)
				h.serveServerError(w, r)
				return
			}
		}
	}

	m := map[string]interface{}{
		"baseurl": config.Get("baseurl"),
		"form": map[string]string{
			"username": username,
			"email":    email,
		},
		"errors": v.Errors,
	}

	h.Templates.ExecuteTemplate(w, "new.html", m)
}
开发者ID:mehulsbhatt,项目名称:go-timesheet,代码行数:53,代码来源:handler.go

示例6: handleUserUpdatePost

func (h *Handler) handleUserUpdatePost(w http.ResponseWriter, r *http.Request) {
	segments := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
	username := segments[2]

	s, err := session.Parse(r)
	if err != nil {
		http.Redirect(w, r, fmt.Sprintf("%s/u/%s",
			config.Get("baseurl"), username), http.StatusFound)
		return
	}

	if s.User.Username != username {
		http.Redirect(w, r, fmt.Sprintf("%s/u/%s",
			config.Get("baseurl"), username), http.StatusFound)
		return
	}

	email := strings.TrimSpace(r.FormValue("email"))
	fullname := strings.TrimSpace(r.FormValue("fullname"))

	// Validate
	v := validation.New()
	if v.Required("email", email, "email is required") {
		v.Email("email", email, "invalid email")
	}

	if len(v.Errors) == 0 {
		err = s.User.Update(email, fullname)
		if err != nil {
			logger.Error(w, err)
			h.serveServerError(w, r)
			return
		}
		flashdata.Set(w, "Profile updated")
		http.Redirect(w, r, fmt.Sprintf("%s/u/%s", config.Get("baseurl"),
			s.User.Username), http.StatusFound)
		return
	}

	m := map[string]interface{}{
		"baseurl": config.Get("baseurl"),
		"session": s,
		"form": map[string]string{
			"email":    email,
			"fullname": fullname,
		},
		"errors": v.Errors,
	}

	h.Templates.ExecuteTemplate(w, "user_update.html", m)
}
开发者ID:mehulsbhatt,项目名称:go-timesheet,代码行数:51,代码来源:handler.go

示例7: loadTemplates

func loadTemplates() {
	if Templates == nil {
		t, _ := template.ParseGlob(
			filepath.Join(config.Get("email"), "*.*"))
		Templates = t
	}
}
开发者ID:mehulsbhatt,项目名称:go-timesheet,代码行数:7,代码来源:user.go

示例8: handleLogout

func (h *Handler) handleLogout(w http.ResponseWriter, r *http.Request) {
	s, _ := session.Parse(r)
	if s != nil {
		s.Save(w, false)
	}
	http.Redirect(w, r, config.Get("baseurl"), http.StatusFound)
}
开发者ID:mehulsbhatt,项目名称:go-timesheet,代码行数:7,代码来源:handler.go

示例9: handleNew

func (h *Handler) handleNew(w http.ResponseWriter, r *http.Request) {
	m := map[string]interface{}{
		"baseurl": config.Get("baseurl"),
	}

	h.Templates.ExecuteTemplate(w, "new.html", m)
}
开发者ID:mehulsbhatt,项目名称:go-timesheet,代码行数:7,代码来源:handler.go

示例10: Row

func Row(q string, params []interface{}, bind []interface{}) error {
	db, err := sql.Open("sqlite3", config.Get("dbf"))
	if err != nil {
		return err
	}
	defer db.Close()

	stmt, err := db.Prepare(q)
	if err != nil {
		return err
	}
	defer stmt.Close()

	row := stmt.QueryRow(params...)
	if err != nil {
		return err
	}

	err = row.Scan(bind...)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:mehulsbhatt,项目名称:go-timesheet,代码行数:25,代码来源:dao.go

示例11: Save

func (s *Session) Save(w http.ResponseWriter, keepalive bool) error {
	q := `
        UPDATE user_session SET
            valid_until = ?
            , modified_date = ?
        WHERE id = ?;
    `

	valid := int64(0)

	if keepalive {
		valid = time.Now().Unix() + SESSION_OFFSET
	}

	params := []interface{}{
		valid,
		time.Now().Unix(),
		s.Id,
	}

	_, err := dao.Exec(q, params)
	if err != nil {
		return err
	}

	expires := -1

	if keepalive {
		expires, _ = strconv.Atoi(config.Get("session_cookie_expires"))
	}

	secure, _ := strconv.ParseBool(config.Get("session_cookie_secure"))

	c := new(http.Cookie)
	c.Name = config.Get("session_cookie_name")
	if keepalive {
		c.Value = s.Key
	}
	c.Path = config.Get("session_cookie_path")
	c.MaxAge = expires
	c.Secure = secure

	http.SetCookie(w, c)
	logger.Log(w, "SET-COOKIE", c.String())
	return nil
}
开发者ID:mehulsbhatt,项目名称:go-timesheet,代码行数:46,代码来源:session.go

示例12: Set

func Set(w http.ResponseWriter, s string) {
	secure, _ := strconv.ParseBool(config.Get("session_cookie_secure"))

	c := new(http.Cookie)
	c.Name = fmt.Sprintf("%s-flash", config.Get("session_cookie_name"))
	c.Path = config.Get("session_cookie_path")
	c.Value = base64.URLEncoding.EncodeToString([]byte(strings.TrimSpace(s)))
	if c.Value != "" {
		c.MaxAge = 0
	} else {
		c.MaxAge = -1
	}
	c.Secure = secure

	http.SetCookie(w, c)
	logger.Log(w, "SET-COOKIE", c.String())
}
开发者ID:mehulsbhatt,项目名称:go-timesheet,代码行数:17,代码来源:flashdata.go

示例13: handleMessage

func (h *Handler) handleMessage(w http.ResponseWriter, r *http.Request) {
	s, ok := flashdata.Get(w, r)
	if !ok {
		http.Redirect(w, r, config.Get("baseurl"), http.StatusFound)
		return
	}

	s = strings.Replace(s, "\n", "<br>\n", -1)
	logger.Info(w, s)

	m := map[string]interface{}{
		"baseurl": config.Get("baseurl"),
		"message": template.HTML(s),
	}

	h.Templates.ExecuteTemplate(w, "message.html", m)
}
开发者ID:mehulsbhatt,项目名称:go-timesheet,代码行数:17,代码来源:handler.go

示例14: handleLoginPost

func (h *Handler) handleLoginPost(w http.ResponseWriter, r *http.Request) {
	username := strings.TrimSpace(r.FormValue("username"))
	password := strings.TrimSpace(r.FormValue("password"))

	// Validate
	v := validation.New()
	v.Required("username", username, "username is required")
	v.Required("password", password, "password is required")

	if len(v.Errors) == 0 {
		u, err := user.Login(username, password)
		if err == nil {
			s, err := session.New(u)
			if err != nil {
				logger.Error(w, err)
				h.serveServerError(w, r)
				return
			}

			err = s.Save(w, true)
			if err != nil {
				logger.Error(w, err)
				h.serveServerError(w, r)
				return
			}

			url := fmt.Sprintf("%s/u/%s", config.Get("baseurl"), u.Username)
			http.Redirect(w, r, url, http.StatusFound)
			return
		} else {
			if err.Error() == "sql: no rows in result set" {
				v.Errors["username"] = "invalid username or password"
			}
		}
	}

	m := map[string]interface{}{
		"baseurl": config.Get("baseurl"),
		"form": map[string]string{
			"username": username,
		},
		"errors": v.Errors,
	}

	h.Templates.ExecuteTemplate(w, "login.html", m)
}
开发者ID:mehulsbhatt,项目名称:go-timesheet,代码行数:46,代码来源:handler.go

示例15: serveServerError

func (h *Handler) serveServerError(w http.ResponseWriter, r *http.Request) {
	s, _ := session.Parse(r)
	m := map[string]interface{}{
		"baseurl": config.Get("baseurl"),
		"session": s,
	}
	w.WriteHeader(http.StatusInternalServerError)
	h.Templates.ExecuteTemplate(w, "error500.html", m)
}
开发者ID:mehulsbhatt,项目名称:go-timesheet,代码行数:9,代码来源:handler.go


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