本文整理匯總了Golang中github.com/dorajistyle/goyangi/util/log.Debugf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Debugf函數的具體用法?Golang Debugf怎麽用?Golang Debugf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Debugf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ResetPassword
// ResetPassword resets a password of user.
func ResetPassword(c *gin.Context) (int, error) {
var user model.User
var passwordResetForm PasswordResetForm
c.BindWith(&passwordResetForm, binding.Form)
if db.ORM.Where(&model.User{PasswordResetToken: passwordResetForm.PasswordResetToken}).First(&user).RecordNotFound() {
return http.StatusNotFound, errors.New("User is not found.")
}
isExpired := timeHelper.IsExpired(user.PasswordResetUntil)
log.Debugf("passwordResetUntil : %s", user.PasswordResetUntil.UTC())
log.Debugf("expired : %t", isExpired)
if isExpired {
return http.StatusForbidden, errors.New("token not valid.")
}
newPassword, err := bcrypt.GenerateFromPassword([]byte(passwordResetForm.Password), 10)
if err != nil {
return http.StatusInternalServerError, errors.New("User is not updated. Password not Generated.")
}
passwordResetForm.Password = string(newPassword)
log.Debugf("user password before : %s ", user.Password)
modelHelper.AssignValue(&user, &passwordResetForm)
user.PasswordResetToken = ""
user.PasswordResetUntil = time.Now()
log.Debugf("user password after : %s ", user.Password)
status, err := UpdateUserCore(&user)
if err != nil {
return status, err
}
status, err = SetCookie(c, user.Token)
return status, err
}
示例2: CreateFiles
// CreateFiles creates files.
func CreateFiles(c *gin.Context) (int, error) {
var forms FilesForm
start := time.Now()
c.BindWith(&forms, binding.JSON)
log.Debugf("CreateFiles c form : %v", forms)
user, _ := userService.CurrentUser(c)
sqlStrBuffer := new(bytes.Buffer)
stringHelper.Concat(sqlStrBuffer, "INSERT INTO file(user_id, name, size, created_at) VALUES ")
values := []interface{}{}
for _, file := range forms.Files {
stringHelper.Concat(sqlStrBuffer, "(?, ?, ?, ?),")
values = append(values, user.Id, file.Name, file.Size, time.Now())
}
// sqlStrBuffer.Truncate(sqlStrBuffer.Len() - 1) is slower than slice.
if len(values) > 0 {
sqlStr := sqlStrBuffer.String()
sqlStr = sqlStr[0 : len(sqlStr)-1]
log.Debugf("sqlStr for File : %s", sqlStr)
db.ORM.Exec(sqlStr, values...)
elapsed := time.Since(start)
log.Debugf("CreateFiles elapsed : %s", elapsed)
}
return http.StatusCreated, nil
}
示例3: SendPasswordResetToken
// SendPasswordResetToken sends a password reset token.
func SendPasswordResetToken(c *gin.Context) (int, error) {
var user model.User
var sendPasswordResetForm SendPasswordResetForm
var err error
log.Debugf("c.Params : %v", c.Params)
c.BindWith(&sendPasswordResetForm, binding.Form)
if db.ORM.Where(&model.User{Email: sendPasswordResetForm.Email}).First(&user).RecordNotFound() {
return http.StatusNotFound, errors.New("User is not found. Please Check the email.")
}
user.PasswordResetUntil = timeHelper.TwentyFourHoursLater()
user.PasswordResetToken, err = crypto.GenerateRandomToken16()
if err != nil {
return http.StatusInternalServerError, err
}
log.Debugf("generated token : %s", user.PasswordResetToken)
status, err := UpdateUserCore(&user)
if err != nil {
return status, err
}
err = SendEmailPasswordResetToken(user.Email, user.PasswordResetToken, "en-us")
if err != nil {
return http.StatusInternalServerError, err
}
return http.StatusOK, nil
}
示例4: RetrieveLocations
// RetrieveLocations retrieves locations.
func RetrieveLocations(c *gin.Context) ([]model.Location, bool, int, bool, bool, int, error) {
var locations []model.Location
var locationCount, locationPerPage int
filterQuery := c.Request.URL.Query().Get("filter")
locationPerPage = config.LocationPerPage
filter := &LocationFilter{}
whereBuffer := new(bytes.Buffer)
whereValues := []interface{}{}
if len(filterQuery) > 0 {
log.Debugf("retrieve Locations filter : %s\n", filterQuery)
json.Unmarshal([]byte(filterQuery), &filter)
if filter.UserId > 0 {
stringHelper.Concat(whereBuffer, "user_id = ?")
whereValues = append(whereValues, filter.UserId)
log.Debugf("userId : %d\n", filter.UserId)
}
if filter.LocationPerPage > 0 {
locationPerPage = filter.LocationPerPage
log.Debugf("locationPerPage : %d\n", filter.LocationPerPage)
}
} else {
log.Debug("no filters found.\n")
}
log.Debugf("filterQuery %v.\n", filterQuery)
log.Debugf("filter %v.\n", filter)
whereStr := whereBuffer.String()
db.ORM.Model(model.Location{}).Where(whereStr, whereValues...).Count(&locationCount)
offset, currentPage, hasPrev, hasNext := pagination.Paginate(filter.CurrentPage, locationPerPage, locationCount)
db.ORM.Limit(locationPerPage).Offset(offset).Order(config.LocationOrder).Where(whereStr, whereValues...).Find(&locations)
return locations, canUserWrite(c), currentPage, hasPrev, hasNext, http.StatusOK, nil
}
示例5: LoginOrCreateOauthUser
// LoginOrCreateOauthUser login or create with oauthUser
func LoginOrCreateOauthUser(c *gin.Context, oauthUser *OauthUser, providerID int64, token *oauth2.Token) (int, error) {
var connection model.Connection
var count int
db.ORM.Where("provider_id = ? and provider_user_id = ?", providerID, oauthUser.Id).First(&connection).Count(&count)
connection.ProviderId = providerID
connection.ProviderUserId = oauthUser.Id
connection.AccessToken = token.AccessToken
connection.ProfileUrl = oauthUser.ProfileUrl
connection.ImageUrl = oauthUser.ImageUrl
log.Debugf("connection count : %v", count)
if count == 1 {
var user model.User
if db.ORM.First(&user, "id = ?", connection.UserId).RecordNotFound() {
return http.StatusNotFound, errors.New("User is not found.")
}
log.Debugf("user : %v", user)
if db.ORM.Save(&connection).Error != nil {
return http.StatusInternalServerError, errors.New("Connection is not updated.")
}
status, err := LoginWithOauthUser(c, user.Token)
return status, err
}
log.Debugf("Connection is not exist.")
user, status, err := CreateOauthUser(c, oauthUser, &connection)
if err != nil {
return status, err
}
status, err = LoginWithOauthUser(c, user.Token)
return status, err
}
示例6: OauthGithub
// OauthGithub link connection and user.
func OauthGithub(c *gin.Context) (int, error) {
var authResponse oauth2.AuthResponse
var oauthUser OauthUser
c.BindWith(&authResponse, binding.Form)
log.Debugf("oauthRedirect form: %v", authResponse)
response, token, err := oauth2.OauthRequest(github.RequestURL, github.Config, authResponse)
if err != nil {
log.Error("get response error")
return http.StatusInternalServerError, err
}
githubUser, err := SetGithubUser(response)
if err != nil {
log.Error("SetGithubUser error")
return http.StatusInternalServerError, err
}
modelHelper.AssignValue(&oauthUser, githubUser)
oauthUser.Id = strconv.Itoa(githubUser.UserId)
log.Debugf("\noauthUser item : %v", oauthUser)
status, err := LoginOrCreateOauthUser(c, &oauthUser, github.ProviderId, token)
if err != nil {
log.Errorf("LoginOrCreateOauthUser error: %d", status)
return status, err
}
return http.StatusSeeOther, nil
}
示例7: RetrieveArticle
// RetrieveArticle retrieve an article.
func RetrieveArticle(c *gin.Context) (model.Article, bool, int64, int, error) {
var article model.Article
var count int
var currentUserId int64
var isAuthor bool
id := c.Params.ByName("id")
if db.ORM.First(&article, "id = ?", id).RecordNotFound() {
return article, isAuthor, currentUserId, http.StatusNotFound, errors.New("Article is not found.")
}
log.Debugf("Article : %s\n", article)
log.Debugf("Count : %s\n", count)
currentUser, err := userService.CurrentUser(c)
if err == nil {
currentUserId = currentUser.Id
isAuthor = currentUser.Id == article.UserId
}
assignRelatedUser(&article)
var commentList model.CommentList
comments, currentPage, hasPrev, hasNext, _ := commentService.RetrieveComments(article)
commentList.Comments = comments
commentService.SetCommentPageMeta(&commentList, currentPage, hasPrev, hasNext, article.CommentCount)
article.CommentList = commentList
var likingList model.LikingList
likings, currentPage, hasPrev, hasNext, _ := likingRetriever.RetrieveLikings(article)
likingList.Likings = likings
currentUserlikedCount := db.ORM.Model(&article).Where("id =?", currentUserId).Association("Likings").Count()
log.Debugf("Current user like count : %d", currentUserlikedCount)
likingMeta.SetLikingPageMeta(&likingList, currentPage, hasPrev, hasNext, article.LikingCount, currentUserlikedCount)
article.LikingList = likingList
return article, isAuthor, currentUserId, http.StatusOK, nil
}
示例8: RetrieveOauthStatus
// RetrieveOauthStatus retrieves ouath status that provider connected or not.
func RetrieveOauthStatus(c *gin.Context) (oauthStatusMap, int, error) {
var oauthStatus oauthStatusMap
var connections []model.Connection
oauthStatus = make(oauthStatusMap)
currentUser, err := userService.CurrentUser(c)
if err != nil {
return oauthStatus, http.StatusUnauthorized, err
}
db.ORM.Model(¤tUser).Association("Connections").Find(&connections)
for _, connection := range connections {
log.Debugf("connection.ProviderId : %d", connection.ProviderId)
switch connection.ProviderId {
case google.ProviderId:
oauthStatus["google"] = true
case github.ProviderId:
oauthStatus["github"] = true
case yahoo.ProviderId:
oauthStatus["yahoo"] = true
case facebook.ProviderId:
oauthStatus["facebook"] = true
case twitter.ProviderId:
oauthStatus["twitter"] = true
case linkedin.ProviderId:
oauthStatus["linkedin"] = true
case kakao.ProviderId:
oauthStatus["kakao"] = true
case naver.ProviderId:
oauthStatus["naver"] = true
}
}
log.Debugf("oauthStatus : %v", oauthStatus)
return oauthStatus, http.StatusOK, nil
}
示例9: EmailVerification
// EmailVerification verifies an email of user.
func EmailVerification(c *gin.Context) (int, error) {
var user model.User
var verifyEmailForm VerifyEmailForm
c.BindWith(&verifyEmailForm, binding.Form)
log.Debugf("verifyEmailForm.ActivationToken : %s", verifyEmailForm.ActivationToken)
if db.ORM.Where(&model.User{ActivationToken: verifyEmailForm.ActivationToken}).First(&user).RecordNotFound() {
return http.StatusNotFound, errors.New("User is not found.")
}
isExpired := timeHelper.IsExpired(user.ActivateUntil)
log.Debugf("passwordResetUntil : %s", user.ActivateUntil.UTC())
log.Debugf("expired : %t", isExpired)
if isExpired {
return http.StatusForbidden, errors.New("token not valid.")
}
user.ActivationToken = ""
user.ActivateUntil = time.Now()
user.ActivatedAt = time.Now()
user.Activation = true
status, err := UpdateUserCore(&user)
if err != nil {
return status, err
}
status, err = SetCookie(c, user.Token)
return status, err
}
示例10: FewDurationLater
func FewDurationLater(duration time.Duration) time.Time {
// When Save time should considering UTC
baseTime := time.Now()
log.Debugf("basetime : %s", baseTime)
fewDurationLater := baseTime.Add(duration)
log.Debugf("time : %s", fewDurationLater)
return fewDurationLater
}
示例11: RegisterHanderFromForm
// RegisterHanderFromForm sets cookie from a RegistrationForm.
func RegisterHanderFromForm(c *gin.Context, registrationForm RegistrationForm) (int, error) {
email := registrationForm.Email
pass := registrationForm.Password
log.Debugf("RegisterHandler UserEmail : %s", email)
log.Debugf("RegisterHandler UserPassword : %s", pass)
status, err := SetCookieHandler(c, email, pass)
return status, err
}
示例12: IsExpired
func IsExpired(expirationTime time.Time) bool {
baseTime := time.Now()
log.Debugf("basetime : %s", baseTime)
log.Debugf("expirationTime : %s", expirationTime)
elapsed := time.Since(expirationTime)
log.Debugf("elapsed : %s", elapsed)
after := time.Now().After(expirationTime)
log.Debugf("after : %t", after)
return after
}
示例13: SetNaverUser
// SetNaverUser set naver user.
func SetNaverUser(response *http.Response) (*NaverUser, error) {
naverUser := &NaverUser{}
defer response.Body.Close()
log.Debugf("response.Body: %v\n", response.Body)
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return naverUser, err
}
json.Unmarshal(body, &naverUser)
log.Debugf("\nnaverUser: %v\n", naverUser)
return naverUser, err
}
示例14: SetKakaoUser
// SetKakaoUser set kakao user.
func SetKakaoUser(response *http.Response) (*KakaoUser, error) {
kakaoUser := &KakaoUser{}
defer response.Body.Close()
log.Debugf("response.Body: %v\n", response.Body)
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return kakaoUser, err
}
json.Unmarshal(body, &kakaoUser)
log.Debugf("\nkakaoUser: %v\n", kakaoUser)
return kakaoUser, err
}
示例15: imageUploader
// imageUploader is a uploader that uploading files.
func imageUploader() concurrency.ConcurrencyManager {
return func(reader *multipart.Reader) concurrency.Result {
atomic.AddInt32(concurrency.BusyWorker, 1)
var result concurrency.Result
result.Code = http.StatusOK
for {
part, err := reader.NextPart()
uploadedNow := atomic.AddUint32(concurrency.Done, 1)
log.Debugf("count %d", uploadedNow)
if err == io.EOF {
log.Debug("End of file.")
break
}
if part.FileName() == "" {
log.Debug("File name is empty.")
continue
}
err = upload.UploadImageFile(s3UploadPath, part)
if err != nil {
log.Error("Image uploading failed. : " + err.Error())
result.Code = http.StatusBadRequest
result.Error = err
return result
}
log.Debug("File uploaded.")
}
log.Debug("Iteration concurrency.Done.")
return result
}
}