From 071ab7aededeeb13db5066d19cc4888ae65d30fd Mon Sep 17 00:00:00 2001 From: shu xian Date: Fri, 17 Jan 2020 00:10:15 +0800 Subject: [PATCH 1/6] add mucp for config/source --- config/source/mucp/mucp.go | 72 +++ config/source/mucp/options.go | 18 + config/source/mucp/proto/mucp.pb.go | 649 ++++++++++++++++++++++ config/source/mucp/proto/mucp.pb.micro.go | 241 ++++++++ config/source/mucp/proto/mucp.proto | 76 +++ config/source/mucp/util.go | 18 + config/source/mucp/watcher.go | 27 + 7 files changed, 1101 insertions(+) create mode 100644 config/source/mucp/mucp.go create mode 100644 config/source/mucp/options.go create mode 100644 config/source/mucp/proto/mucp.pb.go create mode 100644 config/source/mucp/proto/mucp.pb.micro.go create mode 100644 config/source/mucp/proto/mucp.proto create mode 100644 config/source/mucp/util.go create mode 100644 config/source/mucp/watcher.go diff --git a/config/source/mucp/mucp.go b/config/source/mucp/mucp.go new file mode 100644 index 00000000..eeb4bb84 --- /dev/null +++ b/config/source/mucp/mucp.go @@ -0,0 +1,72 @@ +package mucp + +import ( + "context" + + "github.com/micro/go-micro/config/cmd" + "github.com/micro/go-micro/config/source" + proto "github.com/micro/go-micro/config/source/mucp/proto" + "github.com/micro/go-micro/util/log" +) + +var ( + DefaultServiceName = "go.micro.config" +) + +type mucpSource struct { + serviceName string + key string + opts source.Options + client proto.SourceService +} + +func (m *mucpSource) Read() (set *source.ChangeSet, err error) { + req, err := m.client.Read(context.Background(), &proto.ReadRequest{Path: m.key}) + if err != nil { + return nil, err + } + + return toChangeSet(req.Change.ChangeSet), nil +} + +func (m *mucpSource) Watch() (w source.Watcher, err error) { + stream, err := m.client.Watch(context.Background(), &proto.WatchRequest{Key: m.key}) + if err != nil { + log.Error("watch err: ", err) + return + } + return newWatcher(stream) +} + +// Write is unsupported +func (m *mucpSource) Write(cs *source.ChangeSet) error { + return nil +} + +func (m *mucpSource) String() string { + return "mucp" +} + +func NewSource(opts ...source.Option) source.Source { + var options source.Options + for _, o := range opts { + o(&options) + } + + addr := DefaultServiceName + + if options.Context != nil { + a, ok := options.Context.Value(serviceNameKey{}).(string) + if ok { + addr = a + } + } + + s := &mucpSource{ + serviceName: addr, + opts: options, + client: proto.NewSourceService(addr, *cmd.DefaultOptions().Client), + } + + return s +} diff --git a/config/source/mucp/options.go b/config/source/mucp/options.go new file mode 100644 index 00000000..c8717cbd --- /dev/null +++ b/config/source/mucp/options.go @@ -0,0 +1,18 @@ +package mucp + +import ( + "context" + + "github.com/micro/go-micro/config/source" +) + +type serviceNameKey struct{} + +func ServiceName(a string) source.Option { + return func(o *source.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, serviceNameKey{}, a) + } +} diff --git a/config/source/mucp/proto/mucp.pb.go b/config/source/mucp/proto/mucp.pb.go new file mode 100644 index 00000000..b72b9070 --- /dev/null +++ b/config/source/mucp/proto/mucp.pb.go @@ -0,0 +1,649 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: proto/mucp.proto + +package mucp + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// 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 + +type ChangeSet struct { + Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` + Checksum string `protobuf:"bytes,2,opt,name=checksum,proto3" json:"checksum,omitempty"` + Format string `protobuf:"bytes,3,opt,name=format,proto3" json:"format,omitempty"` + Source string `protobuf:"bytes,4,opt,name=source,proto3" json:"source,omitempty"` + Timestamp int64 `protobuf:"varint,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ChangeSet) Reset() { *m = ChangeSet{} } +func (m *ChangeSet) String() string { return proto.CompactTextString(m) } +func (*ChangeSet) ProtoMessage() {} +func (*ChangeSet) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{0} +} + +func (m *ChangeSet) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ChangeSet.Unmarshal(m, b) +} +func (m *ChangeSet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ChangeSet.Marshal(b, m, deterministic) +} +func (m *ChangeSet) XXX_Merge(src proto.Message) { + xxx_messageInfo_ChangeSet.Merge(m, src) +} +func (m *ChangeSet) XXX_Size() int { + return xxx_messageInfo_ChangeSet.Size(m) +} +func (m *ChangeSet) XXX_DiscardUnknown() { + xxx_messageInfo_ChangeSet.DiscardUnknown(m) +} + +var xxx_messageInfo_ChangeSet proto.InternalMessageInfo + +func (m *ChangeSet) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +func (m *ChangeSet) GetChecksum() string { + if m != nil { + return m.Checksum + } + return "" +} + +func (m *ChangeSet) GetFormat() string { + if m != nil { + return m.Format + } + return "" +} + +func (m *ChangeSet) GetSource() string { + if m != nil { + return m.Source + } + return "" +} + +func (m *ChangeSet) GetTimestamp() int64 { + if m != nil { + return m.Timestamp + } + return 0 +} + +type Change struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` + ChangeSet *ChangeSet `protobuf:"bytes,3,opt,name=changeSet,proto3" json:"changeSet,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Change) Reset() { *m = Change{} } +func (m *Change) String() string { return proto.CompactTextString(m) } +func (*Change) ProtoMessage() {} +func (*Change) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{1} +} + +func (m *Change) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Change.Unmarshal(m, b) +} +func (m *Change) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Change.Marshal(b, m, deterministic) +} +func (m *Change) XXX_Merge(src proto.Message) { + xxx_messageInfo_Change.Merge(m, src) +} +func (m *Change) XXX_Size() int { + return xxx_messageInfo_Change.Size(m) +} +func (m *Change) XXX_DiscardUnknown() { + xxx_messageInfo_Change.DiscardUnknown(m) +} + +var xxx_messageInfo_Change proto.InternalMessageInfo + +func (m *Change) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *Change) GetPath() string { + if m != nil { + return m.Path + } + return "" +} + +func (m *Change) GetChangeSet() *ChangeSet { + if m != nil { + return m.ChangeSet + } + return nil +} + +type CreateRequest struct { + Change *Change `protobuf:"bytes,1,opt,name=change,proto3" json:"change,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateRequest) Reset() { *m = CreateRequest{} } +func (m *CreateRequest) String() string { return proto.CompactTextString(m) } +func (*CreateRequest) ProtoMessage() {} +func (*CreateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{2} +} + +func (m *CreateRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateRequest.Unmarshal(m, b) +} +func (m *CreateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateRequest.Marshal(b, m, deterministic) +} +func (m *CreateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateRequest.Merge(m, src) +} +func (m *CreateRequest) XXX_Size() int { + return xxx_messageInfo_CreateRequest.Size(m) +} +func (m *CreateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CreateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateRequest proto.InternalMessageInfo + +func (m *CreateRequest) GetChange() *Change { + if m != nil { + return m.Change + } + return nil +} + +type CreateResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateResponse) Reset() { *m = CreateResponse{} } +func (m *CreateResponse) String() string { return proto.CompactTextString(m) } +func (*CreateResponse) ProtoMessage() {} +func (*CreateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{3} +} + +func (m *CreateResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateResponse.Unmarshal(m, b) +} +func (m *CreateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateResponse.Marshal(b, m, deterministic) +} +func (m *CreateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateResponse.Merge(m, src) +} +func (m *CreateResponse) XXX_Size() int { + return xxx_messageInfo_CreateResponse.Size(m) +} +func (m *CreateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CreateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateResponse proto.InternalMessageInfo + +type UpdateRequest struct { + Change *Change `protobuf:"bytes,1,opt,name=change,proto3" json:"change,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } +func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } +func (*UpdateRequest) ProtoMessage() {} +func (*UpdateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{4} +} + +func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_UpdateRequest.Unmarshal(m, b) +} +func (m *UpdateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_UpdateRequest.Marshal(b, m, deterministic) +} +func (m *UpdateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateRequest.Merge(m, src) +} +func (m *UpdateRequest) XXX_Size() int { + return xxx_messageInfo_UpdateRequest.Size(m) +} +func (m *UpdateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdateRequest proto.InternalMessageInfo + +func (m *UpdateRequest) GetChange() *Change { + if m != nil { + return m.Change + } + return nil +} + +type UpdateResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } +func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } +func (*UpdateResponse) ProtoMessage() {} +func (*UpdateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{5} +} + +func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_UpdateResponse.Unmarshal(m, b) +} +func (m *UpdateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_UpdateResponse.Marshal(b, m, deterministic) +} +func (m *UpdateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateResponse.Merge(m, src) +} +func (m *UpdateResponse) XXX_Size() int { + return xxx_messageInfo_UpdateResponse.Size(m) +} +func (m *UpdateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdateResponse proto.InternalMessageInfo + +type DeleteRequest struct { + Change *Change `protobuf:"bytes,1,opt,name=change,proto3" json:"change,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } +func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } +func (*DeleteRequest) ProtoMessage() {} +func (*DeleteRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{6} +} + +func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteRequest.Unmarshal(m, b) +} +func (m *DeleteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteRequest.Marshal(b, m, deterministic) +} +func (m *DeleteRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteRequest.Merge(m, src) +} +func (m *DeleteRequest) XXX_Size() int { + return xxx_messageInfo_DeleteRequest.Size(m) +} +func (m *DeleteRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteRequest proto.InternalMessageInfo + +func (m *DeleteRequest) GetChange() *Change { + if m != nil { + return m.Change + } + return nil +} + +type DeleteResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } +func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } +func (*DeleteResponse) ProtoMessage() {} +func (*DeleteResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{7} +} + +func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteResponse.Unmarshal(m, b) +} +func (m *DeleteResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteResponse.Marshal(b, m, deterministic) +} +func (m *DeleteResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteResponse.Merge(m, src) +} +func (m *DeleteResponse) XXX_Size() int { + return xxx_messageInfo_DeleteResponse.Size(m) +} +func (m *DeleteResponse) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteResponse proto.InternalMessageInfo + +type ListRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListRequest) Reset() { *m = ListRequest{} } +func (m *ListRequest) String() string { return proto.CompactTextString(m) } +func (*ListRequest) ProtoMessage() {} +func (*ListRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{8} +} + +func (m *ListRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListRequest.Unmarshal(m, b) +} +func (m *ListRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListRequest.Marshal(b, m, deterministic) +} +func (m *ListRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListRequest.Merge(m, src) +} +func (m *ListRequest) XXX_Size() int { + return xxx_messageInfo_ListRequest.Size(m) +} +func (m *ListRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ListRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ListRequest proto.InternalMessageInfo + +type ListResponse struct { + Configs []*Change `protobuf:"bytes,1,rep,name=configs,proto3" json:"configs,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListResponse) Reset() { *m = ListResponse{} } +func (m *ListResponse) String() string { return proto.CompactTextString(m) } +func (*ListResponse) ProtoMessage() {} +func (*ListResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{9} +} + +func (m *ListResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListResponse.Unmarshal(m, b) +} +func (m *ListResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListResponse.Marshal(b, m, deterministic) +} +func (m *ListResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListResponse.Merge(m, src) +} +func (m *ListResponse) XXX_Size() int { + return xxx_messageInfo_ListResponse.Size(m) +} +func (m *ListResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ListResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ListResponse proto.InternalMessageInfo + +func (m *ListResponse) GetConfigs() []*Change { + if m != nil { + return m.Configs + } + return nil +} + +type ReadRequest struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ReadRequest) Reset() { *m = ReadRequest{} } +func (m *ReadRequest) String() string { return proto.CompactTextString(m) } +func (*ReadRequest) ProtoMessage() {} +func (*ReadRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{10} +} + +func (m *ReadRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ReadRequest.Unmarshal(m, b) +} +func (m *ReadRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ReadRequest.Marshal(b, m, deterministic) +} +func (m *ReadRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ReadRequest.Merge(m, src) +} +func (m *ReadRequest) XXX_Size() int { + return xxx_messageInfo_ReadRequest.Size(m) +} +func (m *ReadRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ReadRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ReadRequest proto.InternalMessageInfo + +func (m *ReadRequest) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *ReadRequest) GetPath() string { + if m != nil { + return m.Path + } + return "" +} + +type ReadResponse struct { + Change *Change `protobuf:"bytes,1,opt,name=change,proto3" json:"change,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ReadResponse) Reset() { *m = ReadResponse{} } +func (m *ReadResponse) String() string { return proto.CompactTextString(m) } +func (*ReadResponse) ProtoMessage() {} +func (*ReadResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{11} +} + +func (m *ReadResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ReadResponse.Unmarshal(m, b) +} +func (m *ReadResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ReadResponse.Marshal(b, m, deterministic) +} +func (m *ReadResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ReadResponse.Merge(m, src) +} +func (m *ReadResponse) XXX_Size() int { + return xxx_messageInfo_ReadResponse.Size(m) +} +func (m *ReadResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ReadResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ReadResponse proto.InternalMessageInfo + +func (m *ReadResponse) GetChange() *Change { + if m != nil { + return m.Change + } + return nil +} + +type WatchRequest struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *WatchRequest) Reset() { *m = WatchRequest{} } +func (m *WatchRequest) String() string { return proto.CompactTextString(m) } +func (*WatchRequest) ProtoMessage() {} +func (*WatchRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{12} +} + +func (m *WatchRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WatchRequest.Unmarshal(m, b) +} +func (m *WatchRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WatchRequest.Marshal(b, m, deterministic) +} +func (m *WatchRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_WatchRequest.Merge(m, src) +} +func (m *WatchRequest) XXX_Size() int { + return xxx_messageInfo_WatchRequest.Size(m) +} +func (m *WatchRequest) XXX_DiscardUnknown() { + xxx_messageInfo_WatchRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_WatchRequest proto.InternalMessageInfo + +func (m *WatchRequest) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +type WatchResponse struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + ChangeSet *ChangeSet `protobuf:"bytes,2,opt,name=changeSet,proto3" json:"changeSet,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *WatchResponse) Reset() { *m = WatchResponse{} } +func (m *WatchResponse) String() string { return proto.CompactTextString(m) } +func (*WatchResponse) ProtoMessage() {} +func (*WatchResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{13} +} + +func (m *WatchResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WatchResponse.Unmarshal(m, b) +} +func (m *WatchResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WatchResponse.Marshal(b, m, deterministic) +} +func (m *WatchResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_WatchResponse.Merge(m, src) +} +func (m *WatchResponse) XXX_Size() int { + return xxx_messageInfo_WatchResponse.Size(m) +} +func (m *WatchResponse) XXX_DiscardUnknown() { + xxx_messageInfo_WatchResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_WatchResponse proto.InternalMessageInfo + +func (m *WatchResponse) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *WatchResponse) GetChangeSet() *ChangeSet { + if m != nil { + return m.ChangeSet + } + return nil +} + +func init() { + proto.RegisterType((*ChangeSet)(nil), "ChangeSet") + proto.RegisterType((*Change)(nil), "Change") + proto.RegisterType((*CreateRequest)(nil), "CreateRequest") + proto.RegisterType((*CreateResponse)(nil), "CreateResponse") + proto.RegisterType((*UpdateRequest)(nil), "UpdateRequest") + proto.RegisterType((*UpdateResponse)(nil), "UpdateResponse") + proto.RegisterType((*DeleteRequest)(nil), "DeleteRequest") + proto.RegisterType((*DeleteResponse)(nil), "DeleteResponse") + proto.RegisterType((*ListRequest)(nil), "ListRequest") + proto.RegisterType((*ListResponse)(nil), "ListResponse") + proto.RegisterType((*ReadRequest)(nil), "ReadRequest") + proto.RegisterType((*ReadResponse)(nil), "ReadResponse") + proto.RegisterType((*WatchRequest)(nil), "WatchRequest") + proto.RegisterType((*WatchResponse)(nil), "WatchResponse") +} + +func init() { proto.RegisterFile("proto/mucp.proto", fileDescriptor_942f149553cfb65d) } + +var fileDescriptor_942f149553cfb65d = []byte{ + // 425 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xdd, 0x6e, 0xd3, 0x30, + 0x14, 0xc7, 0x93, 0xa6, 0xcb, 0xc8, 0xc9, 0x47, 0xab, 0x73, 0x81, 0xa2, 0x08, 0x89, 0x60, 0x09, + 0x29, 0x02, 0xc9, 0x1b, 0xdd, 0x23, 0x8c, 0x3b, 0xb8, 0xf2, 0x84, 0xe0, 0xd6, 0xa4, 0xde, 0x52, + 0x8d, 0x34, 0x21, 0x76, 0x2e, 0x78, 0x84, 0xbd, 0x35, 0x8a, 0xed, 0xb4, 0x49, 0x11, 0xb0, 0xde, + 0x9d, 0xcf, 0xbf, 0xff, 0x3d, 0xbf, 0x06, 0xd6, 0x6d, 0xd7, 0xa8, 0xe6, 0xaa, 0xee, 0xcb, 0x96, + 0xea, 0x90, 0x3c, 0xb9, 0x10, 0xdc, 0x56, 0x7c, 0xff, 0x20, 0xee, 0x84, 0x42, 0x84, 0xe5, 0x96, + 0x2b, 0x9e, 0xba, 0xb9, 0x5b, 0x44, 0x4c, 0xc7, 0x98, 0xc1, 0x8b, 0xb2, 0x12, 0xe5, 0xa3, 0xec, + 0xeb, 0x74, 0x91, 0xbb, 0x45, 0xc0, 0x0e, 0x39, 0xbe, 0x04, 0xff, 0xbe, 0xe9, 0x6a, 0xae, 0x52, + 0x4f, 0x77, 0x6c, 0x36, 0xd4, 0x65, 0xd3, 0x77, 0xa5, 0x48, 0x97, 0xa6, 0x6e, 0x32, 0x7c, 0x05, + 0x81, 0xda, 0xd5, 0x42, 0x2a, 0x5e, 0xb7, 0xe9, 0x45, 0x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ad, 0xe8, + 0x09, 0x54, 0x67, 0x18, 0x36, 0x90, 0x30, 0xa1, 0x33, 0xbe, 0xd9, 0x8a, 0x9e, 0xd0, 0xd3, 0xc3, + 0x86, 0x06, 0x26, 0x74, 0x06, 0x32, 0x5b, 0xd1, 0x13, 0x4c, 0x0e, 0xbe, 0x85, 0xe5, 0x40, 0x06, + 0x23, 0x3a, 0xe1, 0x95, 0xc5, 0x74, 0x8a, 0xcb, 0x8c, 0x0d, 0x87, 0xc5, 0x88, 0x4e, 0xa0, 0x64, + 0x31, 0x9d, 0x5e, 0x9b, 0x38, 0xf8, 0x0e, 0x2e, 0xf4, 0xb1, 0x30, 0xa6, 0xd3, 0xb3, 0x66, 0x09, + 0x9d, 0xdd, 0x90, 0x38, 0xd7, 0xee, 0x77, 0x5f, 0x7f, 0xdb, 0x37, 0xbf, 0x03, 0x00, 0x00, 0xff, + 0xff, 0x66, 0x66, 0xa8, 0x5d, 0xef, 0x03, 0x00, 0x00, +} diff --git a/config/source/mucp/proto/mucp.pb.micro.go b/config/source/mucp/proto/mucp.pb.micro.go new file mode 100644 index 00000000..088cd8ee --- /dev/null +++ b/config/source/mucp/proto/mucp.pb.micro.go @@ -0,0 +1,241 @@ +// Code generated by protoc-gen-micro. DO NOT EDIT. +// source: proto/mucp.proto + +package mucp + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +import ( + context "context" + client "github.com/micro/go-micro/client" + server "github.com/micro/go-micro/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 _ context.Context +var _ client.Option +var _ server.Option + +// Client API for Source service + +type SourceService interface { + Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) + Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) + List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) + Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) + Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Source_WatchService, error) +} + +type sourceService struct { + c client.Client + name string +} + +func NewSourceService(name string, c client.Client) SourceService { + if c == nil { + c = client.NewClient() + } + if len(name) == 0 { + name = "source" + } + return &sourceService{ + c: c, + name: name, + } +} + +func (c *sourceService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) { + req := c.c.NewRequest(c.name, "Source.Create", in) + out := new(CreateResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *sourceService) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) { + req := c.c.NewRequest(c.name, "Source.Update", in) + out := new(UpdateResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *sourceService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) { + req := c.c.NewRequest(c.name, "Source.Delete", in) + out := new(DeleteResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *sourceService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { + req := c.c.NewRequest(c.name, "Source.List", in) + out := new(ListResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *sourceService) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) { + req := c.c.NewRequest(c.name, "Source.Read", in) + out := new(ReadResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *sourceService) Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Source_WatchService, error) { + req := c.c.NewRequest(c.name, "Source.Watch", &WatchRequest{}) + 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 &sourceServiceWatch{stream}, nil +} + +type Source_WatchService interface { + SendMsg(interface{}) error + RecvMsg(interface{}) error + Close() error + Recv() (*WatchResponse, error) +} + +type sourceServiceWatch struct { + stream client.Stream +} + +func (x *sourceServiceWatch) Close() error { + return x.stream.Close() +} + +func (x *sourceServiceWatch) SendMsg(m interface{}) error { + return x.stream.Send(m) +} + +func (x *sourceServiceWatch) RecvMsg(m interface{}) error { + return x.stream.Recv(m) +} + +func (x *sourceServiceWatch) Recv() (*WatchResponse, error) { + m := new(WatchResponse) + err := x.stream.Recv(m) + if err != nil { + return nil, err + } + return m, nil +} + +// Server API for Source service + +type SourceHandler interface { + Create(context.Context, *CreateRequest, *CreateResponse) error + Update(context.Context, *UpdateRequest, *UpdateResponse) error + Delete(context.Context, *DeleteRequest, *DeleteResponse) error + List(context.Context, *ListRequest, *ListResponse) error + Read(context.Context, *ReadRequest, *ReadResponse) error + Watch(context.Context, *WatchRequest, Source_WatchStream) error +} + +func RegisterSourceHandler(s server.Server, hdlr SourceHandler, opts ...server.HandlerOption) error { + type source interface { + Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error + Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error + Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error + List(ctx context.Context, in *ListRequest, out *ListResponse) error + Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error + Watch(ctx context.Context, stream server.Stream) error + } + type Source struct { + source + } + h := &sourceHandler{hdlr} + return s.Handle(s.NewHandler(&Source{h}, opts...)) +} + +type sourceHandler struct { + SourceHandler +} + +func (h *sourceHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error { + return h.SourceHandler.Create(ctx, in, out) +} + +func (h *sourceHandler) Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error { + return h.SourceHandler.Update(ctx, in, out) +} + +func (h *sourceHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error { + return h.SourceHandler.Delete(ctx, in, out) +} + +func (h *sourceHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { + return h.SourceHandler.List(ctx, in, out) +} + +func (h *sourceHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error { + return h.SourceHandler.Read(ctx, in, out) +} + +func (h *sourceHandler) Watch(ctx context.Context, stream server.Stream) error { + m := new(WatchRequest) + if err := stream.Recv(m); err != nil { + return err + } + return h.SourceHandler.Watch(ctx, m, &sourceWatchStream{stream}) +} + +type Source_WatchStream interface { + SendMsg(interface{}) error + RecvMsg(interface{}) error + Close() error + Send(*WatchResponse) error +} + +type sourceWatchStream struct { + stream server.Stream +} + +func (x *sourceWatchStream) Close() error { + return x.stream.Close() +} + +func (x *sourceWatchStream) SendMsg(m interface{}) error { + return x.stream.Send(m) +} + +func (x *sourceWatchStream) RecvMsg(m interface{}) error { + return x.stream.Recv(m) +} + +func (x *sourceWatchStream) Send(m *WatchResponse) error { + return x.stream.Send(m) +} diff --git a/config/source/mucp/proto/mucp.proto b/config/source/mucp/proto/mucp.proto new file mode 100644 index 00000000..71bf99bc --- /dev/null +++ b/config/source/mucp/proto/mucp.proto @@ -0,0 +1,76 @@ +syntax = "proto3"; + +service Source { + rpc Create (CreateRequest) returns (CreateResponse) { + } + rpc Update (UpdateRequest) returns (UpdateResponse) { + } + rpc Delete (DeleteRequest) returns (DeleteResponse) { + } + rpc List (ListRequest) returns (ListResponse) { + } + rpc Read (ReadRequest) returns (ReadResponse) { + } + rpc Watch (WatchRequest) returns (stream WatchResponse) { + } +} + +message ChangeSet { + bytes data = 1; + string checksum = 2; + string format = 3; + string source = 4; + int64 timestamp = 5; +} + +message Change { + string key = 1; + string path = 2; + ChangeSet changeSet = 3; +} + +message CreateRequest { + Change change = 1; +} + +message CreateResponse { +} + +message UpdateRequest { + Change change = 1; +} + +message UpdateResponse { +} + +message DeleteRequest { + Change change = 1; +} + +message DeleteResponse { +} + +message ListRequest { +} + +message ListResponse { + repeated Change configs = 1; +} + +message ReadRequest { + string key = 1; + string path = 2; +} + +message ReadResponse { + Change change = 1; +} + +message WatchRequest { + string key = 1; +} + +message WatchResponse { + string key = 1; + ChangeSet changeSet = 2; +} \ No newline at end of file diff --git a/config/source/mucp/util.go b/config/source/mucp/util.go new file mode 100644 index 00000000..b1a8deec --- /dev/null +++ b/config/source/mucp/util.go @@ -0,0 +1,18 @@ +package mucp + +import ( + "time" + + "github.com/micro/go-micro/config/source" + proto "github.com/micro/go-micro/config/source/mucp/proto" +) + +func toChangeSet(c *proto.ChangeSet) *source.ChangeSet { + return &source.ChangeSet{ + Data: c.Data, + Checksum: c.Checksum, + Format: c.Format, + Timestamp: time.Unix(c.Timestamp, 0), + Source: c.Source, + } +} diff --git a/config/source/mucp/watcher.go b/config/source/mucp/watcher.go new file mode 100644 index 00000000..466703e9 --- /dev/null +++ b/config/source/mucp/watcher.go @@ -0,0 +1,27 @@ +package mucp + +import ( + "github.com/micro/go-micro/config/source" + proto "github.com/micro/go-micro/config/source/mucp/proto" +) + +type watcher struct { + stream proto.Source_WatchService +} + +func newWatcher(stream proto.Source_WatchService) (source.Watcher, error) { + return &watcher{stream: stream}, nil +} + +func (w *watcher) Next() (*source.ChangeSet, error) { + var rsp proto.WatchResponse + err := w.stream.RecvMsg(&rsp) + if err != nil { + return nil, err + } + return toChangeSet(rsp.ChangeSet), nil +} + +func (w *watcher) Stop() error { + return w.stream.Close() +} From a03791c5815e7a3c6cece48c4946bf2f54b60027 Mon Sep 17 00:00:00 2001 From: shu xian Date: Fri, 17 Jan 2020 21:32:00 +0800 Subject: [PATCH 2/6] set DefaultClient --- config/source/mucp/mucp.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/source/mucp/mucp.go b/config/source/mucp/mucp.go index eeb4bb84..119c74da 100644 --- a/config/source/mucp/mucp.go +++ b/config/source/mucp/mucp.go @@ -3,7 +3,7 @@ package mucp import ( "context" - "github.com/micro/go-micro/config/cmd" + "github.com/micro/go-micro/client" "github.com/micro/go-micro/config/source" proto "github.com/micro/go-micro/config/source/mucp/proto" "github.com/micro/go-micro/util/log" @@ -11,6 +11,7 @@ import ( var ( DefaultServiceName = "go.micro.config" + DefaultClient = client.DefaultClient ) type mucpSource struct { @@ -65,7 +66,7 @@ func NewSource(opts ...source.Option) source.Source { s := &mucpSource{ serviceName: addr, opts: options, - client: proto.NewSourceService(addr, *cmd.DefaultOptions().Client), + client: proto.NewSourceService(addr, DefaultClient), } return s From ad28b72dd3e56d8ceb57234cc5800245652f6edc Mon Sep 17 00:00:00 2001 From: shu xian Date: Fri, 17 Jan 2020 23:27:41 +0800 Subject: [PATCH 3/6] rename mucpSource to service --- config/source/mucp/mucp.go | 16 ++-- config/source/mucp/proto/mucp.pb.go | 56 +++++------ config/source/mucp/proto/mucp.pb.micro.go | 110 +++++++++++----------- config/source/mucp/proto/mucp.proto | 2 +- config/source/mucp/watcher.go | 4 +- 5 files changed, 94 insertions(+), 94 deletions(-) diff --git a/config/source/mucp/mucp.go b/config/source/mucp/mucp.go index 119c74da..72be5e9f 100644 --- a/config/source/mucp/mucp.go +++ b/config/source/mucp/mucp.go @@ -14,14 +14,14 @@ var ( DefaultClient = client.DefaultClient ) -type mucpSource struct { +type service struct { serviceName string key string opts source.Options - client proto.SourceService + client proto.Service } -func (m *mucpSource) Read() (set *source.ChangeSet, err error) { +func (m *service) Read() (set *source.ChangeSet, err error) { req, err := m.client.Read(context.Background(), &proto.ReadRequest{Path: m.key}) if err != nil { return nil, err @@ -30,7 +30,7 @@ func (m *mucpSource) Read() (set *source.ChangeSet, err error) { return toChangeSet(req.Change.ChangeSet), nil } -func (m *mucpSource) Watch() (w source.Watcher, err error) { +func (m *service) Watch() (w source.Watcher, err error) { stream, err := m.client.Watch(context.Background(), &proto.WatchRequest{Key: m.key}) if err != nil { log.Error("watch err: ", err) @@ -40,11 +40,11 @@ func (m *mucpSource) Watch() (w source.Watcher, err error) { } // Write is unsupported -func (m *mucpSource) Write(cs *source.ChangeSet) error { +func (m *service) Write(cs *source.ChangeSet) error { return nil } -func (m *mucpSource) String() string { +func (m *service) String() string { return "mucp" } @@ -63,10 +63,10 @@ func NewSource(opts ...source.Option) source.Source { } } - s := &mucpSource{ + s := &service{ serviceName: addr, opts: options, - client: proto.NewSourceService(addr, DefaultClient), + client: proto.NewService(addr, DefaultClient), } return s diff --git a/config/source/mucp/proto/mucp.pb.go b/config/source/mucp/proto/mucp.pb.go index b72b9070..08024585 100644 --- a/config/source/mucp/proto/mucp.pb.go +++ b/config/source/mucp/proto/mucp.pb.go @@ -618,32 +618,32 @@ func init() { func init() { proto.RegisterFile("proto/mucp.proto", fileDescriptor_942f149553cfb65d) } var fileDescriptor_942f149553cfb65d = []byte{ - // 425 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xdd, 0x6e, 0xd3, 0x30, - 0x14, 0xc7, 0x93, 0xa6, 0xcb, 0xc8, 0xc9, 0x47, 0xab, 0x73, 0x81, 0xa2, 0x08, 0x89, 0x60, 0x09, - 0x29, 0x02, 0xc9, 0x1b, 0xdd, 0x23, 0x8c, 0x3b, 0xb8, 0xf2, 0x84, 0xe0, 0xd6, 0xa4, 0xde, 0x52, - 0x8d, 0x34, 0x21, 0x76, 0x2e, 0x78, 0x84, 0xbd, 0x35, 0x8a, 0xed, 0xb4, 0x49, 0x11, 0xb0, 0xde, - 0x9d, 0xcf, 0xbf, 0xff, 0x3d, 0xbf, 0x06, 0xd6, 0x6d, 0xd7, 0xa8, 0xe6, 0xaa, 0xee, 0xcb, 0x96, - 0xea, 0x90, 0x3c, 0xb9, 0x10, 0xdc, 0x56, 0x7c, 0xff, 0x20, 0x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0xbd, 0xa9, 0xe4, 0x58, 0x27, 0x37, 0x10, 0x32, 0xc1, 0xb7, 0xa3, 0x87, 0x67, 0x1d, 0x9b, 0x5c, - 0x41, 0x64, 0x96, 0xec, 0x3b, 0xff, 0x75, 0x9e, 0x43, 0xf4, 0x95, 0xab, 0xb2, 0xfa, 0xeb, 0x33, - 0xe4, 0x13, 0xc4, 0x76, 0xc2, 0x6a, 0xfe, 0xe9, 0x64, 0x86, 0x78, 0xf1, 0x0f, 0xc4, 0x9b, 0xa7, - 0x05, 0xf8, 0x77, 0xe6, 0x5f, 0xf6, 0x1e, 0x7c, 0xc3, 0x0e, 0x13, 0x3a, 0xc3, 0x9e, 0xad, 0xe8, - 0x09, 0x54, 0x67, 0x18, 0x36, 0x90, 0x30, 0xa1, 0x33, 0xbe, 0xd9, 0x8a, 0x9e, 0xd0, 0xd3, 0xc3, - 0x86, 0x06, 0x26, 0x74, 0x06, 0x32, 0x5b, 0xd1, 0x13, 0x4c, 0x0e, 0xbe, 0x85, 0xe5, 0x40, 0x06, - 0x23, 0x3a, 0xe1, 0x95, 0xc5, 0x74, 0x8a, 0xcb, 0x8c, 0x0d, 0x87, 0xc5, 0x88, 0x4e, 0xa0, 0x64, - 0x31, 0x9d, 0x5e, 0x9b, 0x38, 0xf8, 0x0e, 0x2e, 0xf4, 0xb1, 0x30, 0xa6, 0xd3, 0xb3, 0x66, 0x09, - 0x9d, 0xdd, 0x90, 0x38, 0xd7, 0xee, 0x77, 0x5f, 0x7f, 0xdb, 0x37, 0xbf, 0x03, 0x00, 0x00, 0xff, - 0xff, 0x66, 0x66, 0xa8, 0x5d, 0xef, 0x03, 0x00, 0x00, + // 429 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xdd, 0x8a, 0xd3, 0x40, + 0x14, 0xc7, 0x9b, 0xb6, 0x9b, 0x9a, 0xd3, 0x24, 0x2d, 0xe7, 0x42, 0x42, 0x10, 0x8c, 0x03, 0x42, + 0x51, 0x98, 0x5d, 0xbb, 0x8f, 0xb0, 0xde, 0xe9, 0xd5, 0x2c, 0xa2, 0xb7, 0xe3, 0xf4, 0xec, 0xb6, + 0xac, 0x69, 0x62, 0x66, 0x2a, 0xf8, 0x08, 0xfa, 0xd4, 0x92, 0x99, 0xc9, 0x36, 0xa9, 0xf8, 0xd1, + 0xbb, 0xf3, 0xf9, 0x9f, 0x7f, 0xce, 0x8f, 0xc0, 0xb2, 0x6e, 0x2a, 0x53, 0x5d, 0x96, 0x07, 0x55, + 0x73, 0x1b, 0xb2, 0x1f, 0x01, 0x44, 0x37, 0x5b, 0xb9, 0xbf, 0xa7, 0x5b, 0x32, 0x88, 0x30, 0xdd, + 0x48, 0x23, 0xb3, 0xa0, 0x08, 0x56, 0xb1, 0xb0, 0x31, 0xe6, 0xf0, 0x44, 0x6d, 0x49, 0x3d, 0xe8, + 0x43, 0x99, 0x8d, 0x8b, 0x60, 0x15, 0x89, 0xc7, 0x1c, 0x9f, 0x42, 0x78, 0x57, 0x35, 0xa5, 0x34, + 0xd9, 0xc4, 0x76, 0x7c, 0xd6, 0xd6, 0x75, 0x75, 0x68, 0x14, 0x65, 0x53, 0x57, 0x77, 0x19, 0x3e, + 0x83, 0xc8, 0xec, 0x4a, 0xd2, 0x46, 0x96, 0x75, 0x76, 0x51, 0x04, 0xab, 0x89, 0x38, 0x16, 0xd8, + 0x27, 0x08, 0x9d, 0x15, 0x5c, 0xc2, 0xe4, 0x81, 0xbe, 0x5b, 0x1b, 0x91, 0x68, 0xc3, 0xd6, 0x59, + 0x2d, 0xcd, 0xd6, 0x3b, 0xb0, 0x31, 0xae, 0x20, 0x52, 0x9d, 0x75, 0x6b, 0x60, 0xbe, 0x06, 0xfe, + 0xf8, 0x31, 0xe2, 0xd8, 0x64, 0x57, 0x90, 0xdc, 0x34, 0x24, 0x0d, 0x09, 0xfa, 0x7a, 0x20, 0x6d, + 0xf0, 0x39,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d9, 0x08, 0x5f, 0xc1, 0x85, 0xbd, 0x16, 0x26, 0xbc, + 0x7f, 0xd7, 0x3c, 0xe5, 0x83, 0x23, 0xb2, 0xd1, 0x55, 0xf0, 0x39, 0xb4, 0x3f, 0xf7, 0xf5, 0xaf, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x75, 0xb2, 0x55, 0xf0, 0x03, 0x00, 0x00, } diff --git a/config/source/mucp/proto/mucp.pb.micro.go b/config/source/mucp/proto/mucp.pb.micro.go index 088cd8ee..430b7842 100644 --- a/config/source/mucp/proto/mucp.pb.micro.go +++ b/config/source/mucp/proto/mucp.pb.micro.go @@ -31,37 +31,37 @@ var _ context.Context var _ client.Option var _ server.Option -// Client API for Source service +// Client API for Service service -type SourceService interface { +type Service interface { Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) - Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Source_WatchService, error) + Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Service_WatchService, error) } -type sourceService struct { +type service struct { c client.Client name string } -func NewSourceService(name string, c client.Client) SourceService { +func NewService(name string, c client.Client) Service { if c == nil { c = client.NewClient() } if len(name) == 0 { - name = "source" + name = "service" } - return &sourceService{ + return &service{ c: c, name: name, } } -func (c *sourceService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) { - req := c.c.NewRequest(c.name, "Source.Create", in) +func (c *service) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) { + req := c.c.NewRequest(c.name, "Service.Create", in) out := new(CreateResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -70,8 +70,8 @@ func (c *sourceService) Create(ctx context.Context, in *CreateRequest, opts ...c return out, nil } -func (c *sourceService) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) { - req := c.c.NewRequest(c.name, "Source.Update", in) +func (c *service) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) { + req := c.c.NewRequest(c.name, "Service.Update", in) out := new(UpdateResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -80,8 +80,8 @@ func (c *sourceService) Update(ctx context.Context, in *UpdateRequest, opts ...c return out, nil } -func (c *sourceService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) { - req := c.c.NewRequest(c.name, "Source.Delete", in) +func (c *service) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) { + req := c.c.NewRequest(c.name, "Service.Delete", in) out := new(DeleteResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -90,8 +90,8 @@ func (c *sourceService) Delete(ctx context.Context, in *DeleteRequest, opts ...c return out, nil } -func (c *sourceService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { - req := c.c.NewRequest(c.name, "Source.List", in) +func (c *service) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { + req := c.c.NewRequest(c.name, "Service.List", in) out := new(ListResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -100,8 +100,8 @@ func (c *sourceService) List(ctx context.Context, in *ListRequest, opts ...clien return out, nil } -func (c *sourceService) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) { - req := c.c.NewRequest(c.name, "Source.Read", in) +func (c *service) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) { + req := c.c.NewRequest(c.name, "Service.Read", in) out := new(ReadResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -110,8 +110,8 @@ func (c *sourceService) Read(ctx context.Context, in *ReadRequest, opts ...clien return out, nil } -func (c *sourceService) Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Source_WatchService, error) { - req := c.c.NewRequest(c.name, "Source.Watch", &WatchRequest{}) +func (c *service) Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Service_WatchService, error) { + req := c.c.NewRequest(c.name, "Service.Watch", &WatchRequest{}) stream, err := c.c.Stream(ctx, req, opts...) if err != nil { return nil, err @@ -119,33 +119,33 @@ func (c *sourceService) Watch(ctx context.Context, in *WatchRequest, opts ...cli if err := stream.Send(in); err != nil { return nil, err } - return &sourceServiceWatch{stream}, nil + return &serviceWatch{stream}, nil } -type Source_WatchService interface { +type Service_WatchService interface { SendMsg(interface{}) error RecvMsg(interface{}) error Close() error Recv() (*WatchResponse, error) } -type sourceServiceWatch struct { +type serviceWatch struct { stream client.Stream } -func (x *sourceServiceWatch) Close() error { +func (x *serviceWatch) Close() error { return x.stream.Close() } -func (x *sourceServiceWatch) SendMsg(m interface{}) error { +func (x *serviceWatch) SendMsg(m interface{}) error { return x.stream.Send(m) } -func (x *sourceServiceWatch) RecvMsg(m interface{}) error { +func (x *serviceWatch) RecvMsg(m interface{}) error { return x.stream.Recv(m) } -func (x *sourceServiceWatch) Recv() (*WatchResponse, error) { +func (x *serviceWatch) Recv() (*WatchResponse, error) { m := new(WatchResponse) err := x.stream.Recv(m) if err != nil { @@ -154,19 +154,19 @@ func (x *sourceServiceWatch) Recv() (*WatchResponse, error) { return m, nil } -// Server API for Source service +// Server API for Service service -type SourceHandler interface { +type ServiceHandler interface { Create(context.Context, *CreateRequest, *CreateResponse) error Update(context.Context, *UpdateRequest, *UpdateResponse) error Delete(context.Context, *DeleteRequest, *DeleteResponse) error List(context.Context, *ListRequest, *ListResponse) error Read(context.Context, *ReadRequest, *ReadResponse) error - Watch(context.Context, *WatchRequest, Source_WatchStream) error + Watch(context.Context, *WatchRequest, Service_WatchStream) error } -func RegisterSourceHandler(s server.Server, hdlr SourceHandler, opts ...server.HandlerOption) error { - type source interface { +func RegisterServiceHandler(s server.Server, hdlr ServiceHandler, opts ...server.HandlerOption) error { + type service interface { Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error @@ -174,68 +174,68 @@ func RegisterSourceHandler(s server.Server, hdlr SourceHandler, opts ...server.H Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error Watch(ctx context.Context, stream server.Stream) error } - type Source struct { - source + type Service struct { + service } - h := &sourceHandler{hdlr} - return s.Handle(s.NewHandler(&Source{h}, opts...)) + h := &serviceHandler{hdlr} + return s.Handle(s.NewHandler(&Service{h}, opts...)) } -type sourceHandler struct { - SourceHandler +type serviceHandler struct { + ServiceHandler } -func (h *sourceHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error { - return h.SourceHandler.Create(ctx, in, out) +func (h *serviceHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error { + return h.ServiceHandler.Create(ctx, in, out) } -func (h *sourceHandler) Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error { - return h.SourceHandler.Update(ctx, in, out) +func (h *serviceHandler) Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error { + return h.ServiceHandler.Update(ctx, in, out) } -func (h *sourceHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error { - return h.SourceHandler.Delete(ctx, in, out) +func (h *serviceHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error { + return h.ServiceHandler.Delete(ctx, in, out) } -func (h *sourceHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { - return h.SourceHandler.List(ctx, in, out) +func (h *serviceHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { + return h.ServiceHandler.List(ctx, in, out) } -func (h *sourceHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error { - return h.SourceHandler.Read(ctx, in, out) +func (h *serviceHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error { + return h.ServiceHandler.Read(ctx, in, out) } -func (h *sourceHandler) Watch(ctx context.Context, stream server.Stream) error { +func (h *serviceHandler) Watch(ctx context.Context, stream server.Stream) error { m := new(WatchRequest) if err := stream.Recv(m); err != nil { return err } - return h.SourceHandler.Watch(ctx, m, &sourceWatchStream{stream}) + return h.ServiceHandler.Watch(ctx, m, &serviceWatchStream{stream}) } -type Source_WatchStream interface { +type Service_WatchStream interface { SendMsg(interface{}) error RecvMsg(interface{}) error Close() error Send(*WatchResponse) error } -type sourceWatchStream struct { +type serviceWatchStream struct { stream server.Stream } -func (x *sourceWatchStream) Close() error { +func (x *serviceWatchStream) Close() error { return x.stream.Close() } -func (x *sourceWatchStream) SendMsg(m interface{}) error { +func (x *serviceWatchStream) SendMsg(m interface{}) error { return x.stream.Send(m) } -func (x *sourceWatchStream) RecvMsg(m interface{}) error { +func (x *serviceWatchStream) RecvMsg(m interface{}) error { return x.stream.Recv(m) } -func (x *sourceWatchStream) Send(m *WatchResponse) error { +func (x *serviceWatchStream) Send(m *WatchResponse) error { return x.stream.Send(m) } diff --git a/config/source/mucp/proto/mucp.proto b/config/source/mucp/proto/mucp.proto index 71bf99bc..2e88c7e5 100644 --- a/config/source/mucp/proto/mucp.proto +++ b/config/source/mucp/proto/mucp.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -service Source { +service Service { rpc Create (CreateRequest) returns (CreateResponse) { } rpc Update (UpdateRequest) returns (UpdateResponse) { diff --git a/config/source/mucp/watcher.go b/config/source/mucp/watcher.go index 466703e9..fd6fb6fe 100644 --- a/config/source/mucp/watcher.go +++ b/config/source/mucp/watcher.go @@ -6,10 +6,10 @@ import ( ) type watcher struct { - stream proto.Source_WatchService + stream proto.Service_WatchService } -func newWatcher(stream proto.Source_WatchService) (source.Watcher, error) { +func newWatcher(stream proto.Service_WatchService) (source.Watcher, error) { return &watcher{stream: stream}, nil } From 9ea4919b9b64a41a3334789e8520d231be6c35df Mon Sep 17 00:00:00 2001 From: shu xian Date: Fri, 17 Jan 2020 23:53:33 +0800 Subject: [PATCH 4/6] rename mucp source directory to service --- config/source/{mucp => service}/mucp.go | 4 ++-- config/source/{mucp => service}/options.go | 2 +- config/source/{mucp => service}/proto/mucp.pb.go | 0 config/source/{mucp => service}/proto/mucp.pb.micro.go | 0 config/source/{mucp => service}/proto/mucp.proto | 0 config/source/{mucp => service}/util.go | 4 ++-- config/source/{mucp => service}/watcher.go | 4 ++-- 7 files changed, 7 insertions(+), 7 deletions(-) rename config/source/{mucp => service}/mucp.go (94%) rename config/source/{mucp => service}/options.go (95%) rename config/source/{mucp => service}/proto/mucp.pb.go (100%) rename config/source/{mucp => service}/proto/mucp.pb.micro.go (100%) rename config/source/{mucp => service}/proto/mucp.proto (100%) rename config/source/{mucp => service}/util.go (78%) rename config/source/{mucp => service}/watcher.go (86%) diff --git a/config/source/mucp/mucp.go b/config/source/service/mucp.go similarity index 94% rename from config/source/mucp/mucp.go rename to config/source/service/mucp.go index 72be5e9f..3f5ee0fe 100644 --- a/config/source/mucp/mucp.go +++ b/config/source/service/mucp.go @@ -1,11 +1,11 @@ -package mucp +package service import ( "context" "github.com/micro/go-micro/client" "github.com/micro/go-micro/config/source" - proto "github.com/micro/go-micro/config/source/mucp/proto" + proto "github.com/micro/go-micro/config/source/service/proto" "github.com/micro/go-micro/util/log" ) diff --git a/config/source/mucp/options.go b/config/source/service/options.go similarity index 95% rename from config/source/mucp/options.go rename to config/source/service/options.go index c8717cbd..ac4079e9 100644 --- a/config/source/mucp/options.go +++ b/config/source/service/options.go @@ -1,4 +1,4 @@ -package mucp +package service import ( "context" diff --git a/config/source/mucp/proto/mucp.pb.go b/config/source/service/proto/mucp.pb.go similarity index 100% rename from config/source/mucp/proto/mucp.pb.go rename to config/source/service/proto/mucp.pb.go diff --git a/config/source/mucp/proto/mucp.pb.micro.go b/config/source/service/proto/mucp.pb.micro.go similarity index 100% rename from config/source/mucp/proto/mucp.pb.micro.go rename to config/source/service/proto/mucp.pb.micro.go diff --git a/config/source/mucp/proto/mucp.proto b/config/source/service/proto/mucp.proto similarity index 100% rename from config/source/mucp/proto/mucp.proto rename to config/source/service/proto/mucp.proto diff --git a/config/source/mucp/util.go b/config/source/service/util.go similarity index 78% rename from config/source/mucp/util.go rename to config/source/service/util.go index b1a8deec..eb248356 100644 --- a/config/source/mucp/util.go +++ b/config/source/service/util.go @@ -1,10 +1,10 @@ -package mucp +package service import ( "time" "github.com/micro/go-micro/config/source" - proto "github.com/micro/go-micro/config/source/mucp/proto" + proto "github.com/micro/go-micro/config/source/service/proto" ) func toChangeSet(c *proto.ChangeSet) *source.ChangeSet { diff --git a/config/source/mucp/watcher.go b/config/source/service/watcher.go similarity index 86% rename from config/source/mucp/watcher.go rename to config/source/service/watcher.go index fd6fb6fe..d604dddf 100644 --- a/config/source/mucp/watcher.go +++ b/config/source/service/watcher.go @@ -1,8 +1,8 @@ -package mucp +package service import ( "github.com/micro/go-micro/config/source" - proto "github.com/micro/go-micro/config/source/mucp/proto" + proto "github.com/micro/go-micro/config/source/service/proto" ) type watcher struct { From 8d6f82707a2ad2afec3ef641ea8832ff03ee292d Mon Sep 17 00:00:00 2001 From: shu xian Date: Sat, 18 Jan 2020 23:16:23 +0800 Subject: [PATCH 5/6] update to standard name convention --- .../proto/{mucp.pb.go => service.pb.go} | 98 +++++++++---------- .../{mucp.pb.micro.go => service.pb.micro.go} | 4 +- .../proto/{mucp.proto => service.proto} | 32 +++--- config/source/service/{mucp.go => service.go} | 8 +- 4 files changed, 66 insertions(+), 76 deletions(-) rename config/source/service/proto/{mucp.pb.go => service.pb.go} (83%) rename config/source/service/proto/{mucp.pb.micro.go => service.pb.micro.go} (99%) rename config/source/service/proto/{mucp.proto => service.proto} (57%) rename config/source/service/{mucp.go => service.go} (91%) diff --git a/config/source/service/proto/mucp.pb.go b/config/source/service/proto/service.pb.go similarity index 83% rename from config/source/service/proto/mucp.pb.go rename to config/source/service/proto/service.pb.go index 08024585..85ba138f 100644 --- a/config/source/service/proto/mucp.pb.go +++ b/config/source/service/proto/service.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: proto/mucp.proto +// source: proto/service.proto -package mucp +package service import ( fmt "fmt" @@ -35,7 +35,7 @@ func (m *ChangeSet) Reset() { *m = ChangeSet{} } func (m *ChangeSet) String() string { return proto.CompactTextString(m) } func (*ChangeSet) ProtoMessage() {} func (*ChangeSet) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{0} + return fileDescriptor_c33392ef2c1961ba, []int{0} } func (m *ChangeSet) XXX_Unmarshal(b []byte) error { @@ -104,7 +104,7 @@ func (m *Change) Reset() { *m = Change{} } func (m *Change) String() string { return proto.CompactTextString(m) } func (*Change) ProtoMessage() {} func (*Change) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{1} + return fileDescriptor_c33392ef2c1961ba, []int{1} } func (m *Change) XXX_Unmarshal(b []byte) error { @@ -157,7 +157,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{2} + return fileDescriptor_c33392ef2c1961ba, []int{2} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -195,7 +195,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{3} + return fileDescriptor_c33392ef2c1961ba, []int{3} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -227,7 +227,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{4} + return fileDescriptor_c33392ef2c1961ba, []int{4} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -265,7 +265,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{5} + return fileDescriptor_c33392ef2c1961ba, []int{5} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -297,7 +297,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{6} + return fileDescriptor_c33392ef2c1961ba, []int{6} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -335,7 +335,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{7} + return fileDescriptor_c33392ef2c1961ba, []int{7} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -366,7 +366,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{8} + return fileDescriptor_c33392ef2c1961ba, []int{8} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -388,7 +388,7 @@ func (m *ListRequest) XXX_DiscardUnknown() { var xxx_messageInfo_ListRequest proto.InternalMessageInfo type ListResponse struct { - Configs []*Change `protobuf:"bytes,1,rep,name=configs,proto3" json:"configs,omitempty"` + Values []*Change `protobuf:"bytes,1,rep,name=values,proto3" json:"values,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -398,7 +398,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{9} + return fileDescriptor_c33392ef2c1961ba, []int{9} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -419,9 +419,9 @@ func (m *ListResponse) XXX_DiscardUnknown() { var xxx_messageInfo_ListResponse proto.InternalMessageInfo -func (m *ListResponse) GetConfigs() []*Change { +func (m *ListResponse) GetValues() []*Change { if m != nil { - return m.Configs + return m.Values } return nil } @@ -438,7 +438,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{10} + return fileDescriptor_c33392ef2c1961ba, []int{10} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -484,7 +484,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{11} + return fileDescriptor_c33392ef2c1961ba, []int{11} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -523,7 +523,7 @@ func (m *WatchRequest) Reset() { *m = WatchRequest{} } func (m *WatchRequest) String() string { return proto.CompactTextString(m) } func (*WatchRequest) ProtoMessage() {} func (*WatchRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{12} + return fileDescriptor_c33392ef2c1961ba, []int{12} } func (m *WatchRequest) XXX_Unmarshal(b []byte) error { @@ -563,7 +563,7 @@ func (m *WatchResponse) Reset() { *m = WatchResponse{} } func (m *WatchResponse) String() string { return proto.CompactTextString(m) } func (*WatchResponse) ProtoMessage() {} func (*WatchResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{13} + return fileDescriptor_c33392ef2c1961ba, []int{13} } func (m *WatchResponse) XXX_Unmarshal(b []byte) error { @@ -615,35 +615,35 @@ func init() { proto.RegisterType((*WatchResponse)(nil), "WatchResponse") } -func init() { proto.RegisterFile("proto/mucp.proto", fileDescriptor_942f149553cfb65d) } +func init() { proto.RegisterFile("proto/service.proto", fileDescriptor_c33392ef2c1961ba) } -var fileDescriptor_942f149553cfb65d = []byte{ - // 429 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xdd, 0x8a, 0xd3, 0x40, - 0x14, 0xc7, 0x9b, 0xb6, 0x9b, 0x9a, 0xd3, 0x24, 0x2d, 0xe7, 0x42, 0x42, 0x10, 0x8c, 0x03, 0x42, - 0x51, 0x98, 0x5d, 0xbb, 0x8f, 0xb0, 0xde, 0xe9, 0xd5, 0x2c, 0xa2, 0xb7, 0xe3, 0xf4, 0xec, 0xb6, - 0xac, 0x69, 0x62, 0x66, 0x2a, 0xf8, 0x08, 0xfa, 0xd4, 0x92, 0x99, 0xc9, 0x36, 0xa9, 0xf8, 0xd1, - 0xbb, 0xf3, 0xf9, 0x9f, 0x7f, 0xce, 0x8f, 0xc0, 0xb2, 0x6e, 0x2a, 0x53, 0x5d, 0x96, 0x07, 0x55, - 0x73, 0x1b, 0xb2, 0x1f, 0x01, 0x44, 0x37, 0x5b, 0xb9, 0xbf, 0xa7, 0x5b, 0x32, 0x88, 0x30, 0xdd, - 0x48, 0x23, 0xb3, 0xa0, 0x08, 0x56, 0xb1, 0xb0, 0x31, 0xe6, 0xf0, 0x44, 0x6d, 0x49, 0x3d, 0xe8, - 0x43, 0x99, 0x8d, 0x8b, 0x60, 0x15, 0x89, 0xc7, 0x1c, 0x9f, 0x42, 0x78, 0x57, 0x35, 0xa5, 0x34, - 0xd9, 0xc4, 0x76, 0x7c, 0xd6, 0xd6, 0x75, 0x75, 0x68, 0x14, 0x65, 0x53, 0x57, 0x77, 0x19, 0x3e, - 0x83, 0xc8, 0xec, 0x4a, 0xd2, 0x46, 0x96, 0x75, 0x76, 0x51, 0x04, 0xab, 0x89, 0x38, 0x16, 0xd8, - 0x27, 0x08, 0x9d, 0x15, 0x5c, 0xc2, 0xe4, 0x81, 0xbe, 0x5b, 0x1b, 0x91, 0x68, 0xc3, 0xd6, 0x59, - 0x2d, 0xcd, 0xd6, 0x3b, 0xb0, 0x31, 0xae, 0x20, 0x52, 0x9d, 0x75, 0x6b, 0x60, 0xbe, 0x06, 0xfe, - 0xf8, 0x31, 0xe2, 0xd8, 0x64, 0x57, 0x90, 0xdc, 0x34, 0x24, 0x0d, 0x09, 0xfa, 0x7a, 0x20, 0x6d, - 0xf0, 0x39, 0x84, 0xae, 0x6b, 0xdf, 0x98, 0xaf, 0x67, 0x7e, 0x4f, 0xf8, 0x32, 0x5b, 0x42, 0xda, - 0x6d, 0xe8, 0xba, 0xda, 0x6b, 0x6a, 0x35, 0x3e, 0xd4, 0x9b, 0x33, 0x35, 0xba, 0x8d, 0xa3, 0xc6, - 0x5b, 0xfa, 0x42, 0xe7, 0x69, 0x74, 0x1b, 0x5e, 0x23, 0x81, 0xf9, 0xfb, 0x9d, 0x36, 0x5e, 0x81, - 0xbd, 0x81, 0xd8, 0xa5, 0xae, 0x8d, 0x2f, 0x60, 0xa6, 0xaa, 0xfd, 0xdd, 0xee, 0x5e, 0x67, 0x41, - 0x31, 0xe9, 0x4b, 0x76, 0x75, 0x76, 0x0d, 0x73, 0x41, 0x72, 0xd3, 0x79, 0xf8, 0xaf, 0x63, 0xb3, - 0x4b, 0x88, 0xdd, 0x92, 0x7f, 0xe7, 0x9f, 0xce, 0x0b, 0x88, 0x3f, 0x4a, 0xa3, 0xb6, 0x7f, 0x7c, - 0x86, 0xbd, 0x83, 0xc4, 0x4f, 0x78, 0xcd, 0xdf, 0x9d, 0x0c, 0x10, 0x8f, 0xff, 0x82, 0x78, 0xfd, - 0x73, 0x0c, 0xb3, 0x5b, 0x6a, 0xbe, 0xed, 0x14, 0xe1, 0x6b, 0x08, 0x1d, 0x3c, 0x4c, 0xf9, 0x80, - 0x7b, 0xbe, 0xe0, 0x27, 0x54, 0x47, 0xed, 0xb0, 0xa3, 0x84, 0x29, 0x1f, 0x00, 0xce, 0x17, 0xfc, - 0x04, 0x9f, 0x1d, 0x76, 0x38, 0x30, 0xe5, 0x03, 0x92, 0xf9, 0x82, 0x9f, 0x70, 0x1a, 0xe1, 0x4b, - 0x98, 0xb6, 0x68, 0x30, 0xe6, 0x3d, 0x60, 0x79, 0xc2, 0xfb, 0xbc, 0xdc, 0x58, 0x7b, 0x59, 0x8c, - 0x79, 0x8f, 0x4a, 0x9e, 0xf0, 0xfe, 0xb9, 0xd9, 0x08, 0x5f, 0xc1, 0x85, 0xbd, 0x16, 0x26, 0xbc, - 0x7f, 0xd7, 0x3c, 0xe5, 0x83, 0x23, 0xb2, 0xd1, 0x55, 0xf0, 0x39, 0xb4, 0x3f, 0xf7, 0xf5, 0xaf, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x75, 0xb2, 0x55, 0xf0, 0x03, 0x00, 0x00, +var fileDescriptor_c33392ef2c1961ba = []byte{ + // 425 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xdb, 0x6a, 0xdb, 0x40, + 0x10, 0x86, 0x2d, 0xdb, 0x51, 0xaa, 0xb1, 0x24, 0x87, 0x29, 0x14, 0x21, 0x0a, 0x15, 0x0b, 0x05, + 0xd3, 0xc2,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f, 0x35, 0x4f, + 0xf9, 0xe4, 0x88, 0x6c, 0x76, 0x11, 0x7c, 0x0b, 0xed, 0xa7, 0x7d, 0xf9, 0x37, 0x00, 0x00, 0xff, + 0xff, 0x85, 0xa3, 0x8e, 0x20, 0xf1, 0x03, 0x00, 0x00, } diff --git a/config/source/service/proto/mucp.pb.micro.go b/config/source/service/proto/service.pb.micro.go similarity index 99% rename from config/source/service/proto/mucp.pb.micro.go rename to config/source/service/proto/service.pb.micro.go index 430b7842..e3847a25 100644 --- a/config/source/service/proto/mucp.pb.micro.go +++ b/config/source/service/proto/service.pb.micro.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: proto/mucp.proto +// source: proto/service.proto -package mucp +package service import ( fmt "fmt" diff --git a/config/source/service/proto/mucp.proto b/config/source/service/proto/service.proto similarity index 57% rename from config/source/service/proto/mucp.proto rename to config/source/service/proto/service.proto index 2e88c7e5..bce92dbe 100644 --- a/config/source/service/proto/mucp.proto +++ b/config/source/service/proto/service.proto @@ -1,18 +1,12 @@ syntax = "proto3"; service Service { - rpc Create (CreateRequest) returns (CreateResponse) { - } - rpc Update (UpdateRequest) returns (UpdateResponse) { - } - rpc Delete (DeleteRequest) returns (DeleteResponse) { - } - rpc List (ListRequest) returns (ListResponse) { - } - rpc Read (ReadRequest) returns (ReadResponse) { - } - rpc Watch (WatchRequest) returns (stream WatchResponse) { - } + rpc Create (CreateRequest) returns (CreateResponse) {} + rpc Update (UpdateRequest) returns (UpdateResponse) {} + rpc Delete (DeleteRequest) returns (DeleteResponse) {} + rpc List (ListRequest) returns (ListResponse) {} + rpc Read (ReadRequest) returns (ReadResponse) {} + rpc Watch (WatchRequest) returns (stream WatchResponse) {} } message ChangeSet { @@ -33,28 +27,24 @@ message CreateRequest { Change change = 1; } -message CreateResponse { -} +message CreateResponse {} message UpdateRequest { Change change = 1; } -message UpdateResponse { -} +message UpdateResponse {} message DeleteRequest { Change change = 1; } -message DeleteResponse { -} +message DeleteResponse {} -message ListRequest { -} +message ListRequest {} message ListResponse { - repeated Change configs = 1; + repeated Change values = 1; } message ReadRequest { diff --git a/config/source/service/mucp.go b/config/source/service/service.go similarity index 91% rename from config/source/service/mucp.go rename to config/source/service/service.go index 3f5ee0fe..9d053126 100644 --- a/config/source/service/mucp.go +++ b/config/source/service/service.go @@ -10,8 +10,8 @@ import ( ) var ( - DefaultServiceName = "go.micro.config" - DefaultClient = client.DefaultClient + DefaultName = "go.micro.config" + DefaultClient = client.DefaultClient ) type service struct { @@ -45,7 +45,7 @@ func (m *service) Write(cs *source.ChangeSet) error { } func (m *service) String() string { - return "mucp" + return "service" } func NewSource(opts ...source.Option) source.Source { @@ -54,7 +54,7 @@ func NewSource(opts ...source.Option) source.Source { o(&options) } - addr := DefaultServiceName + addr := DefaultName if options.Context != nil { a, ok := options.Context.Value(serviceNameKey{}).(string) From 94bb0f4c085f89a2609f31b48c8ef445fe9b7a20 Mon Sep 17 00:00:00 2001 From: shu xian Date: Mon, 20 Jan 2020 18:31:18 +0800 Subject: [PATCH 6/6] watch supports path --- config/source/service/options.go | 24 ++++++- .../{service.pb.micro.go => service.micro.go} | 0 config/source/service/proto/service.pb.go | 64 +++++++++++-------- config/source/service/proto/service.proto | 1 + config/source/service/service.go | 21 +++++- 5 files changed, 78 insertions(+), 32 deletions(-) rename config/source/service/proto/{service.pb.micro.go => service.micro.go} (100%) diff --git a/config/source/service/options.go b/config/source/service/options.go index ac4079e9..1075a4ac 100644 --- a/config/source/service/options.go +++ b/config/source/service/options.go @@ -7,12 +7,32 @@ import ( ) type serviceNameKey struct{} +type keyKey struct{} +type pathKey struct{} -func ServiceName(a string) source.Option { +func ServiceName(name string) source.Option { return func(o *source.Options) { if o.Context == nil { o.Context = context.Background() } - o.Context = context.WithValue(o.Context, serviceNameKey{}, a) + o.Context = context.WithValue(o.Context, serviceNameKey{}, name) + } +} + +func Key(key string) source.Option { + return func(o *source.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, keyKey{}, key) + } +} + +func Path(path string) source.Option { + return func(o *source.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, pathKey{}, path) } } diff --git a/config/source/service/proto/service.pb.micro.go b/config/source/service/proto/service.micro.go similarity index 100% rename from config/source/service/proto/service.pb.micro.go rename to config/source/service/proto/service.micro.go diff --git a/config/source/service/proto/service.pb.go b/config/source/service/proto/service.pb.go index 85ba138f..667d3c76 100644 --- a/config/source/service/proto/service.pb.go +++ b/config/source/service/proto/service.pb.go @@ -514,6 +514,7 @@ func (m *ReadResponse) GetChange() *Change { type WatchRequest struct { Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -551,6 +552,13 @@ func (m *WatchRequest) GetKey() string { return "" } +func (m *WatchRequest) GetPath() string { + if m != nil { + return m.Path + } + return "" +} + type WatchResponse struct { Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` ChangeSet *ChangeSet `protobuf:"bytes,2,opt,name=changeSet,proto3" json:"changeSet,omitempty"` @@ -618,32 +626,32 @@ func init() { func init() { proto.RegisterFile("proto/service.proto", fileDescriptor_c33392ef2c1961ba) } var fileDescriptor_c33392ef2c1961ba = []byte{ - // 425 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xdb, 0x6a, 0xdb, 0x40, - 0x10, 0x86, 0x2d, 0xdb, 0x51, 0xaa, 0xb1, 0x24, 0x87, 0x29, 0x14, 0x21, 0x0a, 0x15, 0x0b, 0x05, - 0xd3, 0xc2, 0x26, 0x38, 0x8f, 0x90, 0xde, 0xb5, 0x57, 0x1b, 0x4a, 0x7b, 0xbb, 0x95, 0xa7, 0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d, 0xf9, 0x37, 0x00, 0x00, 0xff, - 0xff, 0x85, 0xa3, 0x8e, 0x20, 0xf1, 0x03, 0x00, 0x00, + // 427 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xcf, 0x6a, 0xdb, 0x40, + 0x10, 0xc6, 0x2d, 0xdb, 0x51, 0xaa, 0xb1, 0x24, 0x87, 0x29, 0x14, 0x21, 0x0a, 0x35, 0x0b, 0x05, + 0xd3, 0xc2, 0x26, 0x38, 0x7d, 0x83, 0xf4, 0xd6, 0x9e, 0x36, 0x94, 0xf6, 0xba, 0x95, 0xa7, 0xb5, + 0x49, 0x14, 0xa9, 0xda, 0x55, 0xa0, 0x8f, 0xd0, 0x3e, 0x75, 0xd9, 0x3f, 0x8a, 0x24, 0x17, 0x4c, + 0x7c, 0xdb, 0x99, 0xd9, 0xf9, 0xe6, 0xd3, 0xfc, 0x56, 0xf0, 0xb2, 0x6e, 0x2a, 0x5d, 0x5d, 0x2a, + 0x6a, 0x1e, 0xf7, 0x05, 0x71, 0x1b, 0xb1, 0x3f, 0x01, 0x44, 0x37, 0x3b, 0xf9, 0xf0, 0x93, 0x6e, + 0x49, 0x23, 0xc2, 0x7c, 0x2b, 0xb5, 0xcc, 0x82, 0x55, 0xb0, 0x8e, 0x85, 0x3d, 0x63, 0x0e, 0x2f, + 0x8a, 0x1d, 0x15, 0x77, 0xaa, 0x2d, 0xb3, 0xe9, 0x2a, 0x58, 0x47, 0xe2, 0x29, 0xc6, 0x57, 0x10, + 0xfe, 0xa8, 0x9a, 0x52, 0xea, 0x6c, 0x66, 0x2b, 0x3e, 0x32, 0x79, 0x55, 0xb5, 0x4d, 0x41, 0xd9, + 0xdc, 0xe5, 0x5d, 0x84, 0xaf, 0x21, 0xd2, 0xfb, 0x92, 0x94, 0x96, 0x65, 0x9d, 0x9d, 0xad, 0x82, + 0xf5, 0x4c, 0xf4, 0x09,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0x84, 0x3c, 0x5f, 0xf2, 0x03, 0xa0, + 0xf6, 0xb2, 0x03, 0x84, 0x29, 0x1f, 0xb1, 0xcd, 0x97, 0xfc, 0x80, 0xdc, 0x04, 0xdf, 0xc2, 0xdc, + 0xc0, 0xc2, 0x98, 0x0f, 0x10, 0xe6, 0x09, 0x1f, 0x12, 0x74, 0xd7, 0xcc, 0xb6, 0x31, 0xe6, 0x03, + 0x52, 0x79, 0xc2, 0x87, 0x08, 0xd8, 0x04, 0xdf, 0xc1, 0x99, 0xdd, 0x16, 0x26, 0x7c, 0xb8, 0xeb, + 0x3c, 0xe5, 0xa3, 0x25, 0xb2, 0xc9, 0x55, 0xf0, 0x3d, 0xb4, 0xbf, 0xfb, 0xf5, 0xbf, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xc3, 0x45, 0xac, 0x57, 0x05, 0x04, 0x00, 0x00, } diff --git a/config/source/service/proto/service.proto b/config/source/service/proto/service.proto index bce92dbe..1ffcaec3 100644 --- a/config/source/service/proto/service.proto +++ b/config/source/service/proto/service.proto @@ -58,6 +58,7 @@ message ReadResponse { message WatchRequest { string key = 1; + string path = 2; } message WatchResponse { diff --git a/config/source/service/service.go b/config/source/service/service.go index 9d053126..67cb20e1 100644 --- a/config/source/service/service.go +++ b/config/source/service/service.go @@ -11,18 +11,21 @@ import ( var ( DefaultName = "go.micro.config" + DefaultKey = "NAMESPACE:CONFIG" + DefaultPath = "" DefaultClient = client.DefaultClient ) type service struct { serviceName string key string + path string opts source.Options client proto.Service } func (m *service) Read() (set *source.ChangeSet, err error) { - req, err := m.client.Read(context.Background(), &proto.ReadRequest{Path: m.key}) + req, err := m.client.Read(context.Background(), &proto.ReadRequest{Key: m.key, Path: m.path}) if err != nil { return nil, err } @@ -31,7 +34,7 @@ func (m *service) Read() (set *source.ChangeSet, err error) { } func (m *service) Watch() (w source.Watcher, err error) { - stream, err := m.client.Watch(context.Background(), &proto.WatchRequest{Key: m.key}) + stream, err := m.client.Watch(context.Background(), &proto.WatchRequest{Key: m.key, Path: m.path}) if err != nil { log.Error("watch err: ", err) return @@ -55,17 +58,31 @@ func NewSource(opts ...source.Option) source.Source { } addr := DefaultName + key := DefaultKey + path := DefaultPath if options.Context != nil { a, ok := options.Context.Value(serviceNameKey{}).(string) if ok { addr = a } + + k, ok := options.Context.Value(keyKey{}).(string) + if ok { + key = k + } + + p, ok := options.Context.Value(pathKey{}).(string) + if ok { + path = p + } } s := &service{ serviceName: addr, opts: options, + key: key, + path: path, client: proto.NewService(addr, DefaultClient), }