Documentation
¶
Index ¶
- func UnaryClientInterceptor(ctx context.Context, method string, req, reply interface{}, ...) error
- func UsersToProtoUsers(users []User) *pb.Users
- type DatabaseManager
- func (dbm *DatabaseManager) GetUserByID(ctx context.Context, vtspanctx string, ID uint64) (user User, err error)
- func (dbm *DatabaseManager) GetUsersOfRegion(ctx context.Context, vtspanctx, region string) (users []User, err error)
- func (dbm *DatabaseManager) InsertUser(user User) (newID int, err error)
- type MetaDataWriter
- type User
- type UserArray
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UnaryClientInterceptor ¶
func UnaryClientInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error
func UsersToProtoUsers ¶
UsersToProtoUsers transforms an array of User into an array of pb.Users which are auto-generated from protobuf.
Types ¶
type DatabaseManager ¶
type DatabaseManager struct {
// contains filtered or unexported fields
}
DatabaseManager contains the connection pool to Vitess MySQL cluster. DatabaseManager's methods enable using the models with the rest of the cluster properly.
func NewDatabaseManager ¶
func NewDatabaseManager() (dbm *DatabaseManager, err error)
NewDatabaseManager will create a new connection pool to Vitess MySQL cluster using the `users` keyspace.
TODO: add some configuration in the call of this function
func (*DatabaseManager) GetUserByID ¶
func (dbm *DatabaseManager) GetUserByID(ctx context.Context, vtspanctx string, ID uint64) (user User, err error)
GetUserByID will returns a single User corresponding to the given ID.
func (*DatabaseManager) GetUsersOfRegion ¶
func (dbm *DatabaseManager) GetUsersOfRegion(ctx context.Context, vtspanctx, region string) (users []User, err error)
GetUsersOfRegion fetches all the users matching the given region filter. It returns an array of Users, and an error if there is any. No other filter than region is being used thus, the function might be highly computational intensive depending on the data stored in Vitess.
func (*DatabaseManager) InsertUser ¶
func (dbm *DatabaseManager) InsertUser(user User) (newID int, err error)
InsertUser inserts the given User into Vitess MySQL cluster. The new auto-generated ID will be returned, in addition to an error if 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.
type User ¶
type User struct { ID int64 `json:"id"` Timestamp int64 `json:"timestamp"` UID string `json:"uid"` Name string `json:"name"` Gender string `json:"gender"` Email string `json:"email"` Phone string `json:"phone"` Dept string `json:"dept"` Grade string `json:"grade"` Language string `json:"language"` Region string `json:"region"` Role string `json:"role"` PreferTags string `json:"prefer_tags"` ObtainedCredits string `json:"obtained_credits"` }
User model maps to the user table of Vitess MySQL cluster. Implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler.
func ProtoUserToUser ¶
ProtoUserToUser transforms an auto-generated pb.User from protobuf into the package implementation of User.
func (*User) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*User) ProtoUser ¶
ProtoUser transforms an User into a the auto-generated pb.User structure from protobuf.
func (*User) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
type UserArray ¶
type UserArray []User
UserArray represents an array of User. Implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler.
func (*UserArray) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*UserArray) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.