mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
api to rpc
This commit is contained in:
parent
03ccd0131a
commit
0411a5045b
83
go.mod
83
go.mod
@ -1,6 +1,6 @@
|
||||
module OpenIM
|
||||
|
||||
go 1.16
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
firebase.google.com/go v3.13.0+incompatible
|
||||
@ -53,16 +53,97 @@ require (
|
||||
require github.com/minio/minio-go v6.0.14+incompatible
|
||||
|
||||
require (
|
||||
cloud.google.com/go v0.105.0 // indirect
|
||||
cloud.google.com/go/compute v1.13.0 // indirect
|
||||
cloud.google.com/go/compute/metadata v0.2.1 // indirect
|
||||
cloud.google.com/go/firestore v1.9.0 // indirect
|
||||
cloud.google.com/go/iam v0.8.0 // indirect
|
||||
cloud.google.com/go/longrunning v0.3.0 // indirect
|
||||
cloud.google.com/go/storage v1.27.0 // indirect
|
||||
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect
|
||||
github.com/alibabacloud-go/endpoint-util v1.1.0 // indirect
|
||||
github.com/alibabacloud-go/openapi-util v0.0.9 // indirect
|
||||
github.com/alibabacloud-go/tea-utils v1.3.9 // indirect
|
||||
github.com/aliyun/credentials-go v1.1.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.8 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.14 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.8 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.15 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.8 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.11.12 // indirect
|
||||
github.com/aws/smithy-go v1.12.0 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||
github.com/eapache/go-resiliency v1.2.0 // indirect
|
||||
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
|
||||
github.com/eapache/queue v1.1.0 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-ini/ini v1.67.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
||||
github.com/go-stack/stack v1.8.0 // indirect
|
||||
github.com/go-zookeeper/zk v1.0.3 // indirect
|
||||
github.com/goccy/go-json v0.10.0 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
|
||||
github.com/golang/snappy v0.0.3 // indirect
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
|
||||
github.com/hashicorp/go-uuid v1.0.2 // indirect
|
||||
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
|
||||
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
|
||||
github.com/jcmturner/gofork v1.0.0 // indirect
|
||||
github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect
|
||||
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/jonboulle/clockwork v0.3.0 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.13.6 // indirect
|
||||
github.com/klauspost/cpuid v1.3.1 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/lestrrat-go/strftime v1.0.6 // indirect
|
||||
github.com/lithammer/shortuuid v3.0.0+incompatible // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||
github.com/minio/md5-simd v1.1.0 // indirect
|
||||
github.com/minio/sha256-simd v0.1.1 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
|
||||
github.com/pierrec/lz4 v2.6.0+incompatible // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/prometheus/client_model v0.2.0 // indirect
|
||||
github.com/prometheus/common v0.37.0 // indirect
|
||||
github.com/prometheus/procfs v0.8.0 // indirect
|
||||
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
|
||||
github.com/rs/xid v1.2.1 // indirect
|
||||
github.com/tjfoc/gmsm v1.3.2 // indirect
|
||||
github.com/ugorji/go/codec v1.2.8 // indirect
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||
github.com/xdg-go/scram v1.0.2 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.2 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
golang.org/x/crypto v0.5.0 // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/sys v0.4.0 // indirect
|
||||
golang.org/x/text v0.6.0 // indirect
|
||||
golang.org/x/time v0.1.0 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
|
||||
gopkg.in/ini.v1 v1.66.2 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/Shopify/sarama => github.com/Shopify/sarama v1.29.0
|
||||
|
28
internal/a2r/api2rpc.go
Normal file
28
internal/a2r/api2rpc.go
Normal file
@ -0,0 +1,28 @@
|
||||
package a2r
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
// Call TEST
|
||||
func Call[A, B, C, D, E any](
|
||||
apiReq *A,
|
||||
apiResp *B,
|
||||
rpc func(client E, ctx context.Context, req C, options ...grpc.CallOption) (D, error),
|
||||
client func() (E, error),
|
||||
c *gin.Context,
|
||||
before func(apiReq *A, rpcReq *C, bind func() error) error,
|
||||
after func(rpcResp *D, apiResp *B, bind func() error) error,
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
func Call1[C, D, E any](
|
||||
rpc func(client E, ctx context.Context, req C, options ...grpc.CallOption) (D, error),
|
||||
client func() (E, error),
|
||||
c *gin.Context,
|
||||
) {
|
||||
|
||||
}
|
@ -1,14 +1,19 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"OpenIM/internal/api2rpc"
|
||||
"OpenIM/internal/a2r"
|
||||
"OpenIM/pkg/apistruct"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/proto/group"
|
||||
"context"
|
||||
"github.com/OpenIMSDK/openKeeper"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func _() {
|
||||
context.Background()
|
||||
}
|
||||
|
||||
type Group struct {
|
||||
zk *openKeeper.ZkClient
|
||||
}
|
||||
@ -22,17 +27,9 @@ func (g *Group) getGroupClient() (group.GroupClient, error) {
|
||||
}
|
||||
|
||||
func (g *Group) KickGroupMember(c *gin.Context) {
|
||||
api2rpc.New(&apistruct.KickGroupMemberReq{}, &apistruct.KickGroupMemberResp{}, group.GroupClient.KickGroupMember).Call(c, g.getGroupClient)
|
||||
a2r.Call(&apistruct.KickGroupMemberReq{}, &apistruct.KickGroupMemberResp{}, group.GroupClient.KickGroupMember, g.getGroupClient, c, nil, nil)
|
||||
}
|
||||
|
||||
func (g *Group) GetGroupMembersInfo(c *gin.Context) {
|
||||
api2rpc.New(&apistruct.GetGroupMembersInfoReq{}, &apistruct.GetGroupMembersInfoResp{}, group.GroupClient.GetGroupMembersInfo).Call(c, g.getGroupClient)
|
||||
a2r.Call1(group.GroupClient.GetGroupMembersInfo, g.getGroupClient, c)
|
||||
}
|
||||
|
||||
//func GetGroupMembersInfo(c *gin.Context) {
|
||||
// api2rpc.New(&apistruct.GetGroupMembersInfoReq{}, &apistruct.GetGroupMembersInfoResp{}, group.GroupClient.GetGroupMembersInfo).Call(c, g.getGroupClient)
|
||||
//}
|
||||
|
||||
//func New[A, B, C, D any, E any](apiReq *A, apiResp *B, rpc func(client E, ctx context.Context, req *C, options ...grpc.CallOption) (*D, error)) {
|
||||
//
|
||||
//}
|
||||
|
@ -82,6 +82,7 @@ func NewGinRouter() *gin.Engine {
|
||||
c.Next()
|
||||
})
|
||||
{
|
||||
|
||||
groupRouterGroup.POST("/create_group", group.NewCreateGroup) //1
|
||||
groupRouterGroup.POST("/set_group_info", group.NewSetGroupInfo) //1
|
||||
groupRouterGroup.POST("/join_group", group.JoinGroup) //1
|
||||
|
49
internal/api2rpc/new1.go
Normal file
49
internal/api2rpc/new1.go
Normal file
@ -0,0 +1,49 @@
|
||||
package api2rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type FUNC[E, C, D any] func(client E, ctx context.Context, req *C, options ...grpc.CallOption) (*D, error)
|
||||
|
||||
// Call1 TEST
|
||||
func Call1[A, B, C, D, E any](
|
||||
apiReq *A,
|
||||
apiResp *B,
|
||||
rpc FUNC[E, C, D],
|
||||
//client func() (E, error),
|
||||
c *gin.Context,
|
||||
before func(apiReq *A, rpcReq *C, bind func() error) error,
|
||||
after func(rpcResp *D, apiResp *B, bind func() error) error,
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
func Call2[C, D, E any](
|
||||
rpc func(client E, ctx context.Context, req *C, options ...grpc.CallOption) (*D, error),
|
||||
client func() (E, error),
|
||||
c *gin.Context,
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
func Call3[C, D, E any](
|
||||
rpc func(client E, ctx context.Context, req *C, options ...grpc.CallOption) (*D, error),
|
||||
//client func() (E, error),
|
||||
c *gin.Context,
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
func Call4[C, D, E any](
|
||||
rpc func(client E, ctx context.Context, req *C, options ...grpc.CallOption) (*D, error),
|
||||
c *gin.Context,
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
func Call10[A, B, C, D, E any](apiReq A, apiResp B, client func() (E, error), call func(client E, rpcReq C) (D, error)) {
|
||||
|
||||
}
|
@ -9,7 +9,7 @@ import (
|
||||
|
||||
type rpcFunc[E, C, D any] func(client E, ctx context.Context, req *C, options ...grpc.CallOption) (*D, error)
|
||||
|
||||
func New[A, B, C, D any, E any](apiReq *A, apiResp *B, rpc func(client E, ctx context.Context, req *C, options ...grpc.CallOption) (*D, error)) RpcCall[A, B, C, D, E] {
|
||||
func New[A, B, C, D, E any](apiReq *A, apiResp *B, rpc func(client E, ctx context.Context, req *C, options ...grpc.CallOption) (*D, error)) RpcCall[A, B, C, D, E] {
|
||||
return &rpcCall[A, B, C, D, E]{
|
||||
apiReq: apiReq,
|
||||
apiResp: apiResp,
|
||||
|
@ -526,7 +526,8 @@ func (c *config) initConfig(config interface{}, configName, configPath string) e
|
||||
}
|
||||
|
||||
func (c *config) Register(registry discoveryregistry.SvcDiscoveryRegistry) error {
|
||||
registry
|
||||
//registry
|
||||
return nil
|
||||
}
|
||||
|
||||
func InitConfig() error {
|
||||
|
@ -9,5 +9,5 @@ type SvcDiscoveryRegistry interface {
|
||||
UnRegister() error
|
||||
GetConns(serviceName string, opts ...grpc.DialOption) ([]*grpc.ClientConn, error)
|
||||
GetConn(serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
|
||||
Re
|
||||
//Re
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func TestSliceToMap(t *testing.T) {
|
||||
func TestIndexOf(t *testing.T) {
|
||||
arr := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||
|
||||
fmt.Println(IndexOf(arr, 3))
|
||||
fmt.Println(IndexOf(3, arr...))
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user