From b2b566f9dd591d4d7f7017c4a51e3ed20b1bb959 Mon Sep 17 00:00:00 2001 From: Eigeen Date: Tue, 20 Dec 2022 21:35:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E7=89=88core=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E7=94=A8http=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 15 + .idea/.gitignore | 8 + .idea/modules.xml | 8 + .idea/spider-core.iml | 9 + biliapi/base.go | 48 +++ biliapi/error.go | 17 + biliapi/info.go | 20 ++ biliapi/stat.go | 29 ++ go.mod | 17 + go.sum | 23 ++ main.go | 28 ++ rpc/pb/api.pb.go | 754 ++++++++++++++++++++++++++++++++++++++++++ rpc/pb/api_grpc.pb.go | 141 ++++++++ rpc/service.go | 115 +++++++ 14 files changed, 1232 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/modules.xml create mode 100644 .idea/spider-core.iml create mode 100644 biliapi/base.go create mode 100644 biliapi/error.go create mode 100644 biliapi/info.go create mode 100644 biliapi/stat.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 rpc/pb/api.pb.go create mode 100644 rpc/pb/api_grpc.pb.go create mode 100644 rpc/service.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..66fd13c --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..dfb4cd2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/spider-core.iml b/.idea/spider-core.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/spider-core.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/biliapi/base.go b/biliapi/base.go new file mode 100644 index 0000000..5911db0 --- /dev/null +++ b/biliapi/base.go @@ -0,0 +1,48 @@ +package biliapi + +import ( + "io" + "net/http" + "time" +) + +type Root struct { + Code int `json:"code"` + Message string `json:"message"` + TTL int `json:"ttl"` + Data interface{} `json:"data"` +} + +type BaseService struct { + client *http.Client + url string +} + +func (srv *BaseService) DoRequest() ([]byte, error) { + req, err := http.NewRequest("GET", srv.url, nil) + if err != nil { + return nil, err + } + req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.46") + + if srv.client == nil { + srv.client = &http.Client{ + Timeout: time.Duration(5) * time.Second, + } + } + resp, err := srv.client.Do(req) + defer resp.Body.Close() + if err != nil { + return nil, err + } + + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, err + } + //if resp.StatusCode != 200 { + // return body, NewAPIError(fmt.Sprintf("非正常返回值:StatusCode %d", resp.StatusCode)) + //} + + return body, nil +} diff --git a/biliapi/error.go b/biliapi/error.go new file mode 100644 index 0000000..75079ff --- /dev/null +++ b/biliapi/error.go @@ -0,0 +1,17 @@ +package biliapi + +type APIError struct { + Msg string +} + +func (err APIError) Error() string { + return err.Msg +} + +func NewAPIError(msg string) APIError { + return APIError{Msg: msg} +} + +func MissingParamError() APIError { + return APIError{Msg: "缺少参数"} +} diff --git a/biliapi/info.go b/biliapi/info.go new file mode 100644 index 0000000..38133f9 --- /dev/null +++ b/biliapi/info.go @@ -0,0 +1,20 @@ +package biliapi + +import ( + "fmt" + "net/http" +) + +func BasicInfo(mid uint) ([]byte, error) { + url := fmt.Sprintf("https://api.bilibili.com/x/space/wbi/acc/info?mid=%d", mid) + + srv := BaseService{ + client: &http.Client{}, + url: url, + } + respBody, err := srv.DoRequest() + if err != nil { + return nil, err + } + return respBody, nil +} diff --git a/biliapi/stat.go b/biliapi/stat.go new file mode 100644 index 0000000..789ce5c --- /dev/null +++ b/biliapi/stat.go @@ -0,0 +1,29 @@ +package biliapi + +import ( + "fmt" + "net/http" +) + +type StatData struct { + Mid uint64 `json:"mid"` + Following uint32 `json:"following"` + Whisper uint32 `json:"whisper"` + Black uint32 `json:"black"` + Follower uint32 `json:"follower"` +} + +// UserStat 用户统计信息 例如粉丝数,订阅数等 +func UserStat(mid uint) ([]byte, error) { + url := fmt.Sprintf("https://api.bilibili.com/x/relation/stat?vmid=%d", mid) + + srv := BaseService{ + client: &http.Client{}, + url: url, + } + respBody, err := srv.DoRequest() + if err != nil { + return nil, err + } + return respBody, nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d8dc6c9 --- /dev/null +++ b/go.mod @@ -0,0 +1,17 @@ +module github.com/furryboard/spider-core + +go 1.19 + +require ( + google.golang.org/grpc v1.50.1 + google.golang.org/protobuf v1.28.1 +) + +require ( + github.com/golang/protobuf v1.5.2 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + golang.org/x/net v0.1.0 // indirect + golang.org/x/sys v0.1.0 // indirect + golang.org/x/text v0.4.0 // indirect + google.golang.org/genproto v0.0.0-20221025140454-527a21cfbd71 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..caaeb8d --- /dev/null +++ b/go.sum @@ -0,0 +1,23 @@ +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0= +golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= +golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +google.golang.org/genproto v0.0.0-20221025140454-527a21cfbd71 h1:GEgb2jF5zxsFJpJfg9RoDDWm7tiwc/DDSTE2BtLUkXU= +google.golang.org/genproto v0.0.0-20221025140454-527a21cfbd71/go.mod h1:9qHF0xnpdSfF6knlcsnpzUu5y+rpwgbvsyGAZPBMg4s= +google.golang.org/grpc v1.50.1 h1:DS/BukOZWp8s6p4Dt/tOaJaTQyPyOoCcrjroHuCeLzY= +google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/main.go b/main.go new file mode 100644 index 0000000..c7e6eb8 --- /dev/null +++ b/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/furryboard/spider-core/rpc" + "google.golang.org/grpc" + "net" +) + +func main() { + // 监听本地端口 + lis, err := net.Listen("tcp", ":9101") + if err != nil { + fmt.Printf("监听端口失败: %s", err) + return + } + + // 创建gRPC服务器 + s := grpc.NewServer() + // 注册服务 + rpc.RegisterServices(s) + + err = s.Serve(lis) + if err != nil { + fmt.Printf("开启服务失败: %s", err) + return + } +} diff --git a/rpc/pb/api.pb.go b/rpc/pb/api.pb.go new file mode 100644 index 0000000..acd391f --- /dev/null +++ b/rpc/pb/api.pb.go @@ -0,0 +1,754 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v3.21.8 +// source: api.proto + +package pb + +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 StatRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Uid uint64 `protobuf:"varint,1,opt,name=uid,proto3" json:"uid,omitempty"` +} + +func (x *StatRequest) Reset() { + *x = StatRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_api_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StatRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatRequest) ProtoMessage() {} + +func (x *StatRequest) ProtoReflect() protoreflect.Message { + mi := &file_api_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 StatRequest.ProtoReflect.Descriptor instead. +func (*StatRequest) Descriptor() ([]byte, []int) { + return file_api_proto_rawDescGZIP(), []int{0} +} + +func (x *StatRequest) GetUid() uint64 { + if x != nil { + return x.Uid + } + return 0 +} + +type StatReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` + Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` + Data *StatReply_Data `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` +} + +func (x *StatReply) Reset() { + *x = StatReply{} + if protoimpl.UnsafeEnabled { + mi := &file_api_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StatReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatReply) ProtoMessage() {} + +func (x *StatReply) ProtoReflect() protoreflect.Message { + mi := &file_api_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 StatReply.ProtoReflect.Descriptor instead. +func (*StatReply) Descriptor() ([]byte, []int) { + return file_api_proto_rawDescGZIP(), []int{1} +} + +func (x *StatReply) GetCode() int32 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *StatReply) GetMsg() string { + if x != nil { + return x.Msg + } + return "" +} + +func (x *StatReply) GetData() *StatReply_Data { + if x != nil { + return x.Data + } + return nil +} + +type InfoRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Uid uint64 `protobuf:"varint,1,opt,name=uid,proto3" json:"uid,omitempty"` +} + +func (x *InfoRequest) Reset() { + *x = InfoRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_api_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *InfoRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InfoRequest) ProtoMessage() {} + +func (x *InfoRequest) ProtoReflect() protoreflect.Message { + mi := &file_api_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 InfoRequest.ProtoReflect.Descriptor instead. +func (*InfoRequest) Descriptor() ([]byte, []int) { + return file_api_proto_rawDescGZIP(), []int{2} +} + +func (x *InfoRequest) GetUid() uint64 { + if x != nil { + return x.Uid + } + return 0 +} + +type InfoReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` + Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` + Data *InfoReply_Data `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` +} + +func (x *InfoReply) Reset() { + *x = InfoReply{} + if protoimpl.UnsafeEnabled { + mi := &file_api_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *InfoReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InfoReply) ProtoMessage() {} + +func (x *InfoReply) ProtoReflect() protoreflect.Message { + mi := &file_api_proto_msgTypes[3] + 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 InfoReply.ProtoReflect.Descriptor instead. +func (*InfoReply) Descriptor() ([]byte, []int) { + return file_api_proto_rawDescGZIP(), []int{3} +} + +func (x *InfoReply) GetCode() int32 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *InfoReply) GetMsg() string { + if x != nil { + return x.Msg + } + return "" +} + +func (x *InfoReply) GetData() *InfoReply_Data { + if x != nil { + return x.Data + } + return nil +} + +type StatReply_Data struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Mid uint64 `protobuf:"varint,1,opt,name=mid,proto3" json:"mid,omitempty"` + Following uint32 `protobuf:"varint,2,opt,name=following,proto3" json:"following,omitempty"` + Whisper uint32 `protobuf:"varint,3,opt,name=whisper,proto3" json:"whisper,omitempty"` + Black uint32 `protobuf:"varint,4,opt,name=black,proto3" json:"black,omitempty"` + Follower uint32 `protobuf:"varint,5,opt,name=follower,proto3" json:"follower,omitempty"` +} + +func (x *StatReply_Data) Reset() { + *x = StatReply_Data{} + if protoimpl.UnsafeEnabled { + mi := &file_api_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StatReply_Data) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatReply_Data) ProtoMessage() {} + +func (x *StatReply_Data) ProtoReflect() protoreflect.Message { + mi := &file_api_proto_msgTypes[4] + 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 StatReply_Data.ProtoReflect.Descriptor instead. +func (*StatReply_Data) Descriptor() ([]byte, []int) { + return file_api_proto_rawDescGZIP(), []int{1, 0} +} + +func (x *StatReply_Data) GetMid() uint64 { + if x != nil { + return x.Mid + } + return 0 +} + +func (x *StatReply_Data) GetFollowing() uint32 { + if x != nil { + return x.Following + } + return 0 +} + +func (x *StatReply_Data) GetWhisper() uint32 { + if x != nil { + return x.Whisper + } + return 0 +} + +func (x *StatReply_Data) GetBlack() uint32 { + if x != nil { + return x.Black + } + return 0 +} + +func (x *StatReply_Data) GetFollower() uint32 { + if x != nil { + return x.Follower + } + return 0 +} + +type InfoReply_Data struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Mid uint64 `protobuf:"varint,1,opt,name=mid,proto3" json:"mid,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Sex string `protobuf:"bytes,3,opt,name=sex,proto3" json:"sex,omitempty"` + Face string `protobuf:"bytes,4,opt,name=face,proto3" json:"face,omitempty"` + FaceNft uint32 `protobuf:"varint,5,opt,name=face_nft,json=faceNft,proto3" json:"face_nft,omitempty"` + FaceNftType uint32 `protobuf:"varint,6,opt,name=face_nft_type,json=faceNftType,proto3" json:"face_nft_type,omitempty"` + Sign string `protobuf:"bytes,7,opt,name=sign,proto3" json:"sign,omitempty"` + Rank uint32 `protobuf:"varint,8,opt,name=rank,proto3" json:"rank,omitempty"` + Level uint32 `protobuf:"varint,9,opt,name=level,proto3" json:"level,omitempty"` + Jointime uint32 `protobuf:"varint,10,opt,name=jointime,proto3" json:"jointime,omitempty"` + Moral uint32 `protobuf:"varint,11,opt,name=moral,proto3" json:"moral,omitempty"` + Silence uint32 `protobuf:"varint,12,opt,name=silence,proto3" json:"silence,omitempty"` + Coins uint32 `protobuf:"varint,13,opt,name=coins,proto3" json:"coins,omitempty"` + FansBadge bool `protobuf:"varint,14,opt,name=fans_badge,json=fansBadge,proto3" json:"fans_badge,omitempty"` + IsFollowed bool `protobuf:"varint,21,opt,name=is_followed,json=isFollowed,proto3" json:"is_followed,omitempty"` + TopPhoto string `protobuf:"bytes,22,opt,name=top_photo,json=topPhoto,proto3" json:"top_photo,omitempty"` + Birthday string `protobuf:"bytes,26,opt,name=birthday,proto3" json:"birthday,omitempty"` + Tags []string `protobuf:"bytes,29,rep,name=tags,proto3" json:"tags,omitempty"` + IsSeniorMember uint32 `protobuf:"varint,31,opt,name=is_senior_member,json=isSeniorMember,proto3" json:"is_senior_member,omitempty"` + McnInfo string `protobuf:"bytes,32,opt,name=mcn_info,json=mcnInfo,proto3" json:"mcn_info,omitempty"` + GaiaResType uint32 `protobuf:"varint,33,opt,name=gaia_res_type,json=gaiaResType,proto3" json:"gaia_res_type,omitempty"` + GaiaData string `protobuf:"bytes,34,opt,name=gaia_data,json=gaiaData,proto3" json:"gaia_data,omitempty"` + IsRisk bool `protobuf:"varint,35,opt,name=is_risk,json=isRisk,proto3" json:"is_risk,omitempty"` +} + +func (x *InfoReply_Data) Reset() { + *x = InfoReply_Data{} + if protoimpl.UnsafeEnabled { + mi := &file_api_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *InfoReply_Data) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InfoReply_Data) ProtoMessage() {} + +func (x *InfoReply_Data) ProtoReflect() protoreflect.Message { + mi := &file_api_proto_msgTypes[5] + 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 InfoReply_Data.ProtoReflect.Descriptor instead. +func (*InfoReply_Data) Descriptor() ([]byte, []int) { + return file_api_proto_rawDescGZIP(), []int{3, 0} +} + +func (x *InfoReply_Data) GetMid() uint64 { + if x != nil { + return x.Mid + } + return 0 +} + +func (x *InfoReply_Data) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *InfoReply_Data) GetSex() string { + if x != nil { + return x.Sex + } + return "" +} + +func (x *InfoReply_Data) GetFace() string { + if x != nil { + return x.Face + } + return "" +} + +func (x *InfoReply_Data) GetFaceNft() uint32 { + if x != nil { + return x.FaceNft + } + return 0 +} + +func (x *InfoReply_Data) GetFaceNftType() uint32 { + if x != nil { + return x.FaceNftType + } + return 0 +} + +func (x *InfoReply_Data) GetSign() string { + if x != nil { + return x.Sign + } + return "" +} + +func (x *InfoReply_Data) GetRank() uint32 { + if x != nil { + return x.Rank + } + return 0 +} + +func (x *InfoReply_Data) GetLevel() uint32 { + if x != nil { + return x.Level + } + return 0 +} + +func (x *InfoReply_Data) GetJointime() uint32 { + if x != nil { + return x.Jointime + } + return 0 +} + +func (x *InfoReply_Data) GetMoral() uint32 { + if x != nil { + return x.Moral + } + return 0 +} + +func (x *InfoReply_Data) GetSilence() uint32 { + if x != nil { + return x.Silence + } + return 0 +} + +func (x *InfoReply_Data) GetCoins() uint32 { + if x != nil { + return x.Coins + } + return 0 +} + +func (x *InfoReply_Data) GetFansBadge() bool { + if x != nil { + return x.FansBadge + } + return false +} + +func (x *InfoReply_Data) GetIsFollowed() bool { + if x != nil { + return x.IsFollowed + } + return false +} + +func (x *InfoReply_Data) GetTopPhoto() string { + if x != nil { + return x.TopPhoto + } + return "" +} + +func (x *InfoReply_Data) GetBirthday() string { + if x != nil { + return x.Birthday + } + return "" +} + +func (x *InfoReply_Data) GetTags() []string { + if x != nil { + return x.Tags + } + return nil +} + +func (x *InfoReply_Data) GetIsSeniorMember() uint32 { + if x != nil { + return x.IsSeniorMember + } + return 0 +} + +func (x *InfoReply_Data) GetMcnInfo() string { + if x != nil { + return x.McnInfo + } + return "" +} + +func (x *InfoReply_Data) GetGaiaResType() uint32 { + if x != nil { + return x.GaiaResType + } + return 0 +} + +func (x *InfoReply_Data) GetGaiaData() string { + if x != nil { + return x.GaiaData + } + return "" +} + +func (x *InfoReply_Data) GetIsRisk() bool { + if x != nil { + return x.IsRisk + } + return false +} + +var File_api_proto protoreflect.FileDescriptor + +var file_api_proto_rawDesc = []byte{ + 0x0a, 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x61, 0x70, 0x69, + 0x22, 0x1f, 0x0a, 0x0b, 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x75, 0x69, + 0x64, 0x22, 0xdf, 0x01, 0x0a, 0x09, 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, + 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, + 0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x27, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x1a, 0x82, + 0x01, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x6d, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x6f, 0x6c, + 0x6c, 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x66, 0x6f, + 0x6c, 0x6c, 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x77, 0x68, 0x69, 0x73, 0x70, + 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x77, 0x68, 0x69, 0x73, 0x70, 0x65, + 0x72, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x6c, 0x61, 0x63, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, + 0x52, 0x05, 0x62, 0x6c, 0x61, 0x63, 0x6b, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x6f, 0x6c, 0x6c, 0x6f, + 0x77, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x66, 0x6f, 0x6c, 0x6c, 0x6f, + 0x77, 0x65, 0x72, 0x22, 0x1f, 0x0a, 0x0b, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, + 0x03, 0x75, 0x69, 0x64, 0x22, 0xba, 0x05, 0x0a, 0x09, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x27, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x6e, 0x66, + 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x1a, 0xdd, 0x04, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x6d, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, + 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x12, 0x10, 0x0a, 0x03, 0x73, 0x65, 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, + 0x65, 0x78, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x61, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x66, 0x61, 0x63, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x66, 0x61, 0x63, 0x65, 0x5f, 0x6e, + 0x66, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x66, 0x61, 0x63, 0x65, 0x4e, 0x66, + 0x74, 0x12, 0x22, 0x0a, 0x0d, 0x66, 0x61, 0x63, 0x65, 0x5f, 0x6e, 0x66, 0x74, 0x5f, 0x74, 0x79, + 0x70, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0b, 0x66, 0x61, 0x63, 0x65, 0x4e, 0x66, + 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x67, 0x6e, 0x18, 0x07, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x73, 0x69, 0x67, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x61, 0x6e, + 0x6b, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x12, 0x14, 0x0a, + 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x6c, 0x65, + 0x76, 0x65, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x6a, 0x6f, 0x69, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x18, + 0x0a, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6a, 0x6f, 0x69, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x12, + 0x14, 0x0a, 0x05, 0x6d, 0x6f, 0x72, 0x61, 0x6c, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, + 0x6d, 0x6f, 0x72, 0x61, 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x69, 0x6c, 0x65, 0x6e, 0x63, 0x65, + 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x73, 0x69, 0x6c, 0x65, 0x6e, 0x63, 0x65, 0x12, + 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x69, 0x6e, 0x73, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, + 0x63, 0x6f, 0x69, 0x6e, 0x73, 0x12, 0x1d, 0x0a, 0x0a, 0x66, 0x61, 0x6e, 0x73, 0x5f, 0x62, 0x61, + 0x64, 0x67, 0x65, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x66, 0x61, 0x6e, 0x73, 0x42, + 0x61, 0x64, 0x67, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x73, 0x5f, 0x66, 0x6f, 0x6c, 0x6c, 0x6f, + 0x77, 0x65, 0x64, 0x18, 0x15, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x69, 0x73, 0x46, 0x6f, 0x6c, + 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x74, 0x6f, 0x70, 0x5f, 0x70, 0x68, 0x6f, + 0x74, 0x6f, 0x18, 0x16, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x74, 0x6f, 0x70, 0x50, 0x68, 0x6f, + 0x74, 0x6f, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x69, 0x72, 0x74, 0x68, 0x64, 0x61, 0x79, 0x18, 0x1a, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x62, 0x69, 0x72, 0x74, 0x68, 0x64, 0x61, 0x79, 0x12, 0x12, + 0x0a, 0x04, 0x74, 0x61, 0x67, 0x73, 0x18, 0x1d, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x74, 0x61, + 0x67, 0x73, 0x12, 0x28, 0x0a, 0x10, 0x69, 0x73, 0x5f, 0x73, 0x65, 0x6e, 0x69, 0x6f, 0x72, 0x5f, + 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x1f, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0e, 0x69, 0x73, + 0x53, 0x65, 0x6e, 0x69, 0x6f, 0x72, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, + 0x6d, 0x63, 0x6e, 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x20, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x6d, 0x63, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x22, 0x0a, 0x0d, 0x67, 0x61, 0x69, 0x61, 0x5f, + 0x72, 0x65, 0x73, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x21, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0b, + 0x67, 0x61, 0x69, 0x61, 0x52, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x67, + 0x61, 0x69, 0x61, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x22, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x67, 0x61, 0x69, 0x61, 0x44, 0x61, 0x74, 0x61, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x73, 0x5f, 0x72, + 0x69, 0x73, 0x6b, 0x18, 0x23, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x69, 0x73, 0x52, 0x69, 0x73, + 0x6b, 0x32, 0x74, 0x0a, 0x07, 0x42, 0x69, 0x6c, 0x69, 0x41, 0x50, 0x49, 0x12, 0x31, 0x0a, 0x0b, + 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x12, 0x10, 0x2e, 0x61, 0x70, + 0x69, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e, + 0x61, 0x70, 0x69, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, + 0x36, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x42, 0x61, 0x73, 0x69, 0x63, 0x49, + 0x6e, 0x66, 0x6f, 0x12, 0x10, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x6e, 0x66, 0x6f, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_api_proto_rawDescOnce sync.Once + file_api_proto_rawDescData = file_api_proto_rawDesc +) + +func file_api_proto_rawDescGZIP() []byte { + file_api_proto_rawDescOnce.Do(func() { + file_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_api_proto_rawDescData) + }) + return file_api_proto_rawDescData +} + +var file_api_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_api_proto_goTypes = []interface{}{ + (*StatRequest)(nil), // 0: api.StatRequest + (*StatReply)(nil), // 1: api.StatReply + (*InfoRequest)(nil), // 2: api.InfoRequest + (*InfoReply)(nil), // 3: api.InfoReply + (*StatReply_Data)(nil), // 4: api.StatReply.Data + (*InfoReply_Data)(nil), // 5: api.InfoReply.Data +} +var file_api_proto_depIdxs = []int32{ + 4, // 0: api.StatReply.data:type_name -> api.StatReply.Data + 5, // 1: api.InfoReply.data:type_name -> api.InfoReply.Data + 0, // 2: api.BiliAPI.GetUserStat:input_type -> api.StatRequest + 2, // 3: api.BiliAPI.GetUserBasicInfo:input_type -> api.InfoRequest + 1, // 4: api.BiliAPI.GetUserStat:output_type -> api.StatReply + 3, // 5: api.BiliAPI.GetUserBasicInfo:output_type -> api.InfoReply + 4, // [4:6] is the sub-list for method output_type + 2, // [2:4] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_api_proto_init() } +func file_api_proto_init() { + if File_api_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_api_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StatRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_api_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StatReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_api_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*InfoRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_api_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*InfoReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_api_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StatReply_Data); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_api_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*InfoReply_Data); 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_api_proto_rawDesc, + NumEnums: 0, + NumMessages: 6, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_api_proto_goTypes, + DependencyIndexes: file_api_proto_depIdxs, + MessageInfos: file_api_proto_msgTypes, + }.Build() + File_api_proto = out.File + file_api_proto_rawDesc = nil + file_api_proto_goTypes = nil + file_api_proto_depIdxs = nil +} diff --git a/rpc/pb/api_grpc.pb.go b/rpc/pb/api_grpc.pb.go new file mode 100644 index 0000000..8b4ac8d --- /dev/null +++ b/rpc/pb/api_grpc.pb.go @@ -0,0 +1,141 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.21.8 +// source: api.proto + +package pb + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// BiliAPIClient is the client API for BiliAPI service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type BiliAPIClient interface { + GetUserStat(ctx context.Context, in *StatRequest, opts ...grpc.CallOption) (*StatReply, error) + GetUserBasicInfo(ctx context.Context, in *InfoRequest, opts ...grpc.CallOption) (*InfoReply, error) +} + +type biliAPIClient struct { + cc grpc.ClientConnInterface +} + +func NewBiliAPIClient(cc grpc.ClientConnInterface) BiliAPIClient { + return &biliAPIClient{cc} +} + +func (c *biliAPIClient) GetUserStat(ctx context.Context, in *StatRequest, opts ...grpc.CallOption) (*StatReply, error) { + out := new(StatReply) + err := c.cc.Invoke(ctx, "/api.BiliAPI/GetUserStat", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *biliAPIClient) GetUserBasicInfo(ctx context.Context, in *InfoRequest, opts ...grpc.CallOption) (*InfoReply, error) { + out := new(InfoReply) + err := c.cc.Invoke(ctx, "/api.BiliAPI/GetUserBasicInfo", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// BiliAPIServer is the server API for BiliAPI service. +// All implementations must embed UnimplementedBiliAPIServer +// for forward compatibility +type BiliAPIServer interface { + GetUserStat(context.Context, *StatRequest) (*StatReply, error) + GetUserBasicInfo(context.Context, *InfoRequest) (*InfoReply, error) + mustEmbedUnimplementedBiliAPIServer() +} + +// UnimplementedBiliAPIServer must be embedded to have forward compatible implementations. +type UnimplementedBiliAPIServer struct { +} + +func (UnimplementedBiliAPIServer) GetUserStat(context.Context, *StatRequest) (*StatReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetUserStat not implemented") +} +func (UnimplementedBiliAPIServer) GetUserBasicInfo(context.Context, *InfoRequest) (*InfoReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetUserBasicInfo not implemented") +} +func (UnimplementedBiliAPIServer) mustEmbedUnimplementedBiliAPIServer() {} + +// UnsafeBiliAPIServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to BiliAPIServer will +// result in compilation errors. +type UnsafeBiliAPIServer interface { + mustEmbedUnimplementedBiliAPIServer() +} + +func RegisterBiliAPIServer(s grpc.ServiceRegistrar, srv BiliAPIServer) { + s.RegisterService(&BiliAPI_ServiceDesc, srv) +} + +func _BiliAPI_GetUserStat_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StatRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BiliAPIServer).GetUserStat(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/api.BiliAPI/GetUserStat", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BiliAPIServer).GetUserStat(ctx, req.(*StatRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _BiliAPI_GetUserBasicInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(InfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BiliAPIServer).GetUserBasicInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/api.BiliAPI/GetUserBasicInfo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BiliAPIServer).GetUserBasicInfo(ctx, req.(*InfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// BiliAPI_ServiceDesc is the grpc.ServiceDesc for BiliAPI service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var BiliAPI_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "api.BiliAPI", + HandlerType: (*BiliAPIServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetUserStat", + Handler: _BiliAPI_GetUserStat_Handler, + }, + { + MethodName: "GetUserBasicInfo", + Handler: _BiliAPI_GetUserBasicInfo_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "api.proto", +} diff --git a/rpc/service.go b/rpc/service.go new file mode 100644 index 0000000..3e67f75 --- /dev/null +++ b/rpc/service.go @@ -0,0 +1,115 @@ +package rpc + +import ( + "context" + "encoding/json" + "fmt" + "github.com/furryboard/spider-core/biliapi" + "github.com/furryboard/spider-core/rpc/pb" + "github.com/mitchellh/mapstructure" + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" +) + +type Service struct { + pb.UnimplementedBiliAPIServer +} + +// GetUserStat 用户统计信息 +func (s *Service) GetUserStat(ctx context.Context, req *pb.StatRequest) (*pb.StatReply, error) { + body, err := biliapi.UserStat(uint(req.Uid)) + if err != nil { + return &pb.StatReply{ + Code: 400, + Msg: err.Error(), + Data: nil, + }, err + } + + bodyObj := biliapi.Root{} + err = json.Unmarshal(body, &bodyObj) + if err != nil { + return &pb.StatReply{ + Code: 400, + Msg: err.Error(), + Data: nil, + }, err + } + + if bodyObj.Code != 0 { + fmt.Println("bad request: " + bodyObj.Message) + return &pb.StatReply{ + Code: int32(bodyObj.Code), + Msg: bodyObj.Message, + Data: nil, + }, err + } + + data := &biliapi.StatData{} + err = mapstructure.Decode(bodyObj.Data, data) + if err != nil { + return &pb.StatReply{ + Code: 500, + Msg: err.Error(), + Data: nil, + }, err + } + statData := pb.StatReply_Data{ + Mid: data.Mid, + Following: data.Following, + Whisper: data.Whisper, + Black: data.Black, + Follower: data.Follower, + } + return &pb.StatReply{ + Code: 200, + Msg: "", + Data: &statData, + }, nil +} + +// GetUserBasicInfo 用户基础信息 +func (s *Service) GetUserBasicInfo(ctx context.Context, req *pb.InfoRequest) (*pb.InfoReply, error) { + body, err := biliapi.BasicInfo(uint(req.Uid)) + bodyObj := biliapi.Root{} + err = json.Unmarshal(body, &bodyObj) + if err != nil { + fmt.Println("bad request: " + err.Error()) + return &pb.InfoReply{ + Code: 400, + Msg: err.Error(), + Data: nil, + }, err + } + + if bodyObj.Code != 0 { + fmt.Println("bad request: " + bodyObj.Message) + return &pb.InfoReply{ + Code: int32(bodyObj.Code), + Msg: bodyObj.Message, + Data: nil, + }, err + } + + // interface映射到结构体 + data := &pb.InfoReply_Data{} + err = mapstructure.Decode(bodyObj.Data, data) + if err != nil { + return &pb.InfoReply{ + Code: 500, + Msg: err.Error(), + Data: nil, + }, err + } + return &pb.InfoReply{ + Code: 200, + Msg: "", + Data: data, + }, nil + +} + +func RegisterServices(s *grpc.Server) { + pb.RegisterBiliAPIServer(s, &Service{}) + reflection.Register(s) +}