Documentation ¶
Index ¶
- func ArticlesToProtoArticles(articles []Article) *pb.Articles
- func UnaryClientInterceptor(ctx context.Context, method string, req, reply interface{}, ...) error
- type Article
- type ArticleArray
- type DatabaseManager
- func (dbm *DatabaseManager) GetArticleByID(ctx context.Context, vtspanctx string, ID uint64) (article Article, err error)
- func (dbm *DatabaseManager) GetArticlesFromRegion(ctx context.Context, vtspanctx string, region int) (articles []Article, err error)
- func (dbm *DatabaseManager) GetArticlesOfCategory(ctx context.Context, vtspanctx, category string) (articles []Article, err error)
- func (dbm *DatabaseManager) InsertArticle(article Article) (newID int, err error)
- type MetaDataWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArticlesToProtoArticles ¶
ArticlesToProtoArticles transforms an array of Articles into an array of pb.Articles which are auto-generated from protobuf.
func UnaryClientInterceptor ¶
func UnaryClientInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error
Types ¶
type Article ¶
type Article struct { ID int64 `json:"id"` Timestamp int64 `json:"timestamp"` AID string `json:"aid"` Title string `json:"title"` Category string `json:"category"` Abstract string `json:"abstract"` ArticleTags string `json:"article_tags"` Authors string `json:"authors"` Language string `json:"language"` Text string `json:"text"` Image string `json:"image"` Video string `json:"video"` }
Article struct refers to the article table of the Vitess MySQl cluster, in the articles keyspace.
func ProtoArticleToArticle ¶
ProtoArticleToArticle transforms an auto-generated pb.Article from protobuf into the package implementation of Article.
func (*Article) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*Article) ProtoArticle ¶
ProtoArticle transforms an Article into a the auto-generated pb.Article structure from protobuf.
func (*Article) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
type ArticleArray ¶
type ArticleArray []Article
ArticleArray represents an array of Article. Implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler.
func (*ArticleArray) MarshalBinary ¶
func (ua *ArticleArray) MarshalBinary() (data []byte, err error)
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*ArticleArray) UnmarshalBinary ¶
func (ua *ArticleArray) UnmarshalBinary(data []byte) error
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
type DatabaseManager ¶
type DatabaseManager struct {
// contains filtered or unexported fields
}
DatabaseManager contains the connection pools of the Vitess MySQL cluster. The main connection pool that should be used is the `db *sql.DB` one, the others are just for proof-of-concept-purpose.
func NewDatabaseManager ¶
func NewDatabaseManager() (dbm *DatabaseManager, err error)
NewDatabaseManager will return a newly created DatabaseManager, the DatabaseManager will contain the initialized connection pools to Vitess MySQL cluster.
func (*DatabaseManager) GetArticleByID ¶
func (dbm *DatabaseManager) GetArticleByID(ctx context.Context, vtspanctx string, ID uint64) (article Article, err error)
GetArticleByID will fetch an article from Vitess corresponding to the given unique ID.
func (*DatabaseManager) GetArticlesFromRegion ¶
func (dbm *DatabaseManager) GetArticlesFromRegion(ctx context.Context, vtspanctx string, region int) (articles []Article, err error)
GetArticlesFromRegion is used as an experiment. It queries all the articles that are stored ONLY in the given region ID.
To do such query, the function will not use the default connection pool, instead it will use the shard specific connection pool.
RegionID: 1 = Beijing 2 = Hong Kong
func (*DatabaseManager) GetArticlesOfCategory ¶
func (dbm *DatabaseManager) GetArticlesOfCategory(ctx context.Context, vtspanctx, category string) (articles []Article, err error)
GetArticlesOfCategory will return all the articles belonging to the given category.
func (*DatabaseManager) InsertArticle ¶
func (dbm *DatabaseManager) InsertArticle(article Article) (newID int, err error)
InsertArticle will insert the given Article in Vitess MySQL cluster the new ID will be returned, in addition to an error if there is any.
type MetaDataWriter ¶
MetaDataWriter interfaces opentracing.TextMap and is being used to propagate traces to the database cluster.
func (MetaDataWriter) ForeachKey ¶
func (mdw MetaDataWriter) ForeachKey(handler func(key, val string) error) error
ForeachKey implements the Foreach function of opentracing.TextMap interface.
func (MetaDataWriter) Set ¶
func (mdw MetaDataWriter) Set(key, val string)
Set implements the Set function of opentracing.TextMap interface.