Пример #1
0
func (ep *JavascriptEndpoint) Process(response http.ResponseWriter, req *http.Request) (err error) {

	script := path.Join(ep.ScriptPath, mux.Vars(req)["javascript"])

	var file *os.File

	if file, err = os.Open(script); err != nil {
		return respond.NewNotFoundError("cannot open javascript file: %s, %s", script, err)
	}
	defer file.Close()

	var fileInfo os.FileInfo

	if fileInfo, err = file.Stat(); err != nil {
		return fmt.Errorf("can't stat javascript file: %s, %s", script, err)
	} else if fileInfo.IsDir() {
		return respond.NewNotFoundError("cannot open javascript: %s is a directory", script)
	}

	var bytes []byte

	if bytes, err = ioutil.ReadAll(file); err != nil {
		return fmt.Errorf("can't read javascript file: %s, %s", script, err)
	}

	response.Header().Add("Content-Type", "application/javascript")
	response.Write(bytes)

	return nil
}
Пример #2
0
func (store *DBStore) FindUserByEmail(email string) (user *User, err error) {

	user = &User{}

	if err = store.findUserByEmailStmt.QueryRow(email).Scan(
		&user.Id,
		&user.Email,
		&user.PasswordSalt,
		&user.PasswordHash,
		&user.CreatedAt,
		&user.UpdatedAt,
	); err != nil {

		if err.Error() == "sql: no rows in result set" {
			return nil, respond.NewNotFoundError("user with email '%s'", email)
		}

		return nil, err
	}

	user.Email = strings.ToLower(user.Email)

	return
}