Commit 74a55d2a by Li Feifei

im service api init

parent 263bf26a
package gateway
import (
"context"
beeLogger "github.com/beego/bee/logger"
"net/http"
"strings"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"im-microservice/pb"
_ "im-microservice/google_api"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
"google.golang.org/grpc"
)
// ProvideHTTP 把gRPC服务转成HTTP服务,让gRPC同时支持HTTP
func ProvideHTTP(endpoint string, grpcServer *grpc.Server) *http.Server {
ctx := context.Background()
//获取证书
//添加证书
dopts := []grpc.DialOption{grpc.WithInsecure()}
//新建gwmux,它是grpc-gateway的请求复用器。它将http请求与模式匹配,并调用相应的处理程序。
gwmux := runtime.NewServeMux()
//将服务的http处理程序注册到gwmux。处理程序通过endpoint转发请求到grpc端点
err := pb.RegisterUserRelationshipServiceHandlerFromEndpoint(ctx, gwmux, endpoint, dopts)
if err != nil {
beeLogger.Log.Fatalf("Register Endpoint err: %v", err)
}
//新建mux,它是http的请求复用器
mux := http.NewServeMux()
//注册gwmux
mux.Handle("/", gwmux)
beeLogger.Log.Success(endpoint + " HTTP.Listing...")
return &http.Server{
Addr: endpoint,
Handler: grpcHandlerFunc( grpcServer, mux),
}
}
var HeaderValues map[string]string
// grpcHandlerFunc 根据不同的请求重定向到指定的Handler处理
func grpcHandlerFunc(grpcServer *grpc.Server, otherHandler http.Handler) http.Handler {
return h2c.NewHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Appkey") != "" {
HeaderValues = map[string]string{
"Appkey" : r.Header.Get("Appkey"),
"Nonce" : r.Header.Get("Nonce"),
"Curtime" : r.Header.Get("Curtime"),
"Checksum" : r.Header.Get("Checksum"),
}
}
ctx := context.WithValue(r.Context(), "Header", HeaderValues)
if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") {
grpcServer.ServeHTTP(w, r.WithContext(ctx))
} else {
otherHandler.ServeHTTP(w, r.WithContext(ctx))
}
}), &http2.Server{})
}
...@@ -18,6 +18,7 @@ require ( ...@@ -18,6 +18,7 @@ require (
github.com/golang/protobuf v1.4.2 github.com/golang/protobuf v1.4.2
github.com/google/pprof v0.0.0-20200630070148-6609db78bf68 // indirect github.com/google/pprof v0.0.0-20200630070148-6609db78bf68 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 github.com/grpc-ecosystem/go-grpc-middleware v1.2.0
github.com/grpc-ecosystem/grpc-gateway v1.14.6
github.com/grpc-ecosystem/grpc-health-probe v0.3.2 // indirect github.com/grpc-ecosystem/grpc-health-probe v0.3.2 // indirect
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 // indirect github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 // indirect
github.com/ianlancetaylor/demangle v0.0.0-20200705045648-b855e248e31b // indirect github.com/ianlancetaylor/demangle v0.0.0-20200705045648-b855e248e31b // indirect
...@@ -36,15 +37,14 @@ require ( ...@@ -36,15 +37,14 @@ require (
github.com/spf13/afero v1.3.1 // indirect github.com/spf13/afero v1.3.1 // indirect
github.com/stretchr/objx v0.2.0 // indirect github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.6.1 // indirect github.com/stretchr/testify v1.6.1 // indirect
github.com/yuin/goldmark v1.1.32 // indirect
go.opencensus.io v0.22.4 // indirect go.opencensus.io v0.22.4 // indirect
go.uber.org/zap v1.10.0 go.uber.org/zap v1.10.0
golang.org/x/net v0.0.0-20200625001655-4c5254603344 golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 // indirect
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 // indirect golang.org/x/net v0.0.0-20200707034311-ab3426394381
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
golang.org/x/text v0.3.3 // indirect golang.org/x/text v0.3.3 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
golang.org/x/tools v0.0.0-20200702044944-0cc1aa72b347 // indirect golang.org/x/tools v0.0.0-20200709181711-e327e1019dfe // indirect
google.golang.org/genproto v0.0.0-20200702021140-07506425bd67 // indirect google.golang.org/genproto v0.0.0-20200702021140-07506425bd67 // indirect
google.golang.org/grpc v1.30.0 google.golang.org/grpc v1.30.0
google.golang.org/protobuf v1.25.0 google.golang.org/protobuf v1.25.0
......
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.25.0
// protoc v3.12.3
// source: annotations.proto
package google_api
import (
proto "github.com/golang/protobuf/proto"
descriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
)
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)
)
// This is a compile-time assertion that a sufficiently up-to-date version
// of the legacy proto package is being used.
const _ = proto.ProtoPackageIsVersion4
var file_annotations_proto_extTypes = []protoimpl.ExtensionInfo{
{
ExtendedType: (*descriptor.MethodOptions)(nil),
ExtensionType: (*HttpRule)(nil),
Field: 72295728,
Name: "google.api.http",
Tag: "bytes,72295728,opt,name=http",
Filename: "annotations.proto",
},
}
// Extension fields to descriptor.MethodOptions.
var (
// See `HttpRule`.
//
// optional google.api.HttpRule http = 72295728;
E_Http = &file_annotations_proto_extTypes[0]
)
var File_annotations_proto protoreflect.FileDescriptor
var file_annotations_proto_rawDesc = []byte{
0x0a, 0x11, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x1a,
0x0a, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x67, 0x6f, 0x6f,
0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x65, 0x73,
0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3a, 0x4b, 0x0a,
0x04, 0x68, 0x74, 0x74, 0x70, 0x12, 0x1e, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70,
0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xb0, 0xca, 0xbc, 0x22, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14,
0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x74, 0x74, 0x70,
0x52, 0x75, 0x6c, 0x65, 0x52, 0x04, 0x68, 0x74, 0x74, 0x70, 0x42, 0x24, 0x0a, 0x0e, 0x63, 0x6f,
0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x42, 0x10, 0x41, 0x6e,
0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var file_annotations_proto_goTypes = []interface{}{
(*descriptor.MethodOptions)(nil), // 0: google.protobuf.MethodOptions
(*HttpRule)(nil), // 1: google.api.HttpRule
}
var file_annotations_proto_depIdxs = []int32{
0, // 0: google.api.http:extendee -> google.protobuf.MethodOptions
1, // 1: google.api.http:type_name -> google.api.HttpRule
2, // [2:2] is the sub-list for method output_type
2, // [2:2] is the sub-list for method input_type
1, // [1:2] is the sub-list for extension type_name
0, // [0:1] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_annotations_proto_init() }
func file_annotations_proto_init() {
if File_annotations_proto != nil {
return
}
file_http_proto_init()
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_annotations_proto_rawDesc,
NumEnums: 0,
NumMessages: 0,
NumExtensions: 1,
NumServices: 0,
},
GoTypes: file_annotations_proto_goTypes,
DependencyIndexes: file_annotations_proto_depIdxs,
ExtensionInfos: file_annotations_proto_extTypes,
}.Build()
File_annotations_proto = out.File
file_annotations_proto_rawDesc = nil
file_annotations_proto_goTypes = nil
file_annotations_proto_depIdxs = nil
}
...@@ -46,7 +46,7 @@ func init() { ...@@ -46,7 +46,7 @@ func init() {
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer( grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
middleware.Interceptor, middleware.Interceptor,
grpc_validator.UnaryServerInterceptor(), grpc_validator.UnaryServerInterceptor(),
//middleware.Auth, middleware.Auth,
grpc_recovery.UnaryServerInterceptor(middleware.RecoveryInterceptor()), grpc_recovery.UnaryServerInterceptor(middleware.RecoveryInterceptor()),
grpc_zap.UnaryServerInterceptor(middleware.ZapInterceptor()), grpc_zap.UnaryServerInterceptor(middleware.ZapInterceptor()),
))) )))
......
...@@ -3,12 +3,14 @@ package main ...@@ -3,12 +3,14 @@ package main
import ( import (
"net" "net"
"im-microservice/gateway"
initialize "im-microservice/initialization" initialize "im-microservice/initialization"
beeLogger "github.com/beego/bee/logger" beeLogger "github.com/beego/bee/logger"
) )
const ( const (
Address string = "127.0.0.1:8000"
port = ":50051" port = ":50051"
) )
...@@ -20,6 +22,12 @@ func main() { ...@@ -20,6 +22,12 @@ func main() {
} }
beeLogger.Log.Success("gRPC server is running on " + port + " port.") beeLogger.Log.Success("gRPC server is running on " + port + " port.")
go func() {
if err := gateway.ProvideHTTP(Address, initialize.RpcServer).ListenAndServe(); err != nil {
beeLogger.Log.Fatalf("failed to api serve: %v", err)
}
}()
if err := initialize.RpcServer.Serve(lis); err != nil { if err := initialize.RpcServer.Serve(lis); err != nil {
beeLogger.Log.Fatalf("failed to serve: %v", err) beeLogger.Log.Fatalf("failed to serve: %v", err)
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"crypto/sha1" "crypto/sha1"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"google.golang.org/grpc/metadata"
"regexp" "regexp"
"strconv" "strconv"
"time" "time"
...@@ -28,7 +29,7 @@ func checksum(req map[string]string) error { ...@@ -28,7 +29,7 @@ func checksum(req map[string]string) error {
err, AppSecret := helper.GetSecretByKey(req["Appkey"]) err, AppSecret := helper.GetSecretByKey(req["Appkey"])
if err != nil { if err != nil {
return status.Error(codes.NotFound, "appkey不存在") return status.Error(codes.NotFound, "Appkey不存在")
} }
server_time := time.Now().Unix() server_time := time.Now().Unix()
...@@ -50,22 +51,39 @@ func checksum(req map[string]string) error { ...@@ -50,22 +51,39 @@ func checksum(req map[string]string) error {
return nil return nil
} }
func Auth(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, func Auth(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler) (interface{}, error) { handler grpc.UnaryHandler) (interface{}, error) {
if info.FullMethod != health_path { if info.FullMethod != health_path {
request_map := make(map[string]string) request_map := make(map[string]string)
key_r, _ := regexp.Compile(`[^}|^Common:]\s?(.*?):"(.*?)"`) if md, ok := metadata.FromIncomingContext(ctx); ok {
if _, ok := md["x-forwarded-for"]; ok {
request_map = ctx.Value("Header").(map[string]string)
result := key_r.FindAllStringSubmatch(fmt.Sprintf("%v", req), -1) if request_map["Appkey"] == "" {
for _, v := range result { return nil, status.Error(codes.NotFound, "Appkey不能为空")
request_map[v[1]] = v[2] }
if request_map["Curtime"] == "" {
return nil, status.Error(codes.NotFound, "Curtime不能为空")
}
if request_map["Nonce"] == "" {
return nil, status.Error(codes.NotFound, "Nonce不能为空")
}
if request_map["Checksum"] == "" {
return nil, status.Error(codes.NotFound, "Checksum不能为空")
}
} else {
key_r, _ := regexp.Compile(`[^}|^Common:]\s?(.*?):"(.*?)"`)
result := key_r.FindAllStringSubmatch(fmt.Sprintf("%v", req), -1)
for _, v := range result {
request_map[v[1]] = v[2]
}
}
if err := checksum(request_map); err != nil {
return nil, err
}
} }
if err := checksum(request_map); err != nil {
return nil, err
}
} }
return handler(ctx, req) return handler(ctx, req)
} }
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: u-proto/im_user_relationship.proto
/*
Package pb is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
*/
package pb
import (
"context"
"io"
"net/http"
"github.com/golang/protobuf/descriptor"
"github.com/golang/protobuf/proto"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/grpc-ecosystem/grpc-gateway/utilities"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/status"
)
// Suppress "imported and not used" errors
var _ codes.Code
var _ io.Reader
var _ status.Status
var _ = runtime.String
var _ = utilities.NewDoubleArray
var _ = descriptor.ForMessage
var (
filter_UserRelationshipService_ListBlackAndMuteList_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
func request_UserRelationshipService_ListBlackAndMuteList_0(ctx context.Context, marshaler runtime.Marshaler, client UserRelationshipServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq ListBlackAndMuteListReq
var metadata runtime.ServerMetadata
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_UserRelationshipService_ListBlackAndMuteList_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.ListBlackAndMuteList(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_UserRelationshipService_ListBlackAndMuteList_0(ctx context.Context, marshaler runtime.Marshaler, server UserRelationshipServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq ListBlackAndMuteListReq
var metadata runtime.ServerMetadata
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_UserRelationshipService_ListBlackAndMuteList_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.ListBlackAndMuteList(ctx, &protoReq)
return msg, metadata, err
}
// RegisterUserRelationshipServiceHandlerServer registers the http handlers for service UserRelationshipService to "mux".
// UnaryRPC :call UserRelationshipServiceServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
func RegisterUserRelationshipServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server UserRelationshipServiceServer) error {
mux.Handle("GET", pattern_UserRelationshipService_ListBlackAndMuteList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_UserRelationshipService_ListBlackAndMuteList_0(rctx, inboundMarshaler, server, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_UserRelationshipService_ListBlackAndMuteList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
// RegisterUserRelationshipServiceHandlerFromEndpoint is same as RegisterUserRelationshipServiceHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterUserRelationshipServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
conn, err := grpc.Dial(endpoint, opts...)
if err != nil {
return err
}
defer func() {
if err != nil {
if cerr := conn.Close(); cerr != nil {
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
}
return
}
go func() {
<-ctx.Done()
if cerr := conn.Close(); cerr != nil {
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
}
}()
}()
return RegisterUserRelationshipServiceHandler(ctx, mux, conn)
}
// RegisterUserRelationshipServiceHandler registers the http handlers for service UserRelationshipService to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func RegisterUserRelationshipServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterUserRelationshipServiceHandlerClient(ctx, mux, NewUserRelationshipServiceClient(conn))
}
// RegisterUserRelationshipServiceHandlerClient registers the http handlers for service UserRelationshipService
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "UserRelationshipServiceClient".
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "UserRelationshipServiceClient"
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "UserRelationshipServiceClient" to call the correct interceptors.
func RegisterUserRelationshipServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client UserRelationshipServiceClient) error {
mux.Handle("GET", pattern_UserRelationshipService_ListBlackAndMuteList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_UserRelationshipService_ListBlackAndMuteList_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_UserRelationshipService_ListBlackAndMuteList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_UserRelationshipService_ListBlackAndMuteList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "listBlackAndMuteList"}, "", runtime.AssumeColonVerbOpt(true)))
)
var (
forward_UserRelationshipService_ListBlackAndMuteList_0 = runtime.ForwardResponseMessage
)
...@@ -29,10 +29,10 @@ func (us *UserRelationshipService) Add(ctx context.Context, ...@@ -29,10 +29,10 @@ func (us *UserRelationshipService) Add(ctx context.Context,
// 更改用户版本信息 // 更改用户版本信息
u_map := make(map[string]interface{}) u_map := make(map[string]interface{})
u_map["edition"] = helper.GetNowTime() u_map["edition"] = helper.GetNowTime()
_, _ = im_user.UpdateImUser(in.Accid, u_map) _, _ = im_user.UpdateImUser(in.Accid, in.Common.Appkey, u_map)
// 更改请求用户版本信息 // 更改请求用户版本信息
_, _ = im_user.UpdateImUser(in.Faccid, u_map) _, _ = im_user.UpdateImUser(in.Faccid, in.Common.Appkey, u_map)
reply = &pb.UserRelationshipAddReply{} reply = &pb.UserRelationshipAddReply{}
return return
...@@ -52,10 +52,10 @@ func (us *UserRelationshipService) Delete(ctx context.Context, ...@@ -52,10 +52,10 @@ func (us *UserRelationshipService) Delete(ctx context.Context,
// 更改用户版本信息 // 更改用户版本信息
u_map := make(map[string]interface{}) u_map := make(map[string]interface{})
u_map["edition"] = helper.GetNowTime() u_map["edition"] = helper.GetNowTime()
_, _ = im_user.UpdateImUser(in.Accid, u_map) _, _ = im_user.UpdateImUser(in.Accid, in.Common.Appkey, u_map)
// 更改被添加用户版本信息 // 更改被添加用户版本信息
_, _ = im_user.UpdateImUser(in.Faccid, u_map) _, _ = im_user.UpdateImUser(in.Faccid, in.Common.Appkey, u_map)
reply = &pb.UserRelationshipAddReply{} reply = &pb.UserRelationshipAddReply{}
return return
...@@ -106,6 +106,7 @@ func (us *UserRelationshipService) ListBlackAndMuteList(ctx context.Context, ...@@ -106,6 +106,7 @@ func (us *UserRelationshipService) ListBlackAndMuteList(ctx context.Context,
return return
} }
blacklist, mutelist, err := ListBlackAndMuteListDB(in) blacklist, mutelist, err := ListBlackAndMuteListDB(in)
if err != nil { if err != nil {
err = status.Error(codes.Internal, err.Error()) err = status.Error(codes.Internal, err.Error())
......
syntax = "proto3";
package google.api;
import "u-proto/google/api/http.proto";
import "google/protobuf/descriptor.proto";
option java_multiple_files = true;
option java_outer_classname = "AnnotationsProto";
option java_package = "com.google.api";
extend google.protobuf.MethodOptions {
// See `HttpRule`.
HttpRule http = 72295728;
}
\ No newline at end of file
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";
package google.api;
option cc_enable_arenas = true;
option java_multiple_files = true;
option java_outer_classname = "HttpProto";
option java_package = "com.google.api";
// Defines the HTTP configuration for a service. It contains a list of
// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method
// to one or more HTTP REST API methods.
message Http {
// A list of HTTP rules for configuring the HTTP REST API methods.
repeated HttpRule rules = 1;
}
// `HttpRule` defines the mapping of an RPC method to one or more HTTP
// REST APIs. The mapping determines what portions of the request
// message are populated from the path, query parameters, or body of
// the HTTP request. The mapping is typically specified as an
// `google.api.http` annotation, see "google/api/annotations.proto"
// for details.
//
// The mapping consists of a field specifying the path template and
// method kind. The path template can refer to fields in the request
// message, as in the example below which describes a REST GET
// operation on a resource collection of messages:
//
// ```proto
// service Messaging {
// rpc GetMessage(GetMessageRequest) returns (Message) {
// option (google.api.http).get = "/v1/messages/{message_id}/{sub.subfield}";
// }
// }
// message GetMessageRequest {
// message SubMessage {
// string subfield = 1;
// }
// string message_id = 1; // mapped to the URL
// SubMessage sub = 2; // `sub.subfield` is url-mapped
// }
// message Message {
// string text = 1; // content of the resource
// }
// ```
//
// This definition enables an automatic, bidrectional mapping of HTTP
// JSON to RPC. Example:
//
// HTTP | RPC
// -----|-----
// `GET /v1/messages/123456/foo` | `GetMessage(message_id: "123456" sub: SubMessage(subfield: "foo"))`
//
// In general, not only fields but also field paths can be referenced
// from a path pattern. Fields mapped to the path pattern cannot be
// repeated and must have a primitive (non-message) type.
//
// Any fields in the request message which are not bound by the path
// pattern automatically become (optional) HTTP query
// parameters. Assume the following definition of the request message:
//
// ```proto
// message GetMessageRequest {
// message SubMessage {
// string subfield = 1;
// }
// string message_id = 1; // mapped to the URL
// int64 revision = 2; // becomes a parameter
// SubMessage sub = 3; // `sub.subfield` becomes a parameter
// }
// ```
//
// This enables a HTTP JSON to RPC mapping as below:
//
// HTTP | RPC
// -----|-----
// `GET /v1/messages/123456?revision=2&sub.subfield=foo` | `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: "foo"))`
//
// Note that fields which are mapped to HTTP parameters must have a
// primitive type or a repeated primitive type. Message types are not
// allowed. In the case of a repeated type, the parameter can be
// repeated in the URL, as in `...?param=A&param=B`.
//
// For HTTP method kinds which allow a request body, the `body` field
// specifies the mapping. Consider a REST update method on the
// message resource collection:
//
// ```proto
// service Messaging {
// rpc UpdateMessage(UpdateMessageRequest) returns (Message) {
// option (google.api.http) = {
// put: "/v1/messages/{message_id}"
// body: "message"
// };
// }
// }
// message UpdateMessageRequest {
// string message_id = 1; // mapped to the URL
// Message message = 2; // mapped to the body
// }
// ```
//
// The following HTTP JSON to RPC mapping is enabled, where the
// representation of the JSON in the request body is determined by
// protos JSON encoding:
//
// HTTP | RPC
// -----|-----
// `PUT /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "123456" message { text: "Hi!" })`
//
// The special name `*` can be used in the body mapping to define that
// every field not bound by the path template should be mapped to the
// request body. This enables the following alternative definition of
// the update method:
//
// ```proto
// service Messaging {
// rpc UpdateMessage(Message) returns (Message) {
// option (google.api.http) = {
// put: "/v1/messages/{message_id}"
// body: "*"
// };
// }
// }
// message Message {
// string message_id = 1;
// string text = 2;
// }
// ```
//
// The following HTTP JSON to RPC mapping is enabled:
//
// HTTP | RPC
// -----|-----
// `PUT /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "123456" text: "Hi!")`
//
// Note that when using `*` in the body mapping, it is not possible to
// have HTTP parameters, as all fields not bound by the path end in
// the body. This makes this option more rarely used in practice of
// defining REST APIs. The common usage of `*` is in custom methods
// which don't use the URL at all for transferring data.
//
// It is possible to define multiple HTTP methods for one RPC by using
// the `additional_bindings` option. Example:
//
// ```proto
// service Messaging {
// rpc GetMessage(GetMessageRequest) returns (Message) {
// option (google.api.http) = {
// get: "/v1/messages/{message_id}"
// additional_bindings {
// get: "/v1/users/{user_id}/messages/{message_id}"
// }
// };
// }
// }
// message GetMessageRequest {
// string message_id = 1;
// string user_id = 2;
// }
// ```
//
// This enables the following two alternative HTTP JSON to RPC
// mappings:
//
// HTTP | RPC
// -----|-----
// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")`
// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: "123456")`
//
// # Rules for HTTP mapping
//
// The rules for mapping HTTP path, query parameters, and body fields
// to the request message are as follows:
//
// 1. The `body` field specifies either `*` or a field path, or is
// omitted. If omitted, it assumes there is no HTTP body.
// 2. Leaf fields (recursive expansion of nested messages in the
// request) can be classified into three types:
// (a) Matched in the URL template.
// (b) Covered by body (if body is `*`, everything except (a) fields;
// else everything under the body field)
// (c) All other fields.
// 3. URL query parameters found in the HTTP request are mapped to (c) fields.
// 4. Any body sent with an HTTP request can contain only (b) fields.
//
// The syntax of the path template is as follows:
//
// Template = "/" Segments [ Verb ] ;
// Segments = Segment { "/" Segment } ;
// Segment = "*" | "**" | LITERAL | Variable ;
// Variable = "{" FieldPath [ "=" Segments ] "}" ;
// FieldPath = IDENT { "." IDENT } ;
// Verb = ":" LITERAL ;
//
// The syntax `*` matches a single path segment. It follows the semantics of
// [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String
// Expansion.
//
// The syntax `**` matches zero or more path segments. It follows the semantics
// of [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.3 Reserved
// Expansion.
//
// The syntax `LITERAL` matches literal text in the URL path.
//
// The syntax `Variable` matches the entire path as specified by its template;
// this nested template must not contain further variables. If a variable
// matches a single path segment, its template may be omitted, e.g. `{var}`
// is equivalent to `{var=*}`.
//
// NOTE: the field paths in variables and in the `body` must not refer to
// repeated fields or map fields.
//
// Use CustomHttpPattern to specify any HTTP method that is not included in the
// `pattern` field, such as HEAD, or "*" to leave the HTTP method unspecified for
// a given URL path rule. The wild-card rule is useful for services that provide
// content to Web (HTML) clients.
message HttpRule {
// Selects methods to which this rule applies.
//
// Refer to [selector][google.api.DocumentationRule.selector] for syntax details.
string selector = 1;
// Determines the URL pattern is matched by this rules. This pattern can be
// used with any of the {get|put|post|delete|patch} methods. A custom method
// can be defined using the 'custom' field.
oneof pattern {
// Used for listing and getting information about resources.
string get = 2;
// Used for updating a resource.
string put = 3;
// Used for creating a resource.
string post = 4;
// Used for deleting a resource.
string delete = 5;
// Used for updating a resource.
string patch = 6;
// Custom pattern is used for defining custom verbs.
CustomHttpPattern custom = 8;
}
// The name of the request field whose value is mapped to the HTTP body, or
// `*` for mapping all fields not captured by the path pattern to the HTTP
// body. NOTE: the referred field must not be a repeated field.
string body = 7;
// Additional HTTP bindings for the selector. Nested bindings must
// not contain an `additional_bindings` field themselves (that is,
// the nesting may only be one level deep).
repeated HttpRule additional_bindings = 11;
}
// A custom pattern is used for defining custom HTTP verb.
message CustomHttpPattern {
// The name of this custom HTTP verb.
string kind = 1;
// The path matched by this custom verb.
string path = 2;
}
...@@ -3,6 +3,7 @@ syntax = "proto3"; ...@@ -3,6 +3,7 @@ syntax = "proto3";
package pb; package pb;
import "u-proto/common.proto"; import "u-proto/common.proto";
import "u-proto/google/api/annotations.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto"; import "github.com/mwitkow/go-proto-validators/validator.proto";
//添加好友 //添加好友
...@@ -66,5 +67,9 @@ service UserRelationshipService { ...@@ -66,5 +67,9 @@ service UserRelationshipService {
rpc Delete(UserRelationshipDelRequest) returns (UserRelationshipAddReply) {} rpc Delete(UserRelationshipDelRequest) returns (UserRelationshipAddReply) {}
rpc All(UserRelationshipListRequest) returns (UserRelationshipListReply) {} rpc All(UserRelationshipListRequest) returns (UserRelationshipListReply) {}
rpc SetSpecialRelation(SetSpecialRelationReq) returns (UserRelationshipAddReply) {} rpc SetSpecialRelation(SetSpecialRelationReq) returns (UserRelationshipAddReply) {}
rpc ListBlackAndMuteList(ListBlackAndMuteListReq) returns(ListBlackAndMuteListReply) {} rpc ListBlackAndMuteList(ListBlackAndMuteListReq) returns(ListBlackAndMuteListReply) {
option (google.api.http) ={
get:"/api/v1/listBlackAndMuteList"
};
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment