本文整理匯總了Golang中github.com/urandom/readeef/content.User類的典型用法代碼示例。如果您正苦於以下問題:Golang User類的具體用法?Golang User怎麽用?Golang User使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了User類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getFeedTags
func getFeedTags(user content.User, id data.FeedId) (resp responseError) {
resp = newResponse()
repo := user.Repo()
tf := repo.TaggedFeed(user)
if uf := user.FeedById(id); uf.HasErr() {
resp.err = uf.Err()
return
} else {
tf.Data(uf.Data())
}
tags := tf.Tags()
if tf.HasErr() {
resp.err = tf.Err()
return
}
t := make([]string, len(tags))
for _, tag := range tags {
t = append(t, tag.String())
}
resp.val["Tags"] = t
return
}
示例2: setFeedTags
func setFeedTags(user content.User, id data.FeedId, tagValues []data.TagValue) (resp responseError) {
resp = newResponse()
feed := user.FeedById(id)
if feed.HasErr() {
resp.err = feed.Err()
return
}
repo := user.Repo()
tf := repo.TaggedFeed(user)
tf.Data(feed.Data())
tags := make([]content.Tag, len(tagValues))
for i := range tagValues {
tags[i] = repo.Tag(user)
tags[i].Value(tagValues[i])
}
tf.Tags(tags)
if tf.UpdateTags(); tf.HasErr() {
resp.err = tf.Err()
return
}
resp.val["Success"] = true
resp.val["Id"] = id
return
}
示例3: createUserFeed
func createUserFeed(u content.User, d data.Feed) (uf content.UserFeed) {
uf = repo.UserFeed(u)
uf.Data(d)
uf.Update()
u.AddFeed(uf)
return
}
示例4: createTaggedFeed
func createTaggedFeed(u content.User, d data.Feed) (tf content.TaggedFeed) {
tf = repo.TaggedFeed(u)
tf.Data(d)
tf.Update()
u.AddFeed(tf)
return
}
示例5: getAuthData
func getAuthData(user content.User) (resp responseError) {
resp = newResponse()
in := user.Data()
resp.val["Auth"] = true
resp.val["User"] = user
resp.val["ProfileData"] = in.ProfileData
return
}
示例6: addFeeds
func addFeeds(user content.User, fm *readeef.FeedManager, links []string) (resp responseError) {
resp = newResponse()
var err error
errs := make([]addFeedError, 0, len(links))
for _, link := range links {
var u *url.URL
if u, err = url.Parse(link); err != nil {
resp.err = err
errs = append(errs, addFeedError{Link: link, Error: "Error parsing link"})
continue
} else if !u.IsAbs() {
resp.err = errors.New("Feed has no link")
errs = append(errs, addFeedError{Link: link, Error: resp.err.Error()})
continue
} else {
var f content.Feed
if f, err = fm.AddFeedByLink(link); err != nil {
resp.err = err
errs = append(errs, addFeedError{Link: link, Error: "Error adding feed to the database"})
continue
}
uf := user.AddFeed(f)
if uf.HasErr() {
resp.err = f.Err()
errs = append(errs, addFeedError{Link: link, Title: f.Data().Title, Error: "Error adding feed to the database"})
continue
}
tags := strings.SplitN(u.Fragment, ",", -1)
if u.Fragment != "" && len(tags) > 0 {
repo := uf.Repo()
tf := repo.TaggedFeed(user)
tf.Data(uf.Data())
t := make([]content.Tag, len(tags))
for i := range tags {
t[i] = repo.Tag(user)
t[i].Data(data.Tag{Value: data.TagValue(tags[i])})
}
tf.Tags(t)
if tf.UpdateTags(); tf.HasErr() {
resp.err = tf.Err()
errs = append(errs, addFeedError{Link: link, Title: f.Data().Title, Error: "Error adding feed to the database"})
continue
}
}
}
}
resp.val["Errors"] = errs
resp.val["Success"] = len(errs) < len(links)
return
}
示例7: addFeed
func addFeed(user content.User, fm *readeef.FeedManager, links []string) (resp responseError) {
resp = newResponse()
success := false
for _, link := range links {
var u *url.URL
if u, resp.err = url.Parse(link); resp.err != nil {
/* TODO: non-fatal error */
return
} else if !u.IsAbs() {
/* TODO: non-fatal error */
resp.err = errors.New("Feed has no link")
return
} else {
var f content.Feed
if f, resp.err = fm.AddFeedByLink(link); resp.err != nil {
return
}
uf := user.AddFeed(f)
if uf.HasErr() {
resp.err = f.Err()
return
}
tags := strings.SplitN(u.Fragment, ",", -1)
if u.Fragment != "" && len(tags) > 0 {
repo := uf.Repo()
tf := repo.TaggedFeed(user)
tf.Data(uf.Data())
t := make([]content.Tag, len(tags))
for i := range tags {
t[i] = repo.Tag(user)
t[i].Value(data.TagValue(tags[i]))
}
tf.Tags(t)
if tf.UpdateTags(); tf.HasErr() {
resp.err = tf.Err()
return
}
}
success = true
}
}
resp.val["Success"] = success
return
}
示例8: listUsers
func listUsers(user content.User) (resp responseError) {
resp = newResponse()
if !user.Data().Admin {
resp.err = errForbidden
resp.errType = errTypeForbidden
return
}
repo := user.Repo()
resp.val["Users"], resp.err = repo.AllUsers(), repo.Err()
return
}
示例9: readState
func readState(user content.User, id string, beforeId data.ArticleId, timestamp int64) (resp responseError) {
resp = newResponse()
var ar content.ArticleRepo
o := data.ArticleUpdateStateOptions{}
if timestamp > 0 {
t := time.Unix(timestamp/1000, 0)
o.BeforeDate = t
}
if beforeId > 0 {
o.BeforeId = beforeId
}
switch {
case id == "all":
ar = user
case id == "favorite":
o.FavoriteOnly = true
ar = user
case strings.HasPrefix(id, "popular:"):
// Can't bulk set state to popular articles
case strings.HasPrefix(id, "tag:"):
tag := user.Repo().Tag(user)
tag.Data(data.Tag{Value: data.TagValue(id[4:])})
ar = tag
default:
var feedId int64
if feedId, resp.err = strconv.ParseInt(id, 10, 64); resp.err != nil {
/* TODO: non-fatal error */
return
}
ar = user.FeedById(data.FeedId(feedId))
}
if ar != nil {
ar.ReadState(true, o)
if e, ok := ar.(content.Error); ok && e.HasErr() {
resp.err = e.Err()
return
}
}
resp.val["Success"] = true
return
}
示例10: formatArticle
func formatArticle(user content.User, id data.ArticleId, webfwConfig webfw.Config, readeefConfig readeef.Config) (resp responseError) {
resp = newResponse()
article := user.ArticleById(id)
if user.HasErr() {
resp.err = user.Err()
return
}
formatting := article.Format(webfwConfig.Renderer.Dir, readeefConfig.ArticleFormatter.ReadabilityKey)
if article.HasErr() {
resp.err = user.Err()
return
}
s := summarize.NewFromString(formatting.Title, readeef.StripTags(formatting.Content))
s.Language = formatting.Language
keyPoints := s.KeyPoints()
for i := range keyPoints {
keyPoints[i] = html.UnescapeString(keyPoints[i])
}
resp.val["KeyPoints"] = keyPoints
resp.val["Content"] = formatting.Content
resp.val["TopImage"] = formatting.TopImage
resp.val["Id"] = id
return
}
示例11: removeFeed
func removeFeed(user content.User, fm *readeef.FeedManager, id data.FeedId) (resp responseError) {
resp = newResponse()
feed := user.FeedById(id)
if feed.Delete(); feed.HasErr() {
resp.err = feed.Err()
return
}
fm.RemoveFeed(feed)
resp.val["Success"] = true
return
}
示例12: TestImplements
func TestImplements(t *testing.T) {
var article content.Article
r := NewRepo(nil, nil)
article = r.Article()
article.Data()
var userArticle content.UserArticle
userArticle = r.UserArticle(nil)
userArticle.Data()
var scoredArticle content.ScoredArticle
scoredArticle = r.ScoredArticle()
scoredArticle.Data()
var feed content.Feed
feed = r.Feed()
feed.Data()
var userFeed content.UserFeed
userFeed = r.UserFeed(nil)
userFeed.Data()
var taggedFeed content.TaggedFeed
taggedFeed = r.TaggedFeed(nil)
taggedFeed.Data()
r.HasErr()
var subscription content.Subscription
subscription = r.Subscription()
subscription.Data()
var tag content.Tag
tag = r.Tag(nil)
tag.Value()
var user content.User
user = r.User()
user.Data()
}
示例13: getAuthData
func getAuthData(user content.User, sess context.Session, capabilities capabilities) (resp responseError) {
resp = newResponse()
if sess != nil {
sess.Set(readeef.AuthNameKey, user.Data().Login)
if err := sess.Write(nil); err != nil {
resp.err = fmt.Errorf("Error writing session data: %v", err)
}
}
resp.val["Auth"] = true
resp.val["Capabilities"] = capabilities
resp.val["User"] = user
return
}
示例14: getArticles
func getArticles(u content.User, dbo *db.DB, logger webfw.Logger, opts data.ArticleQueryOptions, sorting content.ArticleSorting, join, where string, args []interface{}) (ua []content.UserArticle) {
if u.HasErr() {
return
}
var err error
if getArticlesTemplate == nil {
getArticlesTemplate, err = template.New("read-state-update-sql").
Parse(dbo.SQL().User.GetArticlesTemplate)
if err != nil {
u.Err(fmt.Errorf("Error generating get-articles-update template: %v", err))
return
}
}
/* Much faster than using 'ORDER BY read'
* TODO: potential overall improvement for fetching pages other than the
* first by using the unread count and moving the offset based on it
*/
if opts.UnreadFirst && opts.Offset == 0 {
originalUnreadOnly := opts.UnreadOnly
opts.UnreadFirst = false
opts.UnreadOnly = true
ua = internalGetArticles(u, dbo, logger, opts, sorting, join, where, args)
if !originalUnreadOnly && (opts.Limit == 0 || opts.Limit > len(ua)) {
if opts.Limit > 0 {
opts.Limit -= len(ua)
}
opts.UnreadOnly = false
opts.ReadOnly = true
readOnly := internalGetArticles(u, dbo, logger, opts, sorting, join, where, args)
ua = append(ua, readOnly...)
}
return
}
return internalGetArticles(u, dbo, logger, opts, sorting, join, where, args)
}
示例15: addUser
func addUser(user content.User, login data.Login, password string, secret []byte) (resp responseError) {
resp = newResponse()
resp.val["Login"] = login
if !user.Data().Admin {
resp.err = errForbidden
resp.errType = errTypeForbidden
return
}
repo := user.Repo()
u := repo.UserByLogin(login)
if !u.HasErr() {
/* TODO: non-fatal error */
resp.err = errUserExists
resp.errType = errTypeUserExists
return
} else {
err := u.Err()
if err != content.ErrNoContent {
resp.err = err
return
}
}
resp.err = nil
in := data.User{Login: login}
u = repo.User()
u.Data(in)
u.Password(password, secret)
u.Update()
if resp.err = u.Err(); resp.err != nil {
return
}
resp.val["Success"] = true
return
}