我是 Golang 的新手,正在从 Node.js 服务器切换到 Golang 服务器,我正在尝试重写我之前为 Node 编写的应用程序。
我想在用户登录时设置模板变量,但我不确定如何设置,是的,我试过在谷歌上搜索它。
这是我的注册用户控制器:
func (c User) RegisterUser(user_email, user_password,
user_password_confirmation, user_first_name,
user_last_name string) revel.Result {
// Validate Email
c.Validation.Required(user_email).Message("Username is required")
c.Validation.Email(user_email).Message("Email is not a valid email")
c.Validation.MinSize(user_email, 5).Message("Email must be greater than 5 characters")
// Validate Password
c.Validation.Required(user_password).Message("Password is required")
c.Validation.MinSize(user_password, 5).Message("Password must be greater than 5 characters.")
// Validate Password Confirmation
c.Validation.Required(user_password_confirmation).Message("Password Confirmation is required")
c.Validation.MinSize(user_password_confirmation, 5).Message("Password must be greater than 5 characters.")
c.Validation.Required(user_password == user_password_confirmation).Message("Your passwords do not match")
// Validate First Name
c.Validation.Required(user_first_name).Message("First Name is required")
c.Validation.MinSize(user_first_name, 3).Message("Your First Name must be greater than 3 characters")
// Validate Last Name
c.Validation.Required(user_last_name).Message("Last Name is required")
c.Validation.MinSize(user_last_name, 3).Message("Your Last Name must be greater than 3 characters")
// If anything wasn't right, set flash and display errors to user
if c.Validation.HasErrors() {
c.Validation.Keep()
c.FlashParams()
return c.Redirect(User.Register)
}
我已经读过,c.RenderArgs但它似乎没有做我想要的。
我希望能够设置用户的用户名,以便我可以在导航栏中显示它,以便他们知道他们已登录。
精慕HU
相关分类