diff --git a/ask/.gitignore b/answer/.gitignore similarity index 100% rename from ask/.gitignore rename to answer/.gitignore diff --git a/answer/Dockerfile b/answer/Dockerfile new file mode 100644 index 0000000..ac1950e --- /dev/null +++ b/answer/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine +ADD answer /answer +ENTRYPOINT [ "/answer" ] diff --git a/ask/Makefile b/answer/Makefile similarity index 68% rename from ask/Makefile rename to answer/Makefile index f9ca6aa..8e50468 100644 --- a/ask/Makefile +++ b/answer/Makefile @@ -9,15 +9,15 @@ init: .PHONY: api api: - protoc --openapi_out=. --proto_path=. proto/ask.proto + protoc --openapi_out=. --proto_path=. proto/answer.proto .PHONY: proto proto: - protoc --proto_path=. --micro_out=. --go_out=:. proto/ask.proto + protoc --proto_path=. --micro_out=. --go_out=:. proto/answer.proto .PHONY: build build: - go build -o ask *.go + go build -o answer *.go .PHONY: test test: @@ -25,4 +25,4 @@ test: .PHONY: docker docker: - docker build . -t ask:latest + docker build . -t answer:latest diff --git a/ask/README.md b/answer/README.md similarity index 100% rename from ask/README.md rename to answer/README.md diff --git a/ask/examples.json b/answer/examples.json similarity index 100% rename from ask/examples.json rename to answer/examples.json diff --git a/ask/generate.go b/answer/generate.go similarity index 100% rename from ask/generate.go rename to answer/generate.go diff --git a/ask/handler/ask.go b/answer/handler/answer.go similarity index 75% rename from ask/handler/ask.go rename to answer/handler/answer.go index 8d98e25..593f1bd 100644 --- a/ask/handler/ask.go +++ b/answer/handler/answer.go @@ -5,19 +5,19 @@ import ( "github.com/m3o/goduckgo/goduckgo" "github.com/micro/micro/v3/service/errors" - pb "github.com/micro/services/ask/proto" + pb "github.com/micro/services/answer/proto" ) -type Ask struct{} +type Answer struct{} -func (a *Ask) Question(ctx context.Context, req *pb.QuestionRequest, rsp *pb.QuestionResponse) error { +func (a *Answer) Question(ctx context.Context, req *pb.QuestionRequest, rsp *pb.QuestionResponse) error { if len(req.Query) == 0 { - return errors.BadRequest("ask.question", "need a question") + return errors.BadRequest("answer.question", "need a question") } msg, err := goduckgo.Query(req.Query) if err != nil { - return errors.InternalServerError("ask.question", err.Error()) + return errors.InternalServerError("answer.question", err.Error()) } if len(msg.Abstract) > 0 { diff --git a/ask/main.go b/answer/main.go similarity index 62% rename from ask/main.go rename to answer/main.go index c2aa91e..772b6ef 100644 --- a/ask/main.go +++ b/answer/main.go @@ -3,19 +3,19 @@ package main import ( "github.com/micro/micro/v3/service" "github.com/micro/micro/v3/service/logger" - "github.com/micro/services/ask/handler" - pb "github.com/micro/services/ask/proto" + "github.com/micro/services/answer/handler" + pb "github.com/micro/services/answer/proto" ) func main() { // Create service srv := service.New( - service.Name("ask"), + service.Name("answer"), service.Version("latest"), ) // Register handler - pb.RegisterAskHandler(srv.Server(), new(handler.Ask)) + pb.RegisterAnswerHandler(srv.Server(), new(handler.Answer)) // Run service if err := srv.Run(); err != nil { diff --git a/answer/micro.mu b/answer/micro.mu new file mode 100644 index 0000000..32de970 --- /dev/null +++ b/answer/micro.mu @@ -0,0 +1 @@ +service answer diff --git a/ask/proto/ask.pb.go b/answer/proto/answer.pb.go similarity index 52% rename from ask/proto/ask.pb.go rename to answer/proto/answer.pb.go index 1792b4e..ac0c49e 100644 --- a/ask/proto/ask.pb.go +++ b/answer/proto/answer.pb.go @@ -2,9 +2,9 @@ // versions: // protoc-gen-go v1.26.0 // protoc v3.15.6 -// source: proto/ask.proto +// source: proto/answer.proto -package ask +package answer import ( protoreflect "google.golang.org/protobuf/reflect/protoreflect" @@ -20,20 +20,20 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// Ask a question and receive an instant answer +// Answer a question and receive an instant answer type QuestionRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // the question to ask + // the question to answer Query string `protobuf:"bytes,1,opt,name=query,proto3" json:"query,omitempty"` } func (x *QuestionRequest) Reset() { *x = QuestionRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_ask_proto_msgTypes[0] + mi := &file_proto_answer_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -46,7 +46,7 @@ func (x *QuestionRequest) String() string { func (*QuestionRequest) ProtoMessage() {} func (x *QuestionRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_ask_proto_msgTypes[0] + mi := &file_proto_answer_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -59,7 +59,7 @@ func (x *QuestionRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use QuestionRequest.ProtoReflect.Descriptor instead. func (*QuestionRequest) Descriptor() ([]byte, []int) { - return file_proto_ask_proto_rawDescGZIP(), []int{0} + return file_proto_answer_proto_rawDescGZIP(), []int{0} } func (x *QuestionRequest) GetQuery() string { @@ -85,7 +85,7 @@ type QuestionResponse struct { func (x *QuestionResponse) Reset() { *x = QuestionResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_ask_proto_msgTypes[1] + mi := &file_proto_answer_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -98,7 +98,7 @@ func (x *QuestionResponse) String() string { func (*QuestionResponse) ProtoMessage() {} func (x *QuestionResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_ask_proto_msgTypes[1] + mi := &file_proto_answer_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -111,7 +111,7 @@ func (x *QuestionResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use QuestionResponse.ProtoReflect.Descriptor instead. func (*QuestionResponse) Descriptor() ([]byte, []int) { - return file_proto_ask_proto_rawDescGZIP(), []int{1} + return file_proto_answer_proto_rawDescGZIP(), []int{1} } func (x *QuestionResponse) GetAnswer() string { @@ -135,46 +135,47 @@ func (x *QuestionResponse) GetImage() string { return "" } -var File_proto_ask_proto protoreflect.FileDescriptor +var File_proto_answer_proto protoreflect.FileDescriptor -var file_proto_ask_proto_rawDesc = []byte{ - 0x0a, 0x0f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x61, 0x73, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x12, 0x03, 0x61, 0x73, 0x6b, 0x22, 0x27, 0x0a, 0x0f, 0x51, 0x75, 0x65, 0x73, 0x74, 0x69, - 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x71, 0x75, 0x65, - 0x72, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x22, - 0x52, 0x0a, 0x10, 0x51, 0x75, 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6e, 0x73, 0x77, 0x65, 0x72, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x6e, 0x73, 0x77, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x75, - 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x12, 0x14, 0x0a, - 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x6d, - 0x61, 0x67, 0x65, 0x32, 0x40, 0x0a, 0x03, 0x41, 0x73, 0x6b, 0x12, 0x39, 0x0a, 0x08, 0x51, 0x75, - 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x14, 0x2e, 0x61, 0x73, 0x6b, 0x2e, 0x51, 0x75, 0x65, - 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x61, - 0x73, 0x6b, 0x2e, 0x51, 0x75, 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0d, 0x5a, 0x0b, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x3b, 0x61, 0x73, 0x6b, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +var file_proto_answer_proto_rawDesc = []byte{ + 0x0a, 0x12, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x61, 0x6e, 0x73, 0x77, 0x65, 0x72, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x61, 0x6e, 0x73, 0x77, 0x65, 0x72, 0x22, 0x27, 0x0a, 0x0f, + 0x51, 0x75, 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x14, 0x0a, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, + 0x71, 0x75, 0x65, 0x72, 0x79, 0x22, 0x52, 0x0a, 0x10, 0x51, 0x75, 0x65, 0x73, 0x74, 0x69, 0x6f, + 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6e, 0x73, + 0x77, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x6e, 0x73, 0x77, 0x65, + 0x72, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x75, 0x72, 0x6c, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x32, 0x49, 0x0a, 0x06, 0x41, 0x6e, 0x73, + 0x77, 0x65, 0x72, 0x12, 0x3f, 0x0a, 0x08, 0x51, 0x75, 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x12, + 0x17, 0x2e, 0x61, 0x6e, 0x73, 0x77, 0x65, 0x72, 0x2e, 0x51, 0x75, 0x65, 0x73, 0x74, 0x69, 0x6f, + 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x61, 0x6e, 0x73, 0x77, 0x65, + 0x72, 0x2e, 0x51, 0x75, 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x00, 0x42, 0x10, 0x5a, 0x0e, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, + 0x61, 0x6e, 0x73, 0x77, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - file_proto_ask_proto_rawDescOnce sync.Once - file_proto_ask_proto_rawDescData = file_proto_ask_proto_rawDesc + file_proto_answer_proto_rawDescOnce sync.Once + file_proto_answer_proto_rawDescData = file_proto_answer_proto_rawDesc ) -func file_proto_ask_proto_rawDescGZIP() []byte { - file_proto_ask_proto_rawDescOnce.Do(func() { - file_proto_ask_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_ask_proto_rawDescData) +func file_proto_answer_proto_rawDescGZIP() []byte { + file_proto_answer_proto_rawDescOnce.Do(func() { + file_proto_answer_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_answer_proto_rawDescData) }) - return file_proto_ask_proto_rawDescData + return file_proto_answer_proto_rawDescData } -var file_proto_ask_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_proto_ask_proto_goTypes = []interface{}{ - (*QuestionRequest)(nil), // 0: ask.QuestionRequest - (*QuestionResponse)(nil), // 1: ask.QuestionResponse +var file_proto_answer_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_proto_answer_proto_goTypes = []interface{}{ + (*QuestionRequest)(nil), // 0: answer.QuestionRequest + (*QuestionResponse)(nil), // 1: answer.QuestionResponse } -var file_proto_ask_proto_depIdxs = []int32{ - 0, // 0: ask.Ask.Question:input_type -> ask.QuestionRequest - 1, // 1: ask.Ask.Question:output_type -> ask.QuestionResponse +var file_proto_answer_proto_depIdxs = []int32{ + 0, // 0: answer.Answer.Question:input_type -> answer.QuestionRequest + 1, // 1: answer.Answer.Question:output_type -> answer.QuestionResponse 1, // [1:2] is the sub-list for method output_type 0, // [0:1] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name @@ -182,13 +183,13 @@ var file_proto_ask_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for field type_name } -func init() { file_proto_ask_proto_init() } -func file_proto_ask_proto_init() { - if File_proto_ask_proto != nil { +func init() { file_proto_answer_proto_init() } +func file_proto_answer_proto_init() { + if File_proto_answer_proto != nil { return } if !protoimpl.UnsafeEnabled { - file_proto_ask_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_proto_answer_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*QuestionRequest); i { case 0: return &v.state @@ -200,7 +201,7 @@ func file_proto_ask_proto_init() { return nil } } - file_proto_ask_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_proto_answer_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*QuestionResponse); i { case 0: return &v.state @@ -217,18 +218,18 @@ func file_proto_ask_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_proto_ask_proto_rawDesc, + RawDescriptor: file_proto_answer_proto_rawDesc, NumEnums: 0, NumMessages: 2, NumExtensions: 0, NumServices: 1, }, - GoTypes: file_proto_ask_proto_goTypes, - DependencyIndexes: file_proto_ask_proto_depIdxs, - MessageInfos: file_proto_ask_proto_msgTypes, + GoTypes: file_proto_answer_proto_goTypes, + DependencyIndexes: file_proto_answer_proto_depIdxs, + MessageInfos: file_proto_answer_proto_msgTypes, }.Build() - File_proto_ask_proto = out.File - file_proto_ask_proto_rawDesc = nil - file_proto_ask_proto_goTypes = nil - file_proto_ask_proto_depIdxs = nil + File_proto_answer_proto = out.File + file_proto_answer_proto_rawDesc = nil + file_proto_answer_proto_goTypes = nil + file_proto_answer_proto_depIdxs = nil } diff --git a/ask/proto/ask.pb.micro.go b/answer/proto/answer.pb.micro.go similarity index 58% rename from ask/proto/ask.pb.micro.go rename to answer/proto/answer.pb.micro.go index acbf711..ca846fd 100644 --- a/ask/proto/ask.pb.micro.go +++ b/answer/proto/answer.pb.micro.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: proto/ask.proto +// source: proto/answer.proto -package ask +package answer import ( fmt "fmt" @@ -33,32 +33,32 @@ var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Ask service +// Api Endpoints for Answer service -func NewAskEndpoints() []*api.Endpoint { +func NewAnswerEndpoints() []*api.Endpoint { return []*api.Endpoint{} } -// Client API for Ask service +// Client API for Answer service -type AskService interface { +type AnswerService interface { Question(ctx context.Context, in *QuestionRequest, opts ...client.CallOption) (*QuestionResponse, error) } -type askService struct { +type answerService struct { c client.Client name string } -func NewAskService(name string, c client.Client) AskService { - return &askService{ +func NewAnswerService(name string, c client.Client) AnswerService { + return &answerService{ c: c, name: name, } } -func (c *askService) Question(ctx context.Context, in *QuestionRequest, opts ...client.CallOption) (*QuestionResponse, error) { - req := c.c.NewRequest(c.name, "Ask.Question", in) +func (c *answerService) Question(ctx context.Context, in *QuestionRequest, opts ...client.CallOption) (*QuestionResponse, error) { + req := c.c.NewRequest(c.name, "Answer.Question", in) out := new(QuestionResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -67,27 +67,27 @@ func (c *askService) Question(ctx context.Context, in *QuestionRequest, opts ... return out, nil } -// Server API for Ask service +// Server API for Answer service -type AskHandler interface { +type AnswerHandler interface { Question(context.Context, *QuestionRequest, *QuestionResponse) error } -func RegisterAskHandler(s server.Server, hdlr AskHandler, opts ...server.HandlerOption) error { - type ask interface { +func RegisterAnswerHandler(s server.Server, hdlr AnswerHandler, opts ...server.HandlerOption) error { + type answer interface { Question(ctx context.Context, in *QuestionRequest, out *QuestionResponse) error } - type Ask struct { - ask + type Answer struct { + answer } - h := &askHandler{hdlr} - return s.Handle(s.NewHandler(&Ask{h}, opts...)) + h := &answerHandler{hdlr} + return s.Handle(s.NewHandler(&Answer{h}, opts...)) } -type askHandler struct { - AskHandler +type answerHandler struct { + AnswerHandler } -func (h *askHandler) Question(ctx context.Context, in *QuestionRequest, out *QuestionResponse) error { - return h.AskHandler.Question(ctx, in, out) +func (h *answerHandler) Question(ctx context.Context, in *QuestionRequest, out *QuestionResponse) error { + return h.AnswerHandler.Question(ctx, in, out) } diff --git a/ask/proto/ask.proto b/answer/proto/answer.proto similarity index 66% rename from ask/proto/ask.proto rename to answer/proto/answer.proto index aa5e507..e0418e3 100644 --- a/ask/proto/ask.proto +++ b/answer/proto/answer.proto @@ -1,16 +1,16 @@ syntax = "proto3"; -package ask; +package answer; -option go_package = "./proto;ask"; +option go_package = "./proto;answer"; -service Ask { +service Answer { rpc Question(QuestionRequest) returns (QuestionResponse) {} } -// Ask a question and receive an instant answer +// Answer a question and receive an instant answer message QuestionRequest { - // the question to ask + // the question to answer string query = 1; } diff --git a/ask/publicapi.json b/answer/publicapi.json similarity index 68% rename from ask/publicapi.json rename to answer/publicapi.json index 587c111..3c0d22c 100644 --- a/ask/publicapi.json +++ b/answer/publicapi.json @@ -1,5 +1,5 @@ { - "name": "ask", + "name": "answer", "icon": "❓", "category": "search" } diff --git a/ask/Dockerfile b/ask/Dockerfile deleted file mode 100644 index 1a201a9..0000000 --- a/ask/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM alpine -ADD ask /ask -ENTRYPOINT [ "/ask" ] diff --git a/ask/micro.mu b/ask/micro.mu deleted file mode 100644 index 1ad94e9..0000000 --- a/ask/micro.mu +++ /dev/null @@ -1 +0,0 @@ -service ask