state

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2023 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStatusNotFound       = errors.New("status not found")
	ErrStatusQuotes   error = errors.New("there are quotes")
	ErrTryAgainLater  error = errors.New("txn failed. try again later")
)
View Source
var (
	MsgTypeLike     string = "like"
	MsgTypeBookmark string = "bookmark"
	MsgTypeComment  string = "comment"
	MsgTypeAt       string = "at"
	MsgTypeFollow   string = "follow"
)

Functions

func BookmarkStatus

func BookmarkStatus(user *ActUser, statusID string) error

func Bookmarked

func Bookmarked(statusID, uid string) bool

func Del

func Del(key string) error

func DeleteMessages

func DeleteMessages(user *ActUser, msgs []string) error

func DeleteTipMessages

func DeleteTipMessages(user *ActUser, msgs []string) error

func FollowUser

func FollowUser(user *ActUser, uniqueName string) error

func Followed

func Followed(u1, u2 string) bool

func InitState

func InitState(opts EtcdOptions) (err error)

func IterateWithPrefix

func IterateWithPrefix(prefix string, handle func(key string, value []byte)) error

func LikeStatus

func LikeStatus(user *ActUser, statusID string) error

func Liked

func Liked(statusID, uid string) bool

func ListTipMessages

func ListTipMessages(user *ActUser, size int64) (msgs []string)

func NotRecommandStatus added in v0.2.0

func NotRecommandStatus(statusID string) error

func Put

func Put(key string, value []byte) error

func RecommandStatus added in v0.2.0

func RecommandStatus(statusID string) error

func RecommendCount added in v0.1.0

func RecommendCount(user *ActUser, createRev int64) int

Types

type ActUser

type ActUser struct {
	ID           string `json:"id"`
	UniqueName   string `json:"uniqueName"`
	Name         string `json:"name"`
	Picture      string `json:"picture"`
	VerifiedCode int64  `json:"verifiedCode"`
}

type CommentsRecommandMeta added in v0.2.0

type CommentsRecommandMeta struct {
	Blacklist   []string `json:"blacklist"`
	RecommandID string   `json:"recommandID"`
	// contains filtered or unexported fields
}

func NewCommentsRecommandMeta added in v0.2.0

func NewCommentsRecommandMeta(statusID string) (meta *CommentsRecommandMeta, err error)

func NewCommentsRecommandMetaForRecommand added in v0.2.0

func NewCommentsRecommandMetaForRecommand(statusID string) (meta *CommentsRecommandMeta, err error)

func (*CommentsRecommandMeta) Recommand added in v0.2.0

func (m *CommentsRecommandMeta) Recommand() *Status

func (*CommentsRecommandMeta) RunRecommand added in v0.2.0

func (m *CommentsRecommandMeta) RunRecommand(statusCreateRev int64) error

type EtcdOptions

type EtcdOptions struct {
	Endpoints     []string
	CertFile      string
	KeyFile       string
	TrustedCAFile string
}

type Label

type Label struct {
	Value string `json:"value"`
	Count int64  `json:"count"`
}

func GetLabels

func GetLabels(prefix string, size int64) (labels []*Label)

type MemorySessionManger

type MemorySessionManger struct {
	// contains filtered or unexported fields
}

func (*MemorySessionManger) Create

func (sm *MemorySessionManger) Create(s *Session) error

func (*MemorySessionManger) Delete

func (sm *MemorySessionManger) Delete(apiKey string) error

func (*MemorySessionManger) Expire

func (sm *MemorySessionManger) Expire(userID string) error

func (*MemorySessionManger) Load

func (sm *MemorySessionManger) Load(key string) *Session

type Message

type Message struct {
	ID         string    `json:"id"`
	Message    string    `json:"message,omitempty"`
	From       *ActUser  `json:"from"`
	Type       string    `json:"type"`
	TargetID   string    `json:"targetID"`
	CreateTime time.Time `json:"createTime"`
}

func ListMessages

func ListMessages(user *ActUser, opts *tools.PaginationOptions) (msgs []*Message, more bool)

type ModifiableUser

type ModifiableUser struct {
	UniqueName string `json:"uniqueName"`
	Name       string `json:"name"`
	Picture    string `json:"picture"`
	Locale     string `json:"locale"`
	Bio        string `json:"bio"`
}

type MsgOptions

type MsgOptions struct {
	// contains filtered or unexported fields
}

type PersistentSessionManager

type PersistentSessionManager struct {
	MemorySessionManger
}

func NewSessionManager

func NewSessionManager() *PersistentSessionManager

func (*PersistentSessionManager) Create

func (sm *PersistentSessionManager) Create(s *Session) error

func (*PersistentSessionManager) Delete

func (sm *PersistentSessionManager) Delete(apiKey string) error

func (*PersistentSessionManager) Expire

func (sm *PersistentSessionManager) Expire(userID string) error

type Session

type Session struct {
	ApiKey       string `json:"apiKey"`
	ID           string `json:"id"`
	Name         string `json:"name"`
	UniqueName   string `json:"uniqueName"`
	Picture      string `json:"picture"`
	Locale       string `json:"locale"`
	Bio          string `json:"bio"`
	VerifiedCode int64  `json:"verifiedCode"`
	Admin        bool   `json:"admin"`
}

func CreateSession

func CreateSession(opts *UserOptions) (*Session, error)

func (*Session) ToUser

func (s *Session) ToUser() *ActUser

type SessionManager

type SessionManager interface {
	Create(*Session) error
	Load(string) *Session
	Delete(string) error
	Expire(string) error
}
var DefaultSessionManager SessionManager

type Status

type Status struct {
	ID         string            `json:"id"`
	Content    []*StatusFragment `json:"content"`
	RefStatus  string            `json:"prev"`
	User       *ActUser          `json:"user"`
	CreateRev  int64             `json:"createRev"`
	CreateTime time.Time         `json:"createTime"`
	Comments   int64             `json:"comments"`
	LikeCount  int64             `json:"likeCount"`
	Views      int64             `json:"views"`
	Bookmarks  int64             `json:"bookmarks"`
}

func GetStatus

func GetStatus(statusID string) *Status

func ListBookmarks

func ListBookmarks(user *ActUser, opts *tools.PaginationOptions) ([]*Status, bool)

func ListStatusByKeyword

func ListStatusByKeyword(value string, opts *tools.PaginationOptions) []*Status

func ListStatusByLabel

func ListStatusByLabel(value string, opts *tools.PaginationOptions) ([]*Status, bool)

func NewStatus

func NewStatus(opts *StatusOptions) (*Status, error)

func Recommendations

func Recommendations(user *ActUser, opts *tools.PaginationOptions) (ss []*Status, more bool)

func StatusComments

func StatusComments(statusID string, opts *tools.PaginationOptions) (ss []*Status, more bool)

func (*Status) ContentsByType added in v0.2.0

func (s *Status) ContentsByType(t string) (sfs []*StatusFragment)

func (*Status) Delete added in v0.2.0

func (s *Status) Delete(uid string) error

func (*Status) Overview

func (s *Status) Overview() string

type StatusCommentsOptions

type StatusCommentsOptions struct {
	StatusID   string
	After      string
	Size       int64
	SortAscend bool
}

type StatusFragment

type StatusFragment struct {
	Value string `json:"value"`
	Type  string `json:"type"`
}

type StatusOptions

type StatusOptions struct {
	Content   []*StatusFragment
	RefStatus string
	User      *ActUser
	Labels    []string
	At        []string
}

type StatusViewCountManager added in v0.2.1

type StatusViewCountManager struct {
	// contains filtered or unexported fields
}
var (
	UserChanged chan *User             = make(chan *User, 128)
	SVCM        StatusViewCountManager = StatusViewCountManager{
				// contains filtered or unexported fields
	}
)

func (*StatusViewCountManager) Viewed added in v0.2.1

func (m *StatusViewCountManager) Viewed(statusID string)

type User

type User struct {
	ID           string    `json:"id"`
	UniqueName   string    `json:"uniqueName"`
	Name         string    `json:"name"`
	Picture      string    `json:"picture"`
	Email        string    `json:"email"`
	Locale       string    `json:"locale"`
	CreateTime   time.Time `json:"createTime"`
	Bio          string    `json:"bio"`
	VerifiedCode int64     `json:"verifiedCode"`
	ModRev       int64     `json:"-"`
}

func NewUser

func NewUser(opts *UserOptions) *User

func UserByEmail

func UserByEmail(email string) *User

func UserByID

func UserByID(userID string) *User

func UserByUniqueName

func UserByUniqueName(uniqueName string) *User

func (*User) Followers

func (u *User) Followers() int64

Followers follower count

func (*User) FollowingBy

func (u *User) FollowingBy(user *ActUser) bool

FollowingBy determine if {uid} is following me

func (*User) Followings

func (u *User) Followings() int64

Followings following count

func (*User) ListStatus

func (u *User) ListStatus(opts *tools.PaginationOptions) (ss []*Status, more bool)

ListStatus list user all status

func (*User) Modify

func (u *User) Modify(mu ModifiableUser) error

Modify apply new user props

func (*User) SetVerified added in v0.2.0

func (u *User) SetVerified(code int64) error

func (*User) Tweets

func (u *User) Tweets() int64

Tweets tweet count

type UserOptions

type UserOptions struct {
	Name    string
	Picture string
	Email   string
	Locale  string
	Bio     string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL