mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-21 23:15:06 +00:00
add the chat service (#381)
This commit is contained in:
1585
chat/proto/chat.pb.go
Normal file
1585
chat/proto/chat.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
304
chat/proto/chat.pb.micro.go
Normal file
304
chat/proto/chat.pb.micro.go
Normal file
@@ -0,0 +1,304 @@
|
||||
// Code generated by protoc-gen-micro. DO NOT EDIT.
|
||||
// source: proto/chat.proto
|
||||
|
||||
package chat
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
math "math"
|
||||
)
|
||||
|
||||
import (
|
||||
context "context"
|
||||
api "github.com/micro/micro/v3/service/api"
|
||||
client "github.com/micro/micro/v3/service/client"
|
||||
server "github.com/micro/micro/v3/service/server"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ api.Endpoint
|
||||
var _ context.Context
|
||||
var _ client.Option
|
||||
var _ server.Option
|
||||
|
||||
// Api Endpoints for Chat service
|
||||
|
||||
func NewChatEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{}
|
||||
}
|
||||
|
||||
// Client API for Chat service
|
||||
|
||||
type ChatService interface {
|
||||
New(ctx context.Context, in *NewRequest, opts ...client.CallOption) (*NewResponse, error)
|
||||
History(ctx context.Context, in *HistoryRequest, opts ...client.CallOption) (*HistoryResponse, error)
|
||||
Send(ctx context.Context, in *SendRequest, opts ...client.CallOption) (*SendResponse, error)
|
||||
List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error)
|
||||
Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error)
|
||||
Join(ctx context.Context, in *JoinRequest, opts ...client.CallOption) (Chat_JoinService, error)
|
||||
Invite(ctx context.Context, in *InviteRequest, opts ...client.CallOption) (*InviteResponse, error)
|
||||
Leave(ctx context.Context, in *LeaveRequest, opts ...client.CallOption) (*LeaveResponse, error)
|
||||
Kick(ctx context.Context, in *KickRequest, opts ...client.CallOption) (*KickResponse, error)
|
||||
}
|
||||
|
||||
type chatService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewChatService(name string, c client.Client) ChatService {
|
||||
return &chatService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *chatService) New(ctx context.Context, in *NewRequest, opts ...client.CallOption) (*NewResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Chat.New", in)
|
||||
out := new(NewResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *chatService) History(ctx context.Context, in *HistoryRequest, opts ...client.CallOption) (*HistoryResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Chat.History", in)
|
||||
out := new(HistoryResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *chatService) Send(ctx context.Context, in *SendRequest, opts ...client.CallOption) (*SendResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Chat.Send", in)
|
||||
out := new(SendResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *chatService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Chat.List", in)
|
||||
out := new(ListResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *chatService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Chat.Delete", in)
|
||||
out := new(DeleteResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *chatService) Join(ctx context.Context, in *JoinRequest, opts ...client.CallOption) (Chat_JoinService, error) {
|
||||
req := c.c.NewRequest(c.name, "Chat.Join", &JoinRequest{})
|
||||
stream, err := c.c.Stream(ctx, req, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := stream.Send(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &chatServiceJoin{stream}, nil
|
||||
}
|
||||
|
||||
type Chat_JoinService interface {
|
||||
Context() context.Context
|
||||
SendMsg(interface{}) error
|
||||
RecvMsg(interface{}) error
|
||||
Close() error
|
||||
Recv() (*Message, error)
|
||||
}
|
||||
|
||||
type chatServiceJoin struct {
|
||||
stream client.Stream
|
||||
}
|
||||
|
||||
func (x *chatServiceJoin) Close() error {
|
||||
return x.stream.Close()
|
||||
}
|
||||
|
||||
func (x *chatServiceJoin) Context() context.Context {
|
||||
return x.stream.Context()
|
||||
}
|
||||
|
||||
func (x *chatServiceJoin) SendMsg(m interface{}) error {
|
||||
return x.stream.Send(m)
|
||||
}
|
||||
|
||||
func (x *chatServiceJoin) RecvMsg(m interface{}) error {
|
||||
return x.stream.Recv(m)
|
||||
}
|
||||
|
||||
func (x *chatServiceJoin) Recv() (*Message, error) {
|
||||
m := new(Message)
|
||||
err := x.stream.Recv(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (c *chatService) Invite(ctx context.Context, in *InviteRequest, opts ...client.CallOption) (*InviteResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Chat.Invite", in)
|
||||
out := new(InviteResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *chatService) Leave(ctx context.Context, in *LeaveRequest, opts ...client.CallOption) (*LeaveResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Chat.Leave", in)
|
||||
out := new(LeaveResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *chatService) Kick(ctx context.Context, in *KickRequest, opts ...client.CallOption) (*KickResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Chat.Kick", in)
|
||||
out := new(KickResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for Chat service
|
||||
|
||||
type ChatHandler interface {
|
||||
New(context.Context, *NewRequest, *NewResponse) error
|
||||
History(context.Context, *HistoryRequest, *HistoryResponse) error
|
||||
Send(context.Context, *SendRequest, *SendResponse) error
|
||||
List(context.Context, *ListRequest, *ListResponse) error
|
||||
Delete(context.Context, *DeleteRequest, *DeleteResponse) error
|
||||
Join(context.Context, *JoinRequest, Chat_JoinStream) error
|
||||
Invite(context.Context, *InviteRequest, *InviteResponse) error
|
||||
Leave(context.Context, *LeaveRequest, *LeaveResponse) error
|
||||
Kick(context.Context, *KickRequest, *KickResponse) error
|
||||
}
|
||||
|
||||
func RegisterChatHandler(s server.Server, hdlr ChatHandler, opts ...server.HandlerOption) error {
|
||||
type chat interface {
|
||||
New(ctx context.Context, in *NewRequest, out *NewResponse) error
|
||||
History(ctx context.Context, in *HistoryRequest, out *HistoryResponse) error
|
||||
Send(ctx context.Context, in *SendRequest, out *SendResponse) error
|
||||
List(ctx context.Context, in *ListRequest, out *ListResponse) error
|
||||
Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error
|
||||
Join(ctx context.Context, stream server.Stream) error
|
||||
Invite(ctx context.Context, in *InviteRequest, out *InviteResponse) error
|
||||
Leave(ctx context.Context, in *LeaveRequest, out *LeaveResponse) error
|
||||
Kick(ctx context.Context, in *KickRequest, out *KickResponse) error
|
||||
}
|
||||
type Chat struct {
|
||||
chat
|
||||
}
|
||||
h := &chatHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&Chat{h}, opts...))
|
||||
}
|
||||
|
||||
type chatHandler struct {
|
||||
ChatHandler
|
||||
}
|
||||
|
||||
func (h *chatHandler) New(ctx context.Context, in *NewRequest, out *NewResponse) error {
|
||||
return h.ChatHandler.New(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *chatHandler) History(ctx context.Context, in *HistoryRequest, out *HistoryResponse) error {
|
||||
return h.ChatHandler.History(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *chatHandler) Send(ctx context.Context, in *SendRequest, out *SendResponse) error {
|
||||
return h.ChatHandler.Send(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *chatHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error {
|
||||
return h.ChatHandler.List(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *chatHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error {
|
||||
return h.ChatHandler.Delete(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *chatHandler) Join(ctx context.Context, stream server.Stream) error {
|
||||
m := new(JoinRequest)
|
||||
if err := stream.Recv(m); err != nil {
|
||||
return err
|
||||
}
|
||||
return h.ChatHandler.Join(ctx, m, &chatJoinStream{stream})
|
||||
}
|
||||
|
||||
type Chat_JoinStream interface {
|
||||
Context() context.Context
|
||||
SendMsg(interface{}) error
|
||||
RecvMsg(interface{}) error
|
||||
Close() error
|
||||
Send(*Message) error
|
||||
}
|
||||
|
||||
type chatJoinStream struct {
|
||||
stream server.Stream
|
||||
}
|
||||
|
||||
func (x *chatJoinStream) Close() error {
|
||||
return x.stream.Close()
|
||||
}
|
||||
|
||||
func (x *chatJoinStream) Context() context.Context {
|
||||
return x.stream.Context()
|
||||
}
|
||||
|
||||
func (x *chatJoinStream) SendMsg(m interface{}) error {
|
||||
return x.stream.Send(m)
|
||||
}
|
||||
|
||||
func (x *chatJoinStream) RecvMsg(m interface{}) error {
|
||||
return x.stream.Recv(m)
|
||||
}
|
||||
|
||||
func (x *chatJoinStream) Send(m *Message) error {
|
||||
return x.stream.Send(m)
|
||||
}
|
||||
|
||||
func (h *chatHandler) Invite(ctx context.Context, in *InviteRequest, out *InviteResponse) error {
|
||||
return h.ChatHandler.Invite(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *chatHandler) Leave(ctx context.Context, in *LeaveRequest, out *LeaveResponse) error {
|
||||
return h.ChatHandler.Leave(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *chatHandler) Kick(ctx context.Context, in *KickRequest, out *KickResponse) error {
|
||||
return h.ChatHandler.Kick(ctx, in, out)
|
||||
}
|
||||
163
chat/proto/chat.proto
Normal file
163
chat/proto/chat.proto
Normal file
@@ -0,0 +1,163 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package chat;
|
||||
option go_package = "./proto;chat";
|
||||
|
||||
service Chat {
|
||||
rpc New(NewRequest) returns (NewResponse);
|
||||
rpc History(HistoryRequest) returns (HistoryResponse);
|
||||
rpc Send(SendRequest) returns (SendResponse);
|
||||
rpc List(ListRequest) returns (ListResponse);
|
||||
rpc Delete(DeleteRequest) returns (DeleteResponse);
|
||||
rpc Join(JoinRequest) returns (stream Message);
|
||||
rpc Invite(InviteRequest) returns (InviteResponse);
|
||||
rpc Leave(LeaveRequest) returns (LeaveResponse);
|
||||
rpc Kick(KickRequest) returns (KickResponse);
|
||||
}
|
||||
|
||||
// Create a new chat room
|
||||
message NewRequest {
|
||||
// name of the room
|
||||
string name = 1;
|
||||
// chat description
|
||||
string description = 2;
|
||||
// optional list of user ids
|
||||
repeated string user_ids = 3;
|
||||
// whether its a private room
|
||||
bool private = 4;
|
||||
}
|
||||
|
||||
message NewResponse {
|
||||
// the unique chat room
|
||||
Room room = 1;
|
||||
}
|
||||
|
||||
// List the messages in a chat
|
||||
message HistoryRequest {
|
||||
// the chat room id to get
|
||||
string room_id = 1;
|
||||
}
|
||||
|
||||
// HistoryResponse contains the historical messages in a chat
|
||||
message HistoryResponse {
|
||||
// messages in the chat room
|
||||
repeated Message messages = 1;
|
||||
}
|
||||
|
||||
// List available chats
|
||||
message ListRequest {
|
||||
// optional user id to filter by
|
||||
string user_id = 1;
|
||||
}
|
||||
|
||||
message ListResponse {
|
||||
repeated Room rooms = 1;
|
||||
}
|
||||
|
||||
// Delete a chat room
|
||||
message DeleteRequest {
|
||||
// the chat room id to delete
|
||||
string room_id = 1;
|
||||
}
|
||||
|
||||
message DeleteResponse {
|
||||
Room room = 1;
|
||||
}
|
||||
|
||||
|
||||
// Connect to a chat to receive a stream of messages
|
||||
// Send a message to a chat
|
||||
message SendRequest {
|
||||
// a client side id, should be validated by the server to make the request retry safe
|
||||
string client = 1;
|
||||
// id of the chat room the message is being sent to / from
|
||||
string room_id = 2;
|
||||
// id of the user who sent the message
|
||||
string user_id = 3;
|
||||
// subject of the message
|
||||
string subject = 4;
|
||||
// text of the message
|
||||
string text = 5;
|
||||
}
|
||||
|
||||
message SendResponse {
|
||||
// the message which was created
|
||||
Message message = 1;
|
||||
}
|
||||
|
||||
// Join a chat room
|
||||
message JoinRequest {
|
||||
// chat room to join
|
||||
string room_id = 1;
|
||||
// user id joining
|
||||
string user_id = 2;
|
||||
}
|
||||
|
||||
message Room {
|
||||
// unique room id
|
||||
string id = 1;
|
||||
// name of the chat
|
||||
string name = 2;
|
||||
// description of the that
|
||||
string description = 3;
|
||||
// time of creation
|
||||
string created_at = 4;
|
||||
// list of users
|
||||
repeated string user_ids = 5;
|
||||
// whether its a private room
|
||||
bool private = 6;
|
||||
}
|
||||
|
||||
// Message sent to a chat
|
||||
message Message {
|
||||
// id of the message, allocated by the server
|
||||
string id = 1;
|
||||
// a client side id, should be validated by the server to make the request retry safe
|
||||
string client = 2;
|
||||
// id of the chat the message is being sent to / from
|
||||
string room_id = 3;
|
||||
// id of the user who sent the message
|
||||
string user_id = 4;
|
||||
// time the message was sent in RFC3339 format
|
||||
string sent_at = 5;
|
||||
// subject of the message
|
||||
string subject = 6;
|
||||
// text of the message
|
||||
string text = 7;
|
||||
}
|
||||
|
||||
// Leave a chat room
|
||||
message LeaveRequest {
|
||||
// the chat room id
|
||||
string room_id = 1;
|
||||
// the user id
|
||||
string user_id = 2;
|
||||
}
|
||||
|
||||
message LeaveResponse {
|
||||
Room room = 1;
|
||||
}
|
||||
|
||||
// Invite a user to a chat room
|
||||
message InviteRequest {
|
||||
// the room id
|
||||
string room_id = 1;
|
||||
// the user id
|
||||
string user_id = 2;
|
||||
}
|
||||
|
||||
message InviteResponse {
|
||||
Room room = 1;
|
||||
}
|
||||
|
||||
// Kick a user from a chat room
|
||||
message KickRequest {
|
||||
// the chat room id
|
||||
string room_id = 1;
|
||||
// the user id
|
||||
string user_id = 2;
|
||||
}
|
||||
|
||||
message KickResponse {
|
||||
Room room = 1;
|
||||
}
|
||||
Reference in New Issue
Block a user