mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-22 07:15:25 +00:00
feat: add joke api (#294)
* feat: add joke api close #124 * chore: count boundary * fix: bug fix chore: update README.md * feat: add publicapi.json
This commit is contained in:
314
joke/proto/joke.pb.go
Normal file
314
joke/proto/joke.pb.go
Normal file
@@ -0,0 +1,314 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.27.1
|
||||
// protoc v3.19.1
|
||||
// source: proto/joke.proto
|
||||
|
||||
package joke
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type RandomRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// the count of random jokes want, maximum: 10
|
||||
Count int32 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"`
|
||||
}
|
||||
|
||||
func (x *RandomRequest) Reset() {
|
||||
*x = RandomRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_joke_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *RandomRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*RandomRequest) ProtoMessage() {}
|
||||
|
||||
func (x *RandomRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_joke_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use RandomRequest.ProtoReflect.Descriptor instead.
|
||||
func (*RandomRequest) Descriptor() ([]byte, []int) {
|
||||
return file_proto_joke_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *RandomRequest) GetCount() int32 {
|
||||
if x != nil {
|
||||
return x.Count
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type JokeInfo struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"`
|
||||
Body string `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"`
|
||||
Category string `protobuf:"bytes,4,opt,name=category,proto3" json:"category,omitempty"`
|
||||
// the source of joke
|
||||
Source string `protobuf:"bytes,5,opt,name=source,proto3" json:"source,omitempty"`
|
||||
}
|
||||
|
||||
func (x *JokeInfo) Reset() {
|
||||
*x = JokeInfo{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_joke_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *JokeInfo) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*JokeInfo) ProtoMessage() {}
|
||||
|
||||
func (x *JokeInfo) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_joke_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use JokeInfo.ProtoReflect.Descriptor instead.
|
||||
func (*JokeInfo) Descriptor() ([]byte, []int) {
|
||||
return file_proto_joke_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *JokeInfo) GetId() string {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *JokeInfo) GetTitle() string {
|
||||
if x != nil {
|
||||
return x.Title
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *JokeInfo) GetBody() string {
|
||||
if x != nil {
|
||||
return x.Body
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *JokeInfo) GetCategory() string {
|
||||
if x != nil {
|
||||
return x.Category
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *JokeInfo) GetSource() string {
|
||||
if x != nil {
|
||||
return x.Source
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type RandomResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Jokes []*JokeInfo `protobuf:"bytes,1,rep,name=jokes,proto3" json:"jokes,omitempty"`
|
||||
}
|
||||
|
||||
func (x *RandomResponse) Reset() {
|
||||
*x = RandomResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_proto_joke_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *RandomResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*RandomResponse) ProtoMessage() {}
|
||||
|
||||
func (x *RandomResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_joke_proto_msgTypes[2]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use RandomResponse.ProtoReflect.Descriptor instead.
|
||||
func (*RandomResponse) Descriptor() ([]byte, []int) {
|
||||
return file_proto_joke_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *RandomResponse) GetJokes() []*JokeInfo {
|
||||
if x != nil {
|
||||
return x.Jokes
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_proto_joke_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_proto_joke_proto_rawDesc = []byte{
|
||||
0x0a, 0x10, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6a, 0x6f, 0x6b, 0x65, 0x2e, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x12, 0x04, 0x6a, 0x6f, 0x6b, 0x65, 0x22, 0x25, 0x0a, 0x0d, 0x52, 0x61, 0x6e, 0x64,
|
||||
0x6f, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75,
|
||||
0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22,
|
||||
0x78, 0x0a, 0x08, 0x4a, 0x6f, 0x6b, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x0e, 0x0a, 0x02, 0x69,
|
||||
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x74,
|
||||
0x69, 0x74, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c,
|
||||
0x65, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72,
|
||||
0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72,
|
||||
0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22, 0x36, 0x0a, 0x0e, 0x52, 0x61, 0x6e,
|
||||
0x64, 0x6f, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x24, 0x0a, 0x05, 0x6a,
|
||||
0x6f, 0x6b, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x6a, 0x6f, 0x6b,
|
||||
0x65, 0x2e, 0x4a, 0x6f, 0x6b, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x6a, 0x6f, 0x6b, 0x65,
|
||||
0x73, 0x32, 0x3d, 0x0a, 0x04, 0x4a, 0x6f, 0x6b, 0x65, 0x12, 0x35, 0x0a, 0x06, 0x52, 0x61, 0x6e,
|
||||
0x64, 0x6f, 0x6d, 0x12, 0x13, 0x2e, 0x6a, 0x6f, 0x6b, 0x65, 0x2e, 0x52, 0x61, 0x6e, 0x64, 0x6f,
|
||||
0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x6a, 0x6f, 0x6b, 0x65, 0x2e,
|
||||
0x52, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00,
|
||||
0x42, 0x0e, 0x5a, 0x0c, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x6a, 0x6f, 0x6b, 0x65,
|
||||
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_proto_joke_proto_rawDescOnce sync.Once
|
||||
file_proto_joke_proto_rawDescData = file_proto_joke_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_proto_joke_proto_rawDescGZIP() []byte {
|
||||
file_proto_joke_proto_rawDescOnce.Do(func() {
|
||||
file_proto_joke_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_joke_proto_rawDescData)
|
||||
})
|
||||
return file_proto_joke_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_proto_joke_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
|
||||
var file_proto_joke_proto_goTypes = []interface{}{
|
||||
(*RandomRequest)(nil), // 0: joke.RandomRequest
|
||||
(*JokeInfo)(nil), // 1: joke.JokeInfo
|
||||
(*RandomResponse)(nil), // 2: joke.RandomResponse
|
||||
}
|
||||
var file_proto_joke_proto_depIdxs = []int32{
|
||||
1, // 0: joke.RandomResponse.jokes:type_name -> joke.JokeInfo
|
||||
0, // 1: joke.Joke.Random:input_type -> joke.RandomRequest
|
||||
2, // 2: joke.Joke.Random:output_type -> joke.RandomResponse
|
||||
2, // [2:3] is the sub-list for method output_type
|
||||
1, // [1:2] is the sub-list for method input_type
|
||||
1, // [1:1] is the sub-list for extension type_name
|
||||
1, // [1:1] is the sub-list for extension extendee
|
||||
0, // [0:1] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_proto_joke_proto_init() }
|
||||
func file_proto_joke_proto_init() {
|
||||
if File_proto_joke_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_proto_joke_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*RandomRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_proto_joke_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*JokeInfo); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_proto_joke_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*RandomResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_proto_joke_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 3,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_proto_joke_proto_goTypes,
|
||||
DependencyIndexes: file_proto_joke_proto_depIdxs,
|
||||
MessageInfos: file_proto_joke_proto_msgTypes,
|
||||
}.Build()
|
||||
File_proto_joke_proto = out.File
|
||||
file_proto_joke_proto_rawDesc = nil
|
||||
file_proto_joke_proto_goTypes = nil
|
||||
file_proto_joke_proto_depIdxs = nil
|
||||
}
|
||||
95
joke/proto/joke.pb.micro.go
Normal file
95
joke/proto/joke.pb.micro.go
Normal file
@@ -0,0 +1,95 @@
|
||||
// Code generated by protoc-gen-micro. DO NOT EDIT.
|
||||
// source: proto/joke.proto
|
||||
|
||||
package joke
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
math "math"
|
||||
)
|
||||
|
||||
import (
|
||||
context "context"
|
||||
api "github.com/micro/micro/v3/service/api"
|
||||
client "github.com/micro/micro/v3/service/client"
|
||||
server "github.com/micro/micro/v3/service/server"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ api.Endpoint
|
||||
var _ context.Context
|
||||
var _ client.Option
|
||||
var _ server.Option
|
||||
|
||||
// Api Endpoints for Joke service
|
||||
|
||||
func NewJokeEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{}
|
||||
}
|
||||
|
||||
// Client API for Joke service
|
||||
|
||||
type JokeService interface {
|
||||
// get n random jokes
|
||||
Random(ctx context.Context, in *RandomRequest, opts ...client.CallOption) (*RandomResponse, error)
|
||||
}
|
||||
|
||||
type jokeService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewJokeService(name string, c client.Client) JokeService {
|
||||
return &jokeService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *jokeService) Random(ctx context.Context, in *RandomRequest, opts ...client.CallOption) (*RandomResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Joke.Random", in)
|
||||
out := new(RandomResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for Joke service
|
||||
|
||||
type JokeHandler interface {
|
||||
// get n random jokes
|
||||
Random(context.Context, *RandomRequest, *RandomResponse) error
|
||||
}
|
||||
|
||||
func RegisterJokeHandler(s server.Server, hdlr JokeHandler, opts ...server.HandlerOption) error {
|
||||
type joke interface {
|
||||
Random(ctx context.Context, in *RandomRequest, out *RandomResponse) error
|
||||
}
|
||||
type Joke struct {
|
||||
joke
|
||||
}
|
||||
h := &jokeHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&Joke{h}, opts...))
|
||||
}
|
||||
|
||||
type jokeHandler struct {
|
||||
JokeHandler
|
||||
}
|
||||
|
||||
func (h *jokeHandler) Random(ctx context.Context, in *RandomRequest, out *RandomResponse) error {
|
||||
return h.JokeHandler.Random(ctx, in, out)
|
||||
}
|
||||
28
joke/proto/joke.proto
Normal file
28
joke/proto/joke.proto
Normal file
@@ -0,0 +1,28 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package joke;
|
||||
|
||||
option go_package = "./proto;joke";
|
||||
|
||||
service Joke {
|
||||
// get n random jokes
|
||||
rpc Random(RandomRequest) returns (RandomResponse) {}
|
||||
}
|
||||
|
||||
message RandomRequest {
|
||||
// the count of random jokes want, maximum: 10
|
||||
int32 count = 1;
|
||||
}
|
||||
|
||||
message JokeInfo {
|
||||
string id = 1;
|
||||
string title = 2;
|
||||
string body = 3;
|
||||
string category = 4;
|
||||
// the source of joke
|
||||
string source = 5;
|
||||
}
|
||||
|
||||
message RandomResponse {
|
||||
repeated JokeInfo jokes = 1;
|
||||
}
|
||||
Reference in New Issue
Block a user