diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 000000000..f106438e3 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,71 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ main ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ main ] + schedule: + - cron: '23 2 * * 2' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.gitignore b/.gitignore index 6913e8f09..532c7da35 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,9 @@ +bin +logs +.devcontainer components -logs \ No newline at end of file +logs +out-test +.github + + diff --git a/.gitmodules b/.gitmodules index 446b7535e..be3279250 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ -[submodule "src/Open-IM-SDK-Core"] - path = src/Open-IM-SDK-Core +[submodule "cmd/Open-IM-SDK-Core"] + path = cmd/Open-IM-SDK-Core url = https://github.com/OpenIMSDK/Open-IM-SDK-Core.git diff --git a/README.md b/README.md index 8b32d0903..ad3aa2129 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Open-IM-Server +# Open-IM-Server ![avatar](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/open-im-logo.png) @@ -154,4 +154,4 @@ All images are available at https://hub.docker.com/r/lyt1123/open_im_server ## License -Open-IM-Server is under the Apache 2.0 license. See the [LICENSE](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/LICENSE) file for details. +Open-IM-Server is under the Apache 2.0 license. See the [LICENSE](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/LICENSE) file for details diff --git a/cmd/Open-IM-SDK-Core b/cmd/Open-IM-SDK-Core new file mode 160000 index 000000000..610fc07d4 --- /dev/null +++ b/cmd/Open-IM-SDK-Core @@ -0,0 +1 @@ +Subproject commit 610fc07d46dd0ee52428bf429beb80a515e6b872 diff --git a/cmd/open_im_api/Makefile b/cmd/open_im_api/Makefile new file mode 100644 index 000000000..1f96bca5a --- /dev/null +++ b/cmd/open_im_api/Makefile @@ -0,0 +1,25 @@ +.PHONY: all build run gotool install clean help + +BINARY_NAME=open_im_api +BIN_DIR=../../bin/ + + +all: gotool build + +build: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" + +run: + @go run ./ + +gotool: + go fmt ./ + go vet ./ + +install: + make build + mv ${BINARY_NAME} ${BIN_DIR} + +clean: + @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi + diff --git a/src/api/open_im_api.go b/cmd/open_im_api/main.go similarity index 92% rename from src/api/open_im_api.go rename to cmd/open_im_api/main.go index 00cd63a3f..14c8e1e38 100644 --- a/src/api/open_im_api.go +++ b/cmd/open_im_api/main.go @@ -1,15 +1,15 @@ package main import ( - apiAuth "Open_IM/src/api/auth" - apiChat "Open_IM/src/api/chat" - "Open_IM/src/api/friend" - "Open_IM/src/api/group" - "Open_IM/src/api/manage" - apiThird "Open_IM/src/api/third" - "Open_IM/src/api/user" - "Open_IM/src/common/log" - "Open_IM/src/utils" + apiAuth "Open_IM/internal/api/auth" + apiChat "Open_IM/internal/api/chat" + "Open_IM/internal/api/friend" + "Open_IM/internal/api/group" + "Open_IM/internal/api/manage" + apiThird "Open_IM/internal/api/third" + "Open_IM/internal/api/user" + "Open_IM/pkg/common/log" + "Open_IM/pkg/utils" "flag" "github.com/gin-gonic/gin" "strconv" diff --git a/src/msg_gateway/Makefile b/cmd/open_im_msg_gateway/Makefile similarity index 81% rename from src/msg_gateway/Makefile rename to cmd/open_im_msg_gateway/Makefile index 1b6e67e9c..566d8d9c2 100644 --- a/src/msg_gateway/Makefile +++ b/cmd/open_im_msg_gateway/Makefile @@ -2,13 +2,11 @@ BINARY_NAME=open_im_msg_gateway BIN_DIR=../../bin/ -LAN_FILE=.go -GO_FILE:=${BINARY_NAME}${LAN_FILE} all: gotool build build: - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o ${BINARY_NAME} ${GO_FILE} + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" run: @go run ./ diff --git a/src/msg_gateway/open_im_msg_gateway.go b/cmd/open_im_msg_gateway/main.go similarity index 50% rename from src/msg_gateway/open_im_msg_gateway.go rename to cmd/open_im_msg_gateway/main.go index 364a7568d..196e6c005 100644 --- a/src/msg_gateway/open_im_msg_gateway.go +++ b/cmd/open_im_msg_gateway/main.go @@ -1,14 +1,14 @@ package main import ( - "Open_IM/src/msg_gateway/gate" + "Open_IM/internal/msg_gateway/gate" "flag" "sync" ) func main() { - rpcPort := flag.Int("rpc_port", 10500, "rpc listening port") - wsPort := flag.Int("ws_port", 10800, "ws listening port") + rpcPort := flag.Int("rpc_port", 10400, "rpc listening port") + wsPort := flag.Int("ws_port", 17778, "ws listening port") flag.Parse() var wg sync.WaitGroup wg.Add(1) diff --git a/src/msg_transfer/Makefile b/cmd/open_im_msg_transfer/Makefile similarity index 81% rename from src/msg_transfer/Makefile rename to cmd/open_im_msg_transfer/Makefile index 1813594d5..6a67b9bee 100644 --- a/src/msg_transfer/Makefile +++ b/cmd/open_im_msg_transfer/Makefile @@ -2,13 +2,12 @@ BINARY_NAME=open_im_msg_transfer BIN_DIR=../../bin/ -LAN_FILE=.go -GO_FILE:=${BINARY_NAME}${LAN_FILE} + all: gotool build build: - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o ${BINARY_NAME} ${GO_FILE} + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" run: @go run ./ diff --git a/src/msg_transfer/open_im_msg_transfer.go b/cmd/open_im_msg_transfer/main.go similarity index 75% rename from src/msg_transfer/open_im_msg_transfer.go rename to cmd/open_im_msg_transfer/main.go index 0a3775113..c5487de26 100644 --- a/src/msg_transfer/open_im_msg_transfer.go +++ b/cmd/open_im_msg_transfer/main.go @@ -1,7 +1,7 @@ package main import ( - "Open_IM/src/msg_transfer/logic" + "Open_IM/internal/msg_transfer/logic" "sync" ) diff --git a/src/push/Makefile b/cmd/open_im_push/Makefile similarity index 81% rename from src/push/Makefile rename to cmd/open_im_push/Makefile index 73f1fdd35..df7b9e88a 100644 --- a/src/push/Makefile +++ b/cmd/open_im_push/Makefile @@ -2,13 +2,11 @@ BINARY_NAME=open_im_push BIN_DIR=../../bin/ -LAN_FILE=.go -GO_FILE:=${BINARY_NAME}${LAN_FILE} all: gotool build build: - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o ${BINARY_NAME} ${GO_FILE} + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" run: @go run ./ diff --git a/src/push/open_im_push.go b/cmd/open_im_push/main.go similarity index 63% rename from src/push/open_im_push.go rename to cmd/open_im_push/main.go index 159ecc6cb..590793fbe 100644 --- a/src/push/open_im_push.go +++ b/cmd/open_im_push/main.go @@ -1,13 +1,13 @@ package main import ( - "Open_IM/src/push/logic" + "Open_IM/internal/push/logic" "flag" "sync" ) func main() { - rpcPort := flag.Int("port", -1, "rpc listening port") + rpcPort := flag.Int("port", 10700, "rpc listening port") flag.Parse() var wg sync.WaitGroup wg.Add(1) diff --git a/cmd/open_im_timer_task/Makefile b/cmd/open_im_timer_task/Makefile new file mode 100644 index 000000000..6c6d713d8 --- /dev/null +++ b/cmd/open_im_timer_task/Makefile @@ -0,0 +1,25 @@ +.PHONY: all build run gotool install clean help + +BINARY_NAME=open_im_timer_task +BIN_DIR=../../bin/ + +all: gotool build + +build: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" + +run: + @go run ./ + +gotool: + go fmt ./ + go vet ./ + +install: + make build + mv ${BINARY_NAME} ${BIN_DIR} + +clean: + @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi + + diff --git a/cmd/open_im_timer_task/main.go b/cmd/open_im_timer_task/main.go new file mode 100644 index 000000000..d5cf8150c --- /dev/null +++ b/cmd/open_im_timer_task/main.go @@ -0,0 +1,65 @@ +package main + +import ( + commonDB "Open_IM/pkg/common/db" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + "time" +) + +func main() { + log.NewPrivateLog("timer") + //for { + // fmt.Println("start delete mongodb expired record") + // timeUnixBegin := time.Now().Unix() + // count, _ := db.DB.MgoUserCount() + // fmt.Println("mongodb record count: ", count) + // for i := 0; i < count; i++ { + // time.Sleep(1 * time.Millisecond) + // uid, _ := db.DB.MgoSkipUID(i) + // fmt.Println("operate uid: ", uid) + // err := db.DB.DelUserChat(uid) + // if err != nil { + // fmt.Println("operate uid failed: ", uid, err.Error()) + // } + // } + // + // timeUnixEnd := time.Now().Unix() + // costTime := timeUnixEnd - timeUnixBegin + // if costTime > int64(config.Config.Mongo.DBRetainChatRecords*24*3600) { + // continue + // } else { + // sleepTime := 0 + // if int64(config.Config.Mongo.DBRetainChatRecords*24*3600)-costTime > 24*3600 { + // sleepTime = 24 * 3600 + // } else { + // sleepTime = config.Config.Mongo.DBRetainChatRecords*24*3600 - int(costTime) + // } + // fmt.Println("sleep: ", sleepTime) + // time.Sleep(time.Duration(sleepTime) * time.Second) + // } + //} + for { + uidList, err := im_mysql_model.SelectAllUID() + if err != nil { + log.NewError("999999", err.Error()) + } else { + for _, v := range uidList { + minSeq, err := commonDB.DB.GetMinSeqFromMongo(v) + if err != nil { + log.NewError("999999", "get user minSeq err", err.Error(), v) + continue + } else { + err := commonDB.DB.SetUserMinSeq(v, minSeq) + if err != nil { + log.NewError("999999", "set user minSeq err", err.Error(), v) + } + } + time.Sleep(time.Duration(100) * time.Millisecond) + } + + } + + } + +} diff --git a/cmd/rpc/open_im_auth/Makefile b/cmd/rpc/open_im_auth/Makefile new file mode 100644 index 000000000..da280c3b5 --- /dev/null +++ b/cmd/rpc/open_im_auth/Makefile @@ -0,0 +1,24 @@ +.PHONY: all build run gotool install clean help + +BINARY_NAME=open_im_auth +BIN_DIR=../../../bin/ + +all: gotool build + +build: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" + +run: + @go run ./ + +gotool: + go fmt ./ + go vet ./ + +install: + make build + mv ${BINARY_NAME} ${BIN_DIR} + +clean: + @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi + diff --git a/src/rpc/auth/open_im_auth.go b/cmd/rpc/open_im_auth/main.go similarity index 84% rename from src/rpc/auth/open_im_auth.go rename to cmd/rpc/open_im_auth/main.go index 765d83264..ed4656d35 100644 --- a/src/rpc/auth/open_im_auth.go +++ b/cmd/rpc/open_im_auth/main.go @@ -1,7 +1,7 @@ package main import ( - rpcAuth "Open_IM/src/rpc/auth/auth" + rpcAuth "Open_IM/internal/rpc/auth" "flag" ) diff --git a/cmd/rpc/open_im_friend/Makefile b/cmd/rpc/open_im_friend/Makefile new file mode 100644 index 000000000..c47cbcf1d --- /dev/null +++ b/cmd/rpc/open_im_friend/Makefile @@ -0,0 +1,25 @@ +.PHONY: all build run gotool install clean help + +BINARY_NAME=open_im_friend +BIN_DIR=../../../bin/ + +all: gotool build + +build: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" + +run: + @go run ./ + +gotool: + go fmt ./ + go vet ./ + +install: + make build + mv ${BINARY_NAME} ${BIN_DIR} + +clean: + @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi + + diff --git a/src/rpc/friend/open_im_friend.go b/cmd/rpc/open_im_friend/main.go similarity index 86% rename from src/rpc/friend/open_im_friend.go rename to cmd/rpc/open_im_friend/main.go index 088f5a7f4..0847699c5 100644 --- a/src/rpc/friend/open_im_friend.go +++ b/cmd/rpc/open_im_friend/main.go @@ -1,7 +1,7 @@ package main import ( - "Open_IM/src/rpc/friend/friend" + "Open_IM/internal/rpc/friend" "flag" ) diff --git a/cmd/rpc/open_im_group/Makefile b/cmd/rpc/open_im_group/Makefile new file mode 100644 index 000000000..e7d1cb29d --- /dev/null +++ b/cmd/rpc/open_im_group/Makefile @@ -0,0 +1,25 @@ +.PHONY: all build run gotool install clean help + +BINARY_NAME=open_im_group +BIN_DIR=../../../bin/ + +all: gotool build + +build: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" + +run: + @go run ./ + +gotool: + go fmt ./ + go vet ./ + +install: + make build + mv ${BINARY_NAME} ${BIN_DIR} + +clean: + @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi + + diff --git a/src/rpc/group/open_im_group.go b/cmd/rpc/open_im_group/main.go similarity index 87% rename from src/rpc/group/open_im_group.go rename to cmd/rpc/open_im_group/main.go index e5f1df690..8a3f886cb 100644 --- a/src/rpc/group/open_im_group.go +++ b/cmd/rpc/open_im_group/main.go @@ -1,7 +1,7 @@ package main import ( - "Open_IM/src/rpc/group/group" + "Open_IM/internal/rpc/group" "flag" ) diff --git a/src/rpc/chat/Makefile b/cmd/rpc/open_im_msg/Makefile similarity index 81% rename from src/rpc/chat/Makefile rename to cmd/rpc/open_im_msg/Makefile index 2a2d08918..7214d3fe1 100644 --- a/src/rpc/chat/Makefile +++ b/cmd/rpc/open_im_msg/Makefile @@ -2,13 +2,11 @@ BINARY_NAME=open_im_msg BIN_DIR=../../../bin/ -LAN_FILE=.go -GO_FILE:=${BINARY_NAME}${LAN_FILE} all: gotool build build: - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o ${BINARY_NAME} ${GO_FILE} + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" run: @go run ./ diff --git a/cmd/rpc/open_im_msg/main.go b/cmd/rpc/open_im_msg/main.go new file mode 100644 index 000000000..0dffe8aaa --- /dev/null +++ b/cmd/rpc/open_im_msg/main.go @@ -0,0 +1,13 @@ +package main + +import ( + rpcChat "Open_IM/internal/rpc/chat" + "flag" +) + +func main() { + rpcPort := flag.Int("port", 10300, "rpc listening port") + flag.Parse() + rpcServer := rpcChat.NewRpcChatServer(*rpcPort) + rpcServer.Run() +} diff --git a/cmd/rpc/open_im_user/Makefile b/cmd/rpc/open_im_user/Makefile new file mode 100644 index 000000000..c379db284 --- /dev/null +++ b/cmd/rpc/open_im_user/Makefile @@ -0,0 +1,25 @@ +.PHONY: all build run gotool install clean help + +BINARY_NAME=open_im_user +BIN_DIR=../../../bin/ + +all: gotool build + +build: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" + +run: + @go run ./ + +gotool: + go fmt ./ + go vet ./ + +install: + make build + mv ${BINARY_NAME} ${BIN_DIR} + +clean: + @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi + + diff --git a/src/rpc/user/open_im_user.go b/cmd/rpc/open_im_user/main.go similarity index 86% rename from src/rpc/user/open_im_user.go rename to cmd/rpc/open_im_user/main.go index 0625b11ee..91b6e55b5 100644 --- a/src/rpc/user/open_im_user.go +++ b/cmd/rpc/open_im_user/main.go @@ -1,7 +1,7 @@ package main import ( - "Open_IM/src/rpc/user/user" + "Open_IM/internal/rpc/user" "flag" ) diff --git a/config/config.yaml b/config/config.yaml index d5f27bae2..9f7969466 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -1,7 +1,7 @@ # The class cannot be named by Pascal or camel case. # If it is not used, the corresponding structure will not be set, # and it will not be read naturally. -serverversion: 1.0.0 +serverversion: 1.0.2 #---------------Infrastructure configuration---------------------# etcd: etcdSchema: openIM @@ -137,9 +137,8 @@ multiloginpolicy: #token config tokenpolicy: accessSecret: "open_im_server" - # Token effective time seconds as a unit - #Seven days 7*24*60*60 - accessExpire: 604800 + # Token effective time day as a unit + accessExpire: 7 messagecallback: callbackSwitch: false diff --git a/docker-compose.yaml b/docker-compose.yaml index a9fa9a1c9..1d64dcd9f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -15,7 +15,7 @@ services: restart: always mongodb: - image: mongo + image: mongo:4.0 ports: - 27017:27017 container_name: mongo diff --git a/go.mod b/go.mod index e8cf04b06..8efd048e6 100644 --- a/go.mod +++ b/go.mod @@ -6,18 +6,19 @@ require ( github.com/Shopify/sarama v1.19.0 github.com/Shopify/toxiproxy v2.1.4+incompatible // indirect github.com/antonfisher/nested-logrus-formatter v1.3.0 + github.com/bwmarrin/snowflake v0.3.0 github.com/coreos/go-semver v0.3.0 // indirect - github.com/dgrijalva/jwt-go v3.2.0+incompatible 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/frankban/quicktest v1.11.3 // indirect + github.com/frankban/quicktest v1.14.0 // indirect github.com/garyburd/redigo v1.6.2 github.com/gin-gonic/gin v1.7.0 github.com/go-playground/validator/v10 v10.4.1 + github.com/golang-jwt/jwt/v4 v4.1.0 github.com/golang/protobuf v1.5.2 - github.com/golang/snappy v0.0.3 // indirect + github.com/golang/snappy v0.0.4 // indirect github.com/gorilla/websocket v1.4.2 github.com/jinzhu/gorm v1.9.16 github.com/jonboulle/clockwork v0.2.2 // indirect @@ -28,19 +29,20 @@ require ( github.com/mitchellh/mapstructure v1.4.1 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 github.com/olivere/elastic/v7 v7.0.23 - github.com/pierrec/lz4 v2.6.0+incompatible // indirect + github.com/pierrec/lz4 v2.6.1+incompatible // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 - github.com/sirupsen/logrus v1.6.0 + github.com/sirupsen/logrus v1.8.1 + github.com/stretchr/testify v1.7.0 github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20210325043845-84a0811633ca github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect go.etcd.io/etcd v0.0.0-20200402134248-51bdeb39e698 golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb - golang.org/x/net v0.0.0-20201110031124-69a78807bb2b + golang.org/x/net v0.0.0-20210917221730-978cfadd31cf golang.org/x/tools v0.0.0-20210106214847-113979e3529a // indirect google.golang.org/grpc v1.33.2 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b sigs.k8s.io/yaml v1.2.0 // indirect ) diff --git a/go.sum b/go.sum index fbbe5ea96..e50dd1004 100644 --- a/go.sum +++ b/go.sum @@ -15,6 +15,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0= +github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa h1:OaNxuTZr7kxeODyLWsRMC+OD03aFUH+mW6r2d+MWa5Y= @@ -25,6 +27,7 @@ github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/coreos/go-systemd/v22 v22.0.0 h1:XJIw/+VlJ+87J+doOxznsAWIdmWuViOVhkQamW5YV28= github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -48,8 +51,8 @@ github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= -github.com/frankban/quicktest v1.11.3 h1:8sXhOn0uLys67V8EsXLc6eszDs8VXWxL3iRvebPhedY= -github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= +github.com/frankban/quicktest v1.14.0 h1:+cqqvzZV87b4adx/5ayVOaYZ2CrvM4ejQvUdBzPPUss= +github.com/frankban/quicktest v1.14.0/go.mod h1:NeW+ay9A/U67EYXNFA1nPE8e/tnQv/09mUdL/ijj8og= github.com/garyburd/redigo v1.6.2 h1:yE/pwKCrbLpLpQICzYTeZ7JsTA/C53wFTJHaEtRqniM= github.com/garyburd/redigo v1.6.2/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -74,6 +77,8 @@ github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang-jwt/jwt/v4 v4.1.0 h1:XUgk2Ex5veyVFVeLm0xhusUTQybEbexJXrvPNOKkSY0= +github.com/golang-jwt/jwt/v4 v4.1.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -94,8 +99,8 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw 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/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= -github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -103,9 +108,10 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= 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/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA= @@ -141,15 +147,16 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= -github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8= @@ -188,8 +195,8 @@ github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:v github.com/olivere/elastic/v7 v7.0.23 h1:b7tjMogDMhf2CisGI+L02LXLVa0ZyE82Z15XfW1e8t8= github.com/olivere/elastic/v7 v7.0.23/go.mod h1:OuWmD2DiuYhddWegBKPWQuelVKBLrW0fa/VUYgxuGTY= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= -github.com/pierrec/lz4 v2.6.0+incompatible h1:Ix9yFKn1nSPBLFl/yZknTp8TU5G4Ps0JDmguYK6iH1A= -github.com/pierrec/lz4 v2.6.0+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= +github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -214,10 +221,12 @@ github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnH github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= -github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/smartystreets/assertions v1.1.1/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= github.com/smartystreets/gunit v1.4.2/go.mod h1:ZjM1ozSIMJlAz/ay4SG8PeKF00ckUp+zMHZXV9/bvak= @@ -231,8 +240,9 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20210325043845-84a0811633ca h1:G/aIr3WiUesWHL2YGYgEqjM5tCAJ43Ml+0C18wDkWWs= github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20210325043845-84a0811633ca/go.mod h1:b18KQa4IxHbxeseW1GcZox53d7J0z39VNONTxvvlkXw= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= @@ -289,8 +299,9 @@ golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210917221730-978cfadd31cf h1:R150MpwJIv1MpS0N/pc+NhTM8ajzvlmxlY5OYsrevXQ= +golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -302,15 +313,20 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 h1:+DCIGbF/swA92ohVg0//6X2IVY3KZs6p9mix0ziNYJM= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -357,8 +373,9 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= diff --git a/src/api/auth/user_register.go b/internal/api/auth/user_register.go similarity index 96% rename from src/api/auth/user_register.go rename to internal/api/auth/user_register.go index b2d81218d..e0d69eeda 100644 --- a/src/api/auth/user_register.go +++ b/internal/api/auth/user_register.go @@ -1,10 +1,10 @@ package apiAuth import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbAuth "Open_IM/src/proto/auth" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbAuth "Open_IM/pkg/proto/auth" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/auth/user_token.go b/internal/api/auth/user_token.go similarity index 94% rename from src/api/auth/user_token.go rename to internal/api/auth/user_token.go index 6fcb71d9e..31839b6b0 100644 --- a/src/api/auth/user_token.go +++ b/internal/api/auth/user_token.go @@ -1,10 +1,10 @@ package apiAuth import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbAuth "Open_IM/src/proto/auth" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbAuth "Open_IM/pkg/proto/auth" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/chat/get_max_min_seq.go b/internal/api/chat/get_max_min_seq.go similarity index 91% rename from src/api/chat/get_max_min_seq.go rename to internal/api/chat/get_max_min_seq.go index 02df7ffff..06db8fd9d 100644 --- a/src/api/chat/get_max_min_seq.go +++ b/internal/api/chat/get_max_min_seq.go @@ -1,11 +1,11 @@ package apiChat import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbMsg "Open_IM/src/proto/chat" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbMsg "Open_IM/pkg/proto/chat" + "Open_IM/pkg/utils" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/chat/pull_msg.go b/internal/api/chat/pull_msg.go similarity index 96% rename from src/api/chat/pull_msg.go rename to internal/api/chat/pull_msg.go index e7a038ac6..4fb90b61f 100644 --- a/src/api/chat/pull_msg.go +++ b/internal/api/chat/pull_msg.go @@ -1,11 +1,11 @@ package apiChat import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - "Open_IM/src/proto/chat" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + "Open_IM/pkg/proto/chat" + "Open_IM/pkg/utils" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/chat/send_msg.go b/internal/api/chat/send_msg.go similarity index 95% rename from src/api/chat/send_msg.go rename to internal/api/chat/send_msg.go index 0ba888f29..6d7294109 100644 --- a/src/api/chat/send_msg.go +++ b/internal/api/chat/send_msg.go @@ -1,13 +1,13 @@ package apiChat import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - pbChat "Open_IM/src/proto/chat" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + pbChat "Open_IM/pkg/proto/chat" + "Open_IM/pkg/utils" "context" - "Open_IM/src/grpc-etcdv3/getcdv3" + "Open_IM/pkg/grpc-etcdv3/getcdv3" "github.com/gin-gonic/gin" "net/http" "strings" diff --git a/src/api/friend/add_blacklist.go b/internal/api/friend/add_blacklist.go similarity index 92% rename from src/api/friend/add_blacklist.go rename to internal/api/friend/add_blacklist.go index 1e03b53ec..e5708c659 100644 --- a/src/api/friend/add_blacklist.go +++ b/internal/api/friend/add_blacklist.go @@ -1,10 +1,10 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbFriend "Open_IM/src/proto/friend" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbFriend "Open_IM/pkg/proto/friend" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/friend/add_friend.go b/internal/api/friend/add_friend.go similarity index 96% rename from src/api/friend/add_friend.go rename to internal/api/friend/add_friend.go index d2a67cafd..e6e4632a2 100644 --- a/src/api/friend/add_friend.go +++ b/internal/api/friend/add_friend.go @@ -1,10 +1,10 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbFriend "Open_IM/src/proto/friend" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbFriend "Open_IM/pkg/proto/friend" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/friend/add_friend_response.go b/internal/api/friend/add_friend_response.go similarity index 93% rename from src/api/friend/add_friend_response.go rename to internal/api/friend/add_friend_response.go index 762daa798..c29f2181e 100644 --- a/src/api/friend/add_friend_response.go +++ b/internal/api/friend/add_friend_response.go @@ -1,10 +1,10 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbFriend "Open_IM/src/proto/friend" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbFriend "Open_IM/pkg/proto/friend" "context" "fmt" "github.com/gin-gonic/gin" diff --git a/src/api/friend/delete_friend.go b/internal/api/friend/delete_friend.go similarity index 92% rename from src/api/friend/delete_friend.go rename to internal/api/friend/delete_friend.go index 47700f423..daf81f340 100644 --- a/src/api/friend/delete_friend.go +++ b/internal/api/friend/delete_friend.go @@ -1,10 +1,10 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbFriend "Open_IM/src/proto/friend" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbFriend "Open_IM/pkg/proto/friend" "context" "fmt" "github.com/gin-gonic/gin" diff --git a/src/api/friend/get_blcaklist.go b/internal/api/friend/get_blcaklist.go similarity index 94% rename from src/api/friend/get_blcaklist.go rename to internal/api/friend/get_blcaklist.go index b1eb995dd..3b36dc107 100644 --- a/src/api/friend/get_blcaklist.go +++ b/internal/api/friend/get_blcaklist.go @@ -1,10 +1,10 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbFriend "Open_IM/src/proto/friend" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbFriend "Open_IM/pkg/proto/friend" "context" "fmt" "github.com/gin-gonic/gin" diff --git a/src/api/friend/get_friend_apply_list.go b/internal/api/friend/get_friend_apply_list.go similarity index 97% rename from src/api/friend/get_friend_apply_list.go rename to internal/api/friend/get_friend_apply_list.go index 4fb55cf50..1ace2bcac 100644 --- a/src/api/friend/get_friend_apply_list.go +++ b/internal/api/friend/get_friend_apply_list.go @@ -1,10 +1,10 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbFriend "Open_IM/src/proto/friend" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbFriend "Open_IM/pkg/proto/friend" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/friend/get_friend_list.go b/internal/api/friend/get_friend_list.go similarity index 95% rename from src/api/friend/get_friend_list.go rename to internal/api/friend/get_friend_list.go index f7813cd6c..3c87e1ced 100644 --- a/src/api/friend/get_friend_list.go +++ b/internal/api/friend/get_friend_list.go @@ -1,10 +1,10 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbFriend "Open_IM/src/proto/friend" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbFriend "Open_IM/pkg/proto/friend" "context" "fmt" "github.com/gin-gonic/gin" diff --git a/src/api/friend/get_friends_info.go b/internal/api/friend/get_friends_info.go similarity index 94% rename from src/api/friend/get_friends_info.go rename to internal/api/friend/get_friends_info.go index 21266d032..636d4db7c 100644 --- a/src/api/friend/get_friends_info.go +++ b/internal/api/friend/get_friends_info.go @@ -1,10 +1,10 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbFriend "Open_IM/src/proto/friend" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbFriend "Open_IM/pkg/proto/friend" "context" "fmt" "github.com/gin-gonic/gin" diff --git a/src/api/friend/is_friend.go b/internal/api/friend/is_friend.go similarity index 92% rename from src/api/friend/is_friend.go rename to internal/api/friend/is_friend.go index f3a7544e2..e5e51ed8d 100644 --- a/src/api/friend/is_friend.go +++ b/internal/api/friend/is_friend.go @@ -1,10 +1,10 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbFriend "Open_IM/src/proto/friend" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbFriend "Open_IM/pkg/proto/friend" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/friend/remove_blacklist.go b/internal/api/friend/remove_blacklist.go similarity index 92% rename from src/api/friend/remove_blacklist.go rename to internal/api/friend/remove_blacklist.go index c5fe87132..6952da091 100644 --- a/src/api/friend/remove_blacklist.go +++ b/internal/api/friend/remove_blacklist.go @@ -1,10 +1,10 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbFriend "Open_IM/src/proto/friend" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbFriend "Open_IM/pkg/proto/friend" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/friend/set_friend_comment.go b/internal/api/friend/set_friend_comment.go similarity index 92% rename from src/api/friend/set_friend_comment.go rename to internal/api/friend/set_friend_comment.go index 70816ddd4..77fe3411f 100644 --- a/src/api/friend/set_friend_comment.go +++ b/internal/api/friend/set_friend_comment.go @@ -1,10 +1,10 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbFriend "Open_IM/src/proto/friend" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbFriend "Open_IM/pkg/proto/friend" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/group/create_group.go b/internal/api/group/create_group.go similarity index 94% rename from src/api/group/create_group.go rename to internal/api/group/create_group.go index af606b424..564aee400 100644 --- a/src/api/group/create_group.go +++ b/internal/api/group/create_group.go @@ -1,10 +1,10 @@ package group import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pb "Open_IM/src/proto/group" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pb "Open_IM/pkg/proto/group" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/group/get_group_applicationList.go b/internal/api/group/get_group_applicationList.go similarity index 96% rename from src/api/group/get_group_applicationList.go rename to internal/api/group/get_group_applicationList.go index 5995004cf..faceb921e 100644 --- a/src/api/group/get_group_applicationList.go +++ b/internal/api/group/get_group_applicationList.go @@ -1,11 +1,11 @@ package group import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - "Open_IM/src/proto/group" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + "Open_IM/pkg/proto/group" + "Open_IM/pkg/utils" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/group/get_groups_info.go b/internal/api/group/get_groups_info.go similarity index 94% rename from src/api/group/get_groups_info.go rename to internal/api/group/get_groups_info.go index 8cf9d0fee..251cd8b09 100644 --- a/src/api/group/get_groups_info.go +++ b/internal/api/group/get_groups_info.go @@ -1,10 +1,10 @@ package group import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pb "Open_IM/src/proto/group" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pb "Open_IM/pkg/proto/group" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/group/group.go b/internal/api/group/group.go similarity index 98% rename from src/api/group/group.go rename to internal/api/group/group.go index 1ccecfe06..0fd05b3bd 100644 --- a/src/api/group/group.go +++ b/internal/api/group/group.go @@ -1,10 +1,10 @@ package group import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pb "Open_IM/src/proto/group" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pb "Open_IM/pkg/proto/group" "context" "fmt" "github.com/gin-gonic/gin" diff --git a/src/api/group/group_application_response.go b/internal/api/group/group_application_response.go similarity index 95% rename from src/api/group/group_application_response.go rename to internal/api/group/group_application_response.go index 76c6b6802..70dd966eb 100644 --- a/src/api/group/group_application_response.go +++ b/internal/api/group/group_application_response.go @@ -1,11 +1,11 @@ package group import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - "Open_IM/src/proto/group" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + "Open_IM/pkg/proto/group" + "Open_IM/pkg/utils" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/group/join_group.go b/internal/api/group/join_group.go similarity index 92% rename from src/api/group/join_group.go rename to internal/api/group/join_group.go index 08c58f0df..cc4600333 100644 --- a/src/api/group/join_group.go +++ b/internal/api/group/join_group.go @@ -1,10 +1,10 @@ package group import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pb "Open_IM/src/proto/group" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pb "Open_IM/pkg/proto/group" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/group/quit_group.go b/internal/api/group/quit_group.go similarity index 92% rename from src/api/group/quit_group.go rename to internal/api/group/quit_group.go index 06ec78686..5ee485459 100644 --- a/src/api/group/quit_group.go +++ b/internal/api/group/quit_group.go @@ -1,10 +1,10 @@ package group import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pb "Open_IM/src/proto/group" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pb "Open_IM/pkg/proto/group" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/group/set_group_info.go b/internal/api/group/set_group_info.go similarity index 93% rename from src/api/group/set_group_info.go rename to internal/api/group/set_group_info.go index dde4fc6e1..0075acc86 100644 --- a/src/api/group/set_group_info.go +++ b/internal/api/group/set_group_info.go @@ -1,10 +1,10 @@ package group import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pb "Open_IM/src/proto/group" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pb "Open_IM/pkg/proto/group" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/group/transfer_group_owner.go b/internal/api/group/transfer_group_owner.go similarity index 93% rename from src/api/group/transfer_group_owner.go rename to internal/api/group/transfer_group_owner.go index d01429ada..f7baaba3f 100644 --- a/src/api/group/transfer_group_owner.go +++ b/internal/api/group/transfer_group_owner.go @@ -1,11 +1,11 @@ package group import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - "Open_IM/src/proto/group" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + "Open_IM/pkg/proto/group" + "Open_IM/pkg/utils" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/manage/management_chat.go b/internal/api/manage/management_chat.go similarity index 97% rename from src/api/manage/management_chat.go rename to internal/api/manage/management_chat.go index 6853c172b..a398dce10 100644 --- a/src/api/manage/management_chat.go +++ b/internal/api/manage/management_chat.go @@ -7,12 +7,12 @@ package manage import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbChat "Open_IM/src/proto/chat" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbChat "Open_IM/pkg/proto/chat" + "Open_IM/pkg/utils" "context" "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" diff --git a/src/api/manage/management_user.go b/internal/api/manage/management_user.go similarity index 95% rename from src/api/manage/management_user.go rename to internal/api/manage/management_user.go index 578788c8d..79436cf04 100644 --- a/src/api/manage/management_user.go +++ b/internal/api/manage/management_user.go @@ -7,10 +7,10 @@ package manage import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbUser "Open_IM/src/proto/user" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbUser "Open_IM/pkg/proto/user" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/third/tencent_cloud_storage_credential.go b/internal/api/third/tencent_cloud_storage_credential.go similarity index 97% rename from src/api/third/tencent_cloud_storage_credential.go rename to internal/api/third/tencent_cloud_storage_credential.go index 5c6628d02..af68d8fd8 100644 --- a/src/api/third/tencent_cloud_storage_credential.go +++ b/internal/api/third/tencent_cloud_storage_credential.go @@ -1,8 +1,8 @@ package apiThird import ( - "Open_IM/src/common/config" - log2 "Open_IM/src/common/log" + "Open_IM/pkg/common/config" + log2 "Open_IM/pkg/common/log" "github.com/gin-gonic/gin" sts "github.com/tencentyun/qcloud-cos-sts-sdk/go" "net/http" diff --git a/src/api/user/get_user_info.go b/internal/api/user/get_user_info.go similarity index 94% rename from src/api/user/get_user_info.go rename to internal/api/user/get_user_info.go index 79e79e26c..ac7875356 100644 --- a/src/api/user/get_user_info.go +++ b/internal/api/user/get_user_info.go @@ -1,10 +1,10 @@ package user import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbUser "Open_IM/src/proto/user" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbUser "Open_IM/pkg/proto/user" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/api/user/update_user_info.go b/internal/api/user/update_user_info.go similarity index 94% rename from src/api/user/update_user_info.go rename to internal/api/user/update_user_info.go index 0e296452e..89628ded4 100644 --- a/src/api/user/update_user_info.go +++ b/internal/api/user/update_user_info.go @@ -1,10 +1,10 @@ package user import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbUser "Open_IM/src/proto/user" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbUser "Open_IM/pkg/proto/user" "context" "github.com/gin-gonic/gin" "net/http" diff --git a/src/msg_gateway/gate/init.go b/internal/msg_gateway/gate/init.go similarity index 88% rename from src/msg_gateway/gate/init.go rename to internal/msg_gateway/gate/init.go index 510cdaefc..03f82f3ad 100644 --- a/src/msg_gateway/gate/init.go +++ b/internal/msg_gateway/gate/init.go @@ -1,8 +1,8 @@ package gate import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" "github.com/go-playground/validator/v10" "sync" ) diff --git a/src/msg_gateway/gate/logic.go b/internal/msg_gateway/gate/logic.go similarity index 81% rename from src/msg_gateway/gate/logic.go rename to internal/msg_gateway/gate/logic.go index 15fefb5d4..9eadb529e 100644 --- a/src/msg_gateway/gate/logic.go +++ b/internal/msg_gateway/gate/logic.go @@ -1,18 +1,17 @@ package gate import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbChat "Open_IM/src/proto/chat" - pbWs "Open_IM/src/proto/sdk_ws" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbChat "Open_IM/pkg/proto/chat" + open_im_sdk "Open_IM/pkg/proto/sdk_ws" + "Open_IM/pkg/utils" "bytes" "context" "encoding/gob" "encoding/json" - "fmt" "github.com/golang/protobuf/proto" "github.com/gorilla/websocket" "runtime" @@ -44,7 +43,6 @@ func (ws *WServer) msgParse(conn *UserConn, binaryMsg []byte) { ws.sendErrMsg(conn, 201, err.Error(), m.ReqIdentifier, m.MsgIncr, m.OperationID) return } - //if !utils.VerifyToken(m.Token, m.SendID) { // ws.sendErrMsg(conn, 202, "token validate err", m.ReqIdentifier, m.MsgIncr,m.OperationID) // return @@ -63,12 +61,32 @@ func (ws *WServer) msgParse(conn *UserConn, binaryMsg []byte) { go ws.pullMsgBySeqListReq(conn, &m) default: } - log.NewInfo("", "goroutine num is ", runtime.NumGoroutine()) - +} +func (ws *WServer) getSeqReq(conn *UserConn, m *Req) { + log.NewInfo(m.OperationID, "Ws call success to getNewSeq", m.MsgIncr, m.SendID, m.ReqIdentifier) + pbData := pbChat.GetMaxAndMinSeqReq{} + nReply := new(pbChat.GetMaxAndMinSeqResp) + pbData.UserID = m.SendID + pbData.OperationID = m.OperationID + grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName) + if grpcConn == nil { + log.ErrorByKv("get grpcConn err", pbData.OperationID, "args", m) + } + msgClient := pbChat.NewChatClient(grpcConn) + reply, err := msgClient.GetMaxAndMinSeq(context.Background(), &pbData) + if err != nil { + log.ErrorByKv("rpc call failed to getSeqReq", pbData.OperationID, "err", err, "pbData", pbData.String()) + nReply.ErrCode = 200 + nReply.ErrMsg = err.Error() + ws.getSeqResp(conn, m, nReply) + } else { + log.InfoByKv("rpc call success to getSeqReq", pbData.OperationID, "replyData", reply.String()) + ws.getSeqResp(conn, m, reply) + } } func (ws *WServer) getSeqResp(conn *UserConn, m *Req, pb *pbChat.GetMaxAndMinSeqResp) { - var mReplyData pbWs.GetMaxAndMinSeqResp + var mReplyData open_im_sdk.GetMaxAndMinSeqResp mReplyData.MaxSeq = pb.GetMaxSeq() mReplyData.MinSeq = pb.GetMinSeq() b, _ := proto.Marshal(&mReplyData) @@ -82,29 +100,38 @@ func (ws *WServer) getSeqResp(conn *UserConn, m *Req, pb *pbChat.GetMaxAndMinSeq } ws.sendMsg(conn, mReply) } -func (ws *WServer) getSeqReq(conn *UserConn, m *Req) { - log.NewInfo(m.OperationID, "Ws call success to getNewSeq", m.MsgIncr, m.SendID, m.ReqIdentifier) - pbData := pbChat.GetMaxAndMinSeqReq{} - pbData.UserID = m.SendID - pbData.OperationID = m.OperationID - grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName) - if grpcConn == nil { - log.ErrorByKv("get grpcConn err", pbData.OperationID, "args", m) +func (ws *WServer) pullMsgReq(conn *UserConn, m *Req) { + log.NewInfo(m.OperationID, "Ws call success to pullMsgReq", m.ReqIdentifier, m.MsgIncr, m.SendID) + nReply := new(pbChat.PullMessageResp) + isPass, errCode, errMsg, data := ws.argsValidate(m, constant.WSPullMsg) + if isPass { + pbData := pbChat.PullMessageReq{} + pbData.UserID = m.SendID + pbData.OperationID = m.OperationID + pbData.SeqBegin = data.(SeqData).SeqBegin + pbData.SeqEnd = data.(SeqData).SeqEnd + grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName) + msgClient := pbChat.NewChatClient(grpcConn) + reply, err := msgClient.PullMessage(context.Background(), &pbData) + if err != nil { + log.ErrorByKv("PullMessage error", pbData.OperationID, "err", err.Error()) + nReply.ErrCode = 200 + nReply.ErrMsg = err.Error() + ws.pullMsgResp(conn, m, nReply) + } else { + log.InfoByKv("rpc call success to pullMsgRep", pbData.OperationID, "ReplyArgs", reply.String(), "maxSeq", reply.GetMaxSeq(), + "MinSeq", reply.GetMinSeq(), "singLen", len(reply.GetSingleUserMsg()), "groupLen", len(reply.GetGroupUserMsg())) + ws.pullMsgResp(conn, m, reply) + } + } else { + nReply.ErrCode = errCode + nReply.ErrMsg = errMsg + ws.pullMsgResp(conn, m, nReply) } - msgClient := pbChat.NewChatClient(grpcConn) - reply, err := msgClient.GetMaxAndMinSeq(context.Background(), &pbData) - if err != nil { - log.ErrorByKv("rpc call failed to getSeqReq", pbData.OperationID, "err", err, "pbData", pbData.String()) - return - } - log.InfoByKv("rpc call success to getSeqReq", pbData.OperationID, "replyData", reply.String()) - ws.getSeqResp(conn, m, reply) - } - func (ws *WServer) pullMsgResp(conn *UserConn, m *Req, pb *pbChat.PullMessageResp) { log.NewInfo(m.OperationID, "pullMsgResp come here ", pb.String()) - var mReplyData pbWs.PullMessageBySeqListResp + var mReplyData open_im_sdk.PullMessageBySeqListResp a, err := json.Marshal(pb.SingleUserMsg) if err != nil { log.NewError(m.OperationID, "GetSingleUserMsg,json marshal,err", err.Error()) @@ -139,41 +166,14 @@ func (ws *WServer) pullMsgResp(conn *UserConn, m *Req, pb *pbChat.PullMessageRes ws.sendMsg(conn, mReply) } - -func (ws *WServer) pullMsgReq(conn *UserConn, m *Req) { - log.NewInfo(m.OperationID, "Ws call success to pullMsgReq", m.ReqIdentifier, m.MsgIncr, m.SendID) - reply := new(pbChat.PullMessageResp) - isPass, errCode, errMsg, data := ws.argsValidate(m, constant.WSPullMsg) - if isPass { - pbData := pbChat.PullMessageReq{} - pbData.UserID = m.SendID - pbData.OperationID = m.OperationID - pbData.SeqBegin = data.(SeqData).SeqBegin - pbData.SeqEnd = data.(SeqData).SeqEnd - grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName) - msgClient := pbChat.NewChatClient(grpcConn) - reply, err := msgClient.PullMessage(context.Background(), &pbData) - if err != nil { - log.ErrorByKv("PullMessage error", pbData.OperationID, "err", err.Error()) - return - } - log.InfoByKv("rpc call success to pullMsgRep", pbData.OperationID, "ReplyArgs", reply.String(), "maxSeq", reply.GetMaxSeq(), - "MinSeq", reply.GetMinSeq(), "singLen", len(reply.GetSingleUserMsg()), "groupLen", len(reply.GetGroupUserMsg())) - ws.pullMsgResp(conn, m, reply) - } else { - reply.ErrCode = errCode - reply.ErrMsg = errMsg - ws.pullMsgResp(conn, m, reply) - } -} func (ws *WServer) pullMsgBySeqListReq(conn *UserConn, m *Req) { log.NewInfo(m.OperationID, "Ws call success to pullMsgBySeqListReq start", m.SendID, m.ReqIdentifier, m.MsgIncr) - reply := new(pbChat.PullMessageResp) + nReply := new(pbChat.PullMessageResp) isPass, errCode, errMsg, data := ws.argsValidate(m, constant.WSPullMsgBySeqList) - log.NewInfo(m.OperationID, "Ws call success to pullMsgBySeqListReq middle", m.SendID, m.ReqIdentifier, m.MsgIncr, data.(pbWs.PullMessageBySeqListReq).SeqList) + log.NewInfo(m.OperationID, "Ws call success to pullMsgBySeqListReq middle", m.SendID, m.ReqIdentifier, m.MsgIncr, data.(open_im_sdk.PullMessageBySeqListReq).SeqList) if isPass { pbData := pbChat.PullMessageBySeqListReq{} - pbData.SeqList = data.(pbWs.PullMessageBySeqListReq).SeqList + pbData.SeqList = data.(open_im_sdk.PullMessageBySeqListReq).SeqList pbData.UserID = m.SendID pbData.OperationID = m.OperationID grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName) @@ -181,45 +181,25 @@ func (ws *WServer) pullMsgBySeqListReq(conn *UserConn, m *Req) { reply, err := msgClient.PullMessageBySeqList(context.Background(), &pbData) if err != nil { log.NewError(pbData.OperationID, "pullMsgBySeqListReq err", err.Error()) - reply.ErrCode = 200 - reply.ErrMsg = err.Error() - + nReply.ErrCode = 200 + nReply.ErrMsg = err.Error() + ws.pullMsgResp(conn, m, nReply) } else { log.NewInfo(pbData.OperationID, "rpc call success to pullMsgBySeqListReq", reply.String(), reply.GetMaxSeq(), reply.GetMinSeq(), len(reply.GetSingleUserMsg()), len(reply.GetGroupUserMsg())) + ws.pullMsgResp(conn, m, reply) } - ws.pullMsgResp(conn, m, reply) } else { - reply.ErrCode = errCode - reply.ErrMsg = errMsg - ws.pullMsgResp(conn, m, reply) + nReply.ErrCode = errCode + nReply.ErrMsg = errMsg + ws.pullMsgResp(conn, m, nReply) } } - -func (ws *WServer) sendMsgResp(conn *UserConn, m *Req, pb *pbChat.UserSendMsgResp, sendTime int64) { - // := make(map[string]interface{}) - - var mReplyData pbWs.UserSendMsgResp - mReplyData.ClientMsgID = pb.GetClientMsgID() - mReplyData.ServerMsgID = pb.GetServerMsgID() - mReplyData.SendTime = sendTime - b, _ := proto.Marshal(&mReplyData) - mReply := Resp{ - ReqIdentifier: m.ReqIdentifier, - MsgIncr: m.MsgIncr, - ErrCode: pb.GetErrCode(), - ErrMsg: pb.GetErrMsg(), - OperationID: m.OperationID, - Data: b, - } - ws.sendMsg(conn, mReply) -} - func (ws *WServer) sendMsgReq(conn *UserConn, m *Req, sendTime int64) { log.NewInfo(m.OperationID, "Ws call success to sendMsgReq start", m.MsgIncr, m.ReqIdentifier, m.SendID, sendTime) - reply := new(pbChat.UserSendMsgResp) + nReply := new(pbChat.UserSendMsgResp) isPass, errCode, errMsg, pData := ws.argsValidate(m, constant.WSSendMsg) if isPass { - data := pData.(pbWs.UserSendMsgReq) + data := pData.(open_im_sdk.UserSendMsgReq) pbData := pbChat.UserSendMsgReq{ ReqIdentifier: m.ReqIdentifier, Token: m.Token, @@ -244,27 +224,47 @@ func (ws *WServer) sendMsgReq(conn *UserConn, m *Req, sendTime int64) { reply, err := client.UserSendMsg(context.Background(), &pbData) if err != nil { log.NewError(pbData.OperationID, "UserSendMsg err", err.Error()) - reply.ErrCode = 200 - reply.ErrMsg = err.Error() + nReply.ErrCode = 200 + nReply.ErrMsg = err.Error() + ws.sendMsgResp(conn, m, nReply, sendTime) } else { log.NewInfo(pbData.OperationID, "rpc call success to sendMsgReq", reply.String()) + ws.sendMsgResp(conn, m, reply, sendTime) } - ws.sendMsgResp(conn, m, reply, sendTime) } else { - reply.ErrCode = errCode - reply.ErrMsg = errMsg - ws.sendMsgResp(conn, m, reply, sendTime) + nReply.ErrCode = errCode + nReply.ErrMsg = errMsg + ws.sendMsgResp(conn, m, nReply, sendTime) } } +func (ws *WServer) sendMsgResp(conn *UserConn, m *Req, pb *pbChat.UserSendMsgResp, sendTime int64) { + // := make(map[string]interface{}) + + var mReplyData open_im_sdk.UserSendMsgResp + mReplyData.ClientMsgID = pb.GetClientMsgID() + mReplyData.ServerMsgID = pb.GetServerMsgID() + mReplyData.SendTime = sendTime + b, _ := proto.Marshal(&mReplyData) + mReply := Resp{ + ReqIdentifier: m.ReqIdentifier, + MsgIncr: m.MsgIncr, + ErrCode: pb.GetErrCode(), + ErrMsg: pb.GetErrMsg(), + OperationID: m.OperationID, + Data: b, + } + ws.sendMsg(conn, mReply) +} func (ws *WServer) sendMsg(conn *UserConn, mReply interface{}) { var b bytes.Buffer enc := gob.NewEncoder(&b) err := enc.Encode(mReply) if err != nil { - fmt.Println(err) + log.NewError(mReply.(Resp).OperationID, mReply.(Resp).ReqIdentifier, mReply.(Resp).ErrCode, mReply.(Resp).ErrMsg, "Encode Msg error", conn.RemoteAddr().String(), ws.getUserUid(conn), err.Error()) + return } err = ws.writeMsg(conn, websocket.BinaryMessage, b.Bytes()) if err != nil { diff --git a/src/msg_gateway/gate/rpc_server.go b/internal/msg_gateway/gate/rpc_server.go similarity index 94% rename from src/msg_gateway/gate/rpc_server.go rename to internal/msg_gateway/gate/rpc_server.go index 89f60507e..468d0f5dd 100644 --- a/src/msg_gateway/gate/rpc_server.go +++ b/internal/msg_gateway/gate/rpc_server.go @@ -1,22 +1,23 @@ package gate import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbRelay "Open_IM/src/proto/relay" - pbWs "Open_IM/src/proto/sdk_ws" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbRelay "Open_IM/pkg/proto/relay" + open_im_sdk "Open_IM/pkg/proto/sdk_ws" + "Open_IM/pkg/utils" "bytes" "context" "encoding/gob" "fmt" "github.com/golang/protobuf/proto" - "github.com/gorilla/websocket" - "google.golang.org/grpc" "net" "strings" + + "github.com/gorilla/websocket" + "google.golang.org/grpc" ) type RPCServer struct { @@ -58,7 +59,7 @@ func (r *RPCServer) MsgToUser(_ context.Context, in *pbRelay.MsgToUserReq) (*pbR log.InfoByKv("PushMsgToUser is arriving", in.OperationID, "args", in.String()) var resp []*pbRelay.SingleMsgToUser var RecvID string - msg := pbWs.MsgData{ + msg := open_im_sdk.MsgData{ SendID: in.SendID, RecvID: in.RecvID, MsgFrom: in.MsgFrom, diff --git a/src/msg_gateway/gate/validate.go b/internal/msg_gateway/gate/validate.go similarity index 94% rename from src/msg_gateway/gate/validate.go rename to internal/msg_gateway/gate/validate.go index d69d1787f..269229e9c 100644 --- a/src/msg_gateway/gate/validate.go +++ b/internal/msg_gateway/gate/validate.go @@ -7,9 +7,9 @@ package gate import ( - "Open_IM/src/common/constant" - "Open_IM/src/common/log" - pbWs "Open_IM/src/proto/sdk_ws" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/log" + open_im_sdk "Open_IM/pkg/proto/sdk_ws" "github.com/golang/protobuf/proto" ) @@ -59,7 +59,7 @@ type SeqListData struct { func (ws *WServer) argsValidate(m *Req, r int32) (isPass bool, errCode int32, errMsg string, returnData interface{}) { switch r { case constant.WSSendMsg: - data := pbWs.UserSendMsgReq{} + data := open_im_sdk.UserSendMsgReq{} if err := proto.Unmarshal(m.Data, &data); err != nil { log.ErrorByKv("Decode Data struct err", "", "err", err.Error(), "reqIdentifier", r) return false, 203, err.Error(), nil @@ -71,7 +71,7 @@ func (ws *WServer) argsValidate(m *Req, r int32) (isPass bool, errCode int32, er } return true, 0, "", data case constant.WSPullMsgBySeqList: - data := pbWs.PullMessageBySeqListReq{} + data := open_im_sdk.PullMessageBySeqListReq{} if err := proto.Unmarshal(m.Data, &data); err != nil { log.ErrorByKv("Decode Data struct err", "", "err", err.Error(), "reqIdentifier", r) return false, 203, err.Error(), nil diff --git a/src/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go similarity index 98% rename from src/msg_gateway/gate/ws_server.go rename to internal/msg_gateway/gate/ws_server.go index cc5ca6db1..8faa748a9 100644 --- a/src/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -1,9 +1,9 @@ package gate import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/utils" "github.com/gorilla/websocket" "net/http" "sync" diff --git a/src/msg_transfer/logic/db.go b/internal/msg_transfer/logic/db.go similarity index 78% rename from src/msg_transfer/logic/db.go rename to internal/msg_transfer/logic/db.go index 65eaf691e..3d6e0e3f6 100644 --- a/src/msg_transfer/logic/db.go +++ b/internal/msg_transfer/logic/db.go @@ -1,11 +1,11 @@ package logic import ( - "Open_IM/src/common/db" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbMsg "Open_IM/src/proto/chat" - "Open_IM/src/utils" + "Open_IM/pkg/common/db" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbMsg "Open_IM/pkg/proto/chat" + "Open_IM/pkg/utils" ) func saveUserChat(uid string, pbMsg *pbMsg.MsgSvrToPushSvrChatMsg) error { diff --git a/src/msg_transfer/logic/history_msg_handler.go b/internal/msg_transfer/logic/history_msg_handler.go similarity index 96% rename from src/msg_transfer/logic/history_msg_handler.go rename to internal/msg_transfer/logic/history_msg_handler.go index e6b7befdd..e3b5efb05 100644 --- a/src/msg_transfer/logic/history_msg_handler.go +++ b/internal/msg_transfer/logic/history_msg_handler.go @@ -1,14 +1,14 @@ package logic import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - kfk "Open_IM/src/common/kafka" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbMsg "Open_IM/src/proto/chat" - pbPush "Open_IM/src/proto/push" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + kfk "Open_IM/pkg/common/kafka" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbMsg "Open_IM/pkg/proto/chat" + pbPush "Open_IM/pkg/proto/push" + "Open_IM/pkg/utils" "context" "github.com/Shopify/sarama" "github.com/golang/protobuf/proto" diff --git a/src/msg_transfer/logic/init.go b/internal/msg_transfer/logic/init.go similarity index 87% rename from src/msg_transfer/logic/init.go rename to internal/msg_transfer/logic/init.go index 03a7d2c33..cce434d99 100644 --- a/src/msg_transfer/logic/init.go +++ b/internal/msg_transfer/logic/init.go @@ -1,9 +1,9 @@ package logic import ( - "Open_IM/src/common/config" - "Open_IM/src/common/kafka" - "Open_IM/src/common/log" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/kafka" + "Open_IM/pkg/common/log" ) var ( diff --git a/src/msg_transfer/logic/persistent_msg_handler.go b/internal/msg_transfer/logic/persistent_msg_handler.go similarity index 92% rename from src/msg_transfer/logic/persistent_msg_handler.go rename to internal/msg_transfer/logic/persistent_msg_handler.go index 2c7df4b7c..88039041c 100644 --- a/src/msg_transfer/logic/persistent_msg_handler.go +++ b/internal/msg_transfer/logic/persistent_msg_handler.go @@ -7,13 +7,13 @@ package logic import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/db/mysql_model/im_mysql_msg_model" - kfk "Open_IM/src/common/kafka" - "Open_IM/src/common/log" - pbMsg "Open_IM/src/proto/chat" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/db/mysql_model/im_mysql_msg_model" + kfk "Open_IM/pkg/common/kafka" + "Open_IM/pkg/common/log" + pbMsg "Open_IM/pkg/proto/chat" + "Open_IM/pkg/utils" "github.com/Shopify/sarama" "github.com/golang/protobuf/proto" "strings" diff --git a/src/push/content_struct/content.go b/internal/push/content_struct/content.go similarity index 100% rename from src/push/content_struct/content.go rename to internal/push/content_struct/content.go diff --git a/src/push/jpush/common/JGPlatform.go b/internal/push/jpush/common/JGPlatform.go similarity index 100% rename from src/push/jpush/common/JGPlatform.go rename to internal/push/jpush/common/JGPlatform.go diff --git a/src/push/jpush/push.go b/internal/push/jpush/push.go similarity index 90% rename from src/push/jpush/push.go rename to internal/push/jpush/push.go index 84140da89..b2cf95d9a 100644 --- a/src/push/jpush/push.go +++ b/internal/push/jpush/push.go @@ -1,9 +1,9 @@ package push import ( - "Open_IM/src/common/config" - "Open_IM/src/push/jpush/common" - "Open_IM/src/push/jpush/requestBody" + "Open_IM/internal/push/jpush/common" + "Open_IM/internal/push/jpush/requestBody" + "Open_IM/pkg/common/config" "bytes" "encoding/json" "io/ioutil" diff --git a/src/push/jpush/requestBody/audience.go b/internal/push/jpush/requestBody/audience.go similarity index 100% rename from src/push/jpush/requestBody/audience.go rename to internal/push/jpush/requestBody/audience.go diff --git a/src/push/jpush/requestBody/message.go b/internal/push/jpush/requestBody/message.go similarity index 100% rename from src/push/jpush/requestBody/message.go rename to internal/push/jpush/requestBody/message.go diff --git a/src/push/jpush/requestBody/notification.go b/internal/push/jpush/requestBody/notification.go similarity index 100% rename from src/push/jpush/requestBody/notification.go rename to internal/push/jpush/requestBody/notification.go diff --git a/src/push/jpush/requestBody/platform.go b/internal/push/jpush/requestBody/platform.go similarity index 98% rename from src/push/jpush/requestBody/platform.go rename to internal/push/jpush/requestBody/platform.go index 5fe33ea43..47a08fc57 100644 --- a/src/push/jpush/requestBody/platform.go +++ b/internal/push/jpush/requestBody/platform.go @@ -1,7 +1,7 @@ package requestBody import ( - "Open_IM/src/utils" + "Open_IM/pkg/utils" "errors" ) diff --git a/src/push/jpush/requestBody/pushObj.go b/internal/push/jpush/requestBody/pushObj.go similarity index 100% rename from src/push/jpush/requestBody/pushObj.go rename to internal/push/jpush/requestBody/pushObj.go diff --git a/src/push/logic/init.go b/internal/push/logic/init.go similarity index 86% rename from src/push/logic/init.go rename to internal/push/logic/init.go index eb2515caf..9fba41bdd 100644 --- a/src/push/logic/init.go +++ b/internal/push/logic/init.go @@ -7,10 +7,10 @@ package logic import ( - "Open_IM/src/common/config" - "Open_IM/src/common/kafka" - "Open_IM/src/common/log" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/kafka" + "Open_IM/pkg/common/log" + "Open_IM/pkg/utils" ) var ( diff --git a/src/push/logic/push_handler.go b/internal/push/logic/push_handler.go similarity index 93% rename from src/push/logic/push_handler.go rename to internal/push/logic/push_handler.go index 01a6115f4..22382a5b9 100644 --- a/src/push/logic/push_handler.go +++ b/internal/push/logic/push_handler.go @@ -7,11 +7,11 @@ package logic import ( - "Open_IM/src/common/config" - kfk "Open_IM/src/common/kafka" - "Open_IM/src/common/log" - pbChat "Open_IM/src/proto/chat" - pbRelay "Open_IM/src/proto/relay" + "Open_IM/pkg/common/config" + kfk "Open_IM/pkg/common/kafka" + "Open_IM/pkg/common/log" + pbChat "Open_IM/pkg/proto/chat" + pbRelay "Open_IM/pkg/proto/relay" "github.com/Shopify/sarama" "github.com/golang/protobuf/proto" ) diff --git a/src/push/logic/push_rpc_server.go b/internal/push/logic/push_rpc_server.go similarity index 92% rename from src/push/logic/push_rpc_server.go rename to internal/push/logic/push_rpc_server.go index ed128790c..ca0e93880 100644 --- a/src/push/logic/push_rpc_server.go +++ b/internal/push/logic/push_rpc_server.go @@ -1,12 +1,12 @@ package logic import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - "Open_IM/src/proto/push" - pbRelay "Open_IM/src/proto/relay" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + "Open_IM/pkg/proto/push" + pbRelay "Open_IM/pkg/proto/relay" + "Open_IM/pkg/utils" "context" "google.golang.org/grpc" "net" diff --git a/src/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go similarity index 94% rename from src/push/logic/push_to_client.go rename to internal/push/logic/push_to_client.go index 5da019c8d..8f5a004d9 100644 --- a/src/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -7,16 +7,16 @@ package logic import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbChat "Open_IM/src/proto/chat" - pbGroup "Open_IM/src/proto/group" - pbRelay "Open_IM/src/proto/relay" - push "Open_IM/src/push/jpush" - rpcChat "Open_IM/src/rpc/chat/chat" - "Open_IM/src/utils" + push "Open_IM/internal/push/jpush" + rpcChat "Open_IM/internal/rpc/chat" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbChat "Open_IM/pkg/proto/chat" + pbGroup "Open_IM/pkg/proto/group" + pbRelay "Open_IM/pkg/proto/relay" + "Open_IM/pkg/utils" "context" "encoding/json" "strings" diff --git a/src/push/logic/tpns.go b/internal/push/logic/tpns.go similarity index 75% rename from src/push/logic/tpns.go rename to internal/push/logic/tpns.go index 616c9c099..3d737f4a7 100644 --- a/src/push/logic/tpns.go +++ b/internal/push/logic/tpns.go @@ -1,11 +1,11 @@ package logic import ( - "Open_IM/src/common/config" - tpns "Open_IM/src/push/sdk/tpns-server-sdk-go/go" - "Open_IM/src/push/sdk/tpns-server-sdk-go/go/auth" - "Open_IM/src/push/sdk/tpns-server-sdk-go/go/common" - "Open_IM/src/push/sdk/tpns-server-sdk-go/go/req" + tpns "Open_IM/internal/push/sdk/tpns-server-sdk-go/go" + "Open_IM/internal/push/sdk/tpns-server-sdk-go/go/auth" + "Open_IM/internal/push/sdk/tpns-server-sdk-go/go/common" + "Open_IM/internal/push/sdk/tpns-server-sdk-go/go/req" + "Open_IM/pkg/common/config" ) var badgeType = -2 diff --git a/src/push/sdk/tpns-server-sdk-go/go/auth/auth.go b/internal/push/sdk/tpns-server-sdk-go/go/auth/auth.go similarity index 100% rename from src/push/sdk/tpns-server-sdk-go/go/auth/auth.go rename to internal/push/sdk/tpns-server-sdk-go/go/auth/auth.go diff --git a/src/push/sdk/tpns-server-sdk-go/go/client/client.go b/internal/push/sdk/tpns-server-sdk-go/go/client/client.go similarity index 100% rename from src/push/sdk/tpns-server-sdk-go/go/client/client.go rename to internal/push/sdk/tpns-server-sdk-go/go/client/client.go diff --git a/src/push/sdk/tpns-server-sdk-go/go/common/http_helper.go b/internal/push/sdk/tpns-server-sdk-go/go/common/http_helper.go similarity index 95% rename from src/push/sdk/tpns-server-sdk-go/go/common/http_helper.go rename to internal/push/sdk/tpns-server-sdk-go/go/common/http_helper.go index 31ef387ff..6c010c4f4 100644 --- a/src/push/sdk/tpns-server-sdk-go/go/common/http_helper.go +++ b/internal/push/sdk/tpns-server-sdk-go/go/common/http_helper.go @@ -1,7 +1,7 @@ package common import ( - tpns "Open_IM/src/push/sdk/tpns-server-sdk-go/go" + tpns "Open_IM/internal/push/sdk/tpns-server-sdk-go/go" "encoding/json" "fmt" "io/ioutil" diff --git a/src/push/sdk/tpns-server-sdk-go/go/common/json_helper.go b/internal/push/sdk/tpns-server-sdk-go/go/common/json_helper.go similarity index 100% rename from src/push/sdk/tpns-server-sdk-go/go/common/json_helper.go rename to internal/push/sdk/tpns-server-sdk-go/go/common/json_helper.go diff --git a/src/push/sdk/tpns-server-sdk-go/go/def.go b/internal/push/sdk/tpns-server-sdk-go/go/def.go similarity index 100% rename from src/push/sdk/tpns-server-sdk-go/go/def.go rename to internal/push/sdk/tpns-server-sdk-go/go/def.go diff --git a/src/push/sdk/tpns-server-sdk-go/go/req/req.go b/internal/push/sdk/tpns-server-sdk-go/go/req/req.go similarity index 99% rename from src/push/sdk/tpns-server-sdk-go/go/req/req.go rename to internal/push/sdk/tpns-server-sdk-go/go/req/req.go index cc4195ec7..7afc07004 100644 --- a/src/push/sdk/tpns-server-sdk-go/go/req/req.go +++ b/internal/push/sdk/tpns-server-sdk-go/go/req/req.go @@ -1,7 +1,7 @@ package req import ( - tpns "Open_IM/src/push/sdk/tpns-server-sdk-go/go" + tpns "Open_IM/internal/push/sdk/tpns-server-sdk-go/go" "bytes" "encoding/json" "io" diff --git a/src/rpc/auth/auth/rpcAuth.go b/internal/rpc/auth/rpcAuth.go similarity index 89% rename from src/rpc/auth/auth/rpcAuth.go rename to internal/rpc/auth/rpcAuth.go index 8c83a97fd..162f04fd5 100644 --- a/src/rpc/auth/auth/rpcAuth.go +++ b/internal/rpc/auth/rpcAuth.go @@ -1,12 +1,11 @@ -package rpcAuth +package auth import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - - "Open_IM/src/grpc-etcdv3/getcdv3" - pbAuth "Open_IM/src/proto/auth" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbAuth "Open_IM/pkg/proto/auth" + "Open_IM/pkg/utils" "google.golang.org/grpc" "net" "strconv" diff --git a/src/rpc/auth/auth/user_register.go b/internal/rpc/auth/user_register.go similarity index 74% rename from src/rpc/auth/auth/user_register.go rename to internal/rpc/auth/user_register.go index aa2bc40f3..5f7aa9023 100644 --- a/src/rpc/auth/auth/user_register.go +++ b/internal/rpc/auth/user_register.go @@ -1,15 +1,18 @@ -package rpcAuth +package auth import ( - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbAuth "Open_IM/src/proto/auth" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbAuth "Open_IM/pkg/proto/auth" "context" ) func (rpc *rpcAuth) UserRegister(_ context.Context, pb *pbAuth.UserRegisterReq) (*pbAuth.UserRegisterResp, error) { log.Info("", "", "rpc user_register start, [data: %s]", pb.String()) + //if len(pb.UID) == 0 { + // pb.UID = utils.GenID() + //} if err := im_mysql_model.UserRegister(pb); err != nil { log.Error("", "", "rpc user_register error, [data: %s] [err: %s]", pb.String(), err.Error()) return &pbAuth.UserRegisterResp{Success: false}, err diff --git a/src/rpc/auth/auth/user_token.go b/internal/rpc/auth/user_token.go similarity index 81% rename from src/rpc/auth/auth/user_token.go rename to internal/rpc/auth/user_token.go index 59e91c33b..6ebb2900b 100644 --- a/src/rpc/auth/auth/user_token.go +++ b/internal/rpc/auth/user_token.go @@ -1,10 +1,10 @@ -package rpcAuth +package auth import ( - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbAuth "Open_IM/src/proto/auth" - "Open_IM/src/utils" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbAuth "Open_IM/pkg/proto/auth" + "Open_IM/pkg/utils" "context" ) @@ -18,7 +18,7 @@ func (rpc *rpcAuth) UserToken(_ context.Context, pb *pbAuth.UserTokenReq) (*pbAu } log.Info("", "", "rpc user_token call..., im_mysql_model.AppServerFindFromUserByUserID") - tokens, expTime, err := utils.CreateToken(pb.UID, "", pb.Platform) + tokens, expTime, err := utils.CreateToken(pb.UID, pb.Platform) if err != nil { log.Error("", "", "rpc user_token call..., utils.CreateToken fail [uid: %s] [err: %s]", pb.UID, err.Error()) return &pbAuth.UserTokenResp{ErrCode: 500, ErrMsg: err.Error()}, err diff --git a/src/rpc/chat/chat/pull_message.go b/internal/rpc/chat/pull_message.go similarity index 97% rename from src/rpc/chat/chat/pull_message.go rename to internal/rpc/chat/pull_message.go index 7184dddd1..725725037 100644 --- a/src/rpc/chat/chat/pull_message.go +++ b/internal/rpc/chat/pull_message.go @@ -1,16 +1,16 @@ -package rpcChat +package chat import ( "context" "github.com/garyburd/redigo/redis" - commonDB "Open_IM/src/common/db" - "Open_IM/src/common/log" + commonDB "Open_IM/pkg/common/db" + "Open_IM/pkg/common/log" "sort" "strings" - pbMsg "Open_IM/src/proto/chat" + pbMsg "Open_IM/pkg/proto/chat" ) func (rpc *rpcChat) GetMaxAndMinSeq(_ context.Context, in *pbMsg.GetMaxAndMinSeqReq) (*pbMsg.GetMaxAndMinSeqResp, error) { diff --git a/src/rpc/chat/chat/rpcChat.go b/internal/rpc/chat/rpcChat.go similarity index 89% rename from src/rpc/chat/chat/rpcChat.go rename to internal/rpc/chat/rpcChat.go index d1dbad54b..e3d2460dd 100644 --- a/src/rpc/chat/chat/rpcChat.go +++ b/internal/rpc/chat/rpcChat.go @@ -1,12 +1,12 @@ -package rpcChat +package chat import ( - "Open_IM/src/common/config" - "Open_IM/src/common/kafka" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbChat "Open_IM/src/proto/chat" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/kafka" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbChat "Open_IM/pkg/proto/chat" + "Open_IM/pkg/utils" "google.golang.org/grpc" "net" "strconv" diff --git a/src/rpc/chat/chat/send_msg.go b/internal/rpc/chat/send_msg.go similarity index 95% rename from src/rpc/chat/chat/send_msg.go rename to internal/rpc/chat/send_msg.go index 5a9c47d6c..5cfc4ee71 100644 --- a/src/rpc/chat/chat/send_msg.go +++ b/internal/rpc/chat/send_msg.go @@ -1,16 +1,16 @@ -package rpcChat +package chat import ( - "Open_IM/src/api/group" - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - http2 "Open_IM/src/common/http" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbChat "Open_IM/src/proto/chat" - pbGroup "Open_IM/src/proto/group" - "Open_IM/src/push/content_struct" - "Open_IM/src/utils" + "Open_IM/internal/api/group" + "Open_IM/internal/push/content_struct" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + http2 "Open_IM/pkg/common/http" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbChat "Open_IM/pkg/proto/chat" + pbGroup "Open_IM/pkg/proto/group" + "Open_IM/pkg/utils" "context" "encoding/json" "math/rand" diff --git a/src/rpc/friend/friend/add_blacklist.go b/internal/rpc/friend/add_blacklist.go similarity index 90% rename from src/rpc/friend/friend/add_blacklist.go rename to internal/rpc/friend/add_blacklist.go index 7efe4e226..f490a2934 100644 --- a/src/rpc/friend/friend/add_blacklist.go +++ b/internal/rpc/friend/add_blacklist.go @@ -1,11 +1,11 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbFriend "Open_IM/src/proto/friend" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbFriend "Open_IM/pkg/proto/friend" + "Open_IM/pkg/utils" "context" ) diff --git a/src/rpc/friend/friend/add_friend.go b/internal/rpc/friend/add_friend.go similarity index 94% rename from src/rpc/friend/friend/add_friend.go rename to internal/rpc/friend/add_friend.go index 8b822dd29..615b05170 100644 --- a/src/rpc/friend/friend/add_friend.go +++ b/internal/rpc/friend/add_friend.go @@ -1,15 +1,15 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbChat "Open_IM/src/proto/chat" - pbFriend "Open_IM/src/proto/friend" - "Open_IM/src/push/content_struct" - "Open_IM/src/push/logic" - "Open_IM/src/utils" + "Open_IM/internal/push/content_struct" + "Open_IM/internal/push/logic" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbChat "Open_IM/pkg/proto/chat" + pbFriend "Open_IM/pkg/proto/friend" + "Open_IM/pkg/utils" "context" ) diff --git a/src/rpc/friend/friend/add_friend_response.go b/internal/rpc/friend/add_friend_response.go similarity index 92% rename from src/rpc/friend/friend/add_friend_response.go rename to internal/rpc/friend/add_friend_response.go index f372f03a6..048110a23 100644 --- a/src/rpc/friend/friend/add_friend_response.go +++ b/internal/rpc/friend/add_friend_response.go @@ -1,15 +1,15 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbChat "Open_IM/src/proto/chat" - pbFriend "Open_IM/src/proto/friend" - "Open_IM/src/push/content_struct" - "Open_IM/src/push/logic" - "Open_IM/src/utils" + "Open_IM/internal/push/content_struct" + "Open_IM/internal/push/logic" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbChat "Open_IM/pkg/proto/chat" + pbFriend "Open_IM/pkg/proto/friend" + "Open_IM/pkg/utils" "context" ) diff --git a/src/rpc/friend/friend/delete_friend.go b/internal/rpc/friend/delete_friend.go similarity index 85% rename from src/rpc/friend/friend/delete_friend.go rename to internal/rpc/friend/delete_friend.go index fba59d212..2b11988b8 100644 --- a/src/rpc/friend/friend/delete_friend.go +++ b/internal/rpc/friend/delete_friend.go @@ -1,11 +1,11 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbFriend "Open_IM/src/proto/friend" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbFriend "Open_IM/pkg/proto/friend" + "Open_IM/pkg/utils" "context" ) diff --git a/src/rpc/friend/friend/get_blacklist.go b/internal/rpc/friend/get_blacklist.go similarity index 91% rename from src/rpc/friend/friend/get_blacklist.go rename to internal/rpc/friend/get_blacklist.go index 421081b1a..99d57fb25 100644 --- a/src/rpc/friend/friend/get_blacklist.go +++ b/internal/rpc/friend/get_blacklist.go @@ -1,11 +1,11 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbFriend "Open_IM/src/proto/friend" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbFriend "Open_IM/pkg/proto/friend" + "Open_IM/pkg/utils" "context" ) diff --git a/src/rpc/friend/friend/get_firends_info.go b/internal/rpc/friend/get_firends_info.go similarity index 93% rename from src/rpc/friend/friend/get_firends_info.go rename to internal/rpc/friend/get_firends_info.go index a090a2b22..1aa34a43b 100644 --- a/src/rpc/friend/friend/get_firends_info.go +++ b/internal/rpc/friend/get_firends_info.go @@ -1,13 +1,13 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbFriend "Open_IM/src/proto/friend" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbFriend "Open_IM/pkg/proto/friend" + "Open_IM/pkg/utils" "context" "fmt" "google.golang.org/grpc" diff --git a/src/rpc/friend/friend/get_friend_apply_list.go b/internal/rpc/friend/get_friend_apply_list.go similarity index 95% rename from src/rpc/friend/friend/get_friend_apply_list.go rename to internal/rpc/friend/get_friend_apply_list.go index 5e8e15a0f..556576f71 100644 --- a/src/rpc/friend/friend/get_friend_apply_list.go +++ b/internal/rpc/friend/get_friend_apply_list.go @@ -1,11 +1,11 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbFriend "Open_IM/src/proto/friend" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbFriend "Open_IM/pkg/proto/friend" + "Open_IM/pkg/utils" "context" "fmt" "strconv" diff --git a/src/rpc/friend/friend/get_friend_list.go b/internal/rpc/friend/get_friend_list.go similarity index 90% rename from src/rpc/friend/friend/get_friend_list.go rename to internal/rpc/friend/get_friend_list.go index 92809ad7f..0674cdc53 100644 --- a/src/rpc/friend/friend/get_friend_list.go +++ b/internal/rpc/friend/get_friend_list.go @@ -1,12 +1,12 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbFriend "Open_IM/src/proto/friend" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbFriend "Open_IM/pkg/proto/friend" + "Open_IM/pkg/utils" "context" ) diff --git a/src/rpc/friend/friend/is_friend.go b/internal/rpc/friend/is_friend.go similarity index 80% rename from src/rpc/friend/friend/is_friend.go rename to internal/rpc/friend/is_friend.go index f64f3f00f..3690423e7 100644 --- a/src/rpc/friend/friend/is_friend.go +++ b/internal/rpc/friend/is_friend.go @@ -1,12 +1,12 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbFriend "Open_IM/src/proto/friend" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbFriend "Open_IM/pkg/proto/friend" + "Open_IM/pkg/utils" "context" "fmt" ) diff --git a/src/rpc/friend/friend/is_in_blacklist.go b/internal/rpc/friend/is_in_blacklist.go similarity index 82% rename from src/rpc/friend/friend/is_in_blacklist.go rename to internal/rpc/friend/is_in_blacklist.go index 3e3e8caa2..6275f5300 100644 --- a/src/rpc/friend/friend/is_in_blacklist.go +++ b/internal/rpc/friend/is_in_blacklist.go @@ -1,9 +1,9 @@ package friend import ( - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbFriend "Open_IM/src/proto/friend" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbFriend "Open_IM/pkg/proto/friend" "context" "fmt" ) diff --git a/src/rpc/friend/friend/remove_blacklist.go b/internal/rpc/friend/remove_blacklist.go similarity index 85% rename from src/rpc/friend/friend/remove_blacklist.go rename to internal/rpc/friend/remove_blacklist.go index 7d13d8a2f..af163e86d 100644 --- a/src/rpc/friend/friend/remove_blacklist.go +++ b/internal/rpc/friend/remove_blacklist.go @@ -1,11 +1,11 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbFriend "Open_IM/src/proto/friend" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbFriend "Open_IM/pkg/proto/friend" + "Open_IM/pkg/utils" "context" ) diff --git a/src/rpc/friend/friend/set_friend_comment.go b/internal/rpc/friend/set_friend_comment.go similarity index 85% rename from src/rpc/friend/friend/set_friend_comment.go rename to internal/rpc/friend/set_friend_comment.go index 66c974f47..8b7331935 100644 --- a/src/rpc/friend/friend/set_friend_comment.go +++ b/internal/rpc/friend/set_friend_comment.go @@ -1,11 +1,11 @@ package friend import ( - "Open_IM/src/common/config" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbFriend "Open_IM/src/proto/friend" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbFriend "Open_IM/pkg/proto/friend" + "Open_IM/pkg/utils" "context" ) diff --git a/src/rpc/group/group/create_group.go b/internal/rpc/group/create_group.go similarity index 93% rename from src/rpc/group/group/create_group.go rename to internal/rpc/group/create_group.go index 2d558f5d0..b95394efd 100644 --- a/src/rpc/group/group/create_group.go +++ b/internal/rpc/group/create_group.go @@ -1,17 +1,17 @@ package group import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/db" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbChat "Open_IM/src/proto/chat" - pbGroup "Open_IM/src/proto/group" - "Open_IM/src/push/content_struct" - "Open_IM/src/push/logic" - "Open_IM/src/utils" + "Open_IM/internal/push/content_struct" + "Open_IM/internal/push/logic" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/db" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbChat "Open_IM/pkg/proto/chat" + pbGroup "Open_IM/pkg/proto/group" + "Open_IM/pkg/utils" "context" "google.golang.org/grpc" "net" diff --git a/src/rpc/group/group/get_group_applicationList.go b/internal/rpc/group/get_group_applicationList.go similarity index 87% rename from src/rpc/group/group/get_group_applicationList.go rename to internal/rpc/group/get_group_applicationList.go index 72cb6e750..a08b32f8e 100644 --- a/src/rpc/group/group/get_group_applicationList.go +++ b/internal/rpc/group/get_group_applicationList.go @@ -1,9 +1,9 @@ package group import ( - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - "Open_IM/src/proto/group" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + "Open_IM/pkg/proto/group" "context" ) diff --git a/src/rpc/group/group/get_groups_info.go b/internal/rpc/group/get_groups_info.go similarity index 90% rename from src/rpc/group/group/get_groups_info.go rename to internal/rpc/group/get_groups_info.go index a7fecc773..667e3c84f 100644 --- a/src/rpc/group/group/get_groups_info.go +++ b/internal/rpc/group/get_groups_info.go @@ -1,11 +1,11 @@ package group import ( - "Open_IM/src/common/config" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbGroup "Open_IM/src/proto/group" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbGroup "Open_IM/pkg/proto/group" + "Open_IM/pkg/utils" "context" ) diff --git a/src/rpc/group/group/group.go b/internal/rpc/group/group.go similarity index 97% rename from src/rpc/group/group/group.go rename to internal/rpc/group/group.go index 87ce94da6..d7101680f 100644 --- a/src/rpc/group/group/group.go +++ b/internal/rpc/group/group.go @@ -1,18 +1,18 @@ package group import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/db" - pbChat "Open_IM/src/proto/chat" - "Open_IM/src/push/content_struct" - "Open_IM/src/push/logic" + "Open_IM/internal/push/content_struct" + "Open_IM/internal/push/logic" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/db" + pbChat "Open_IM/pkg/proto/chat" "encoding/json" - imdb "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbGroup "Open_IM/src/proto/group" - "Open_IM/src/utils" + imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbGroup "Open_IM/pkg/proto/group" + "Open_IM/pkg/utils" "context" "fmt" diff --git a/src/rpc/group/group/group_application_response.go b/internal/rpc/group/group_application_response.go similarity index 90% rename from src/rpc/group/group/group_application_response.go rename to internal/rpc/group/group_application_response.go index fc0da6306..4282de51b 100644 --- a/src/rpc/group/group/group_application_response.go +++ b/internal/rpc/group/group_application_response.go @@ -1,10 +1,10 @@ package group import ( - "Open_IM/src/common/db" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - "Open_IM/src/proto/group" + "Open_IM/pkg/common/db" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + "Open_IM/pkg/proto/group" "context" ) diff --git a/src/rpc/group/group/join_group.go b/internal/rpc/group/join_group.go similarity index 93% rename from src/rpc/group/group/join_group.go rename to internal/rpc/group/join_group.go index a3993f67d..4b1c88c89 100644 --- a/src/rpc/group/group/join_group.go +++ b/internal/rpc/group/join_group.go @@ -1,11 +1,11 @@ package group import ( - "Open_IM/src/common/config" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbGroup "Open_IM/src/proto/group" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbGroup "Open_IM/pkg/proto/group" + "Open_IM/pkg/utils" "context" ) diff --git a/src/rpc/group/group/quit_group.go b/internal/rpc/group/quit_group.go similarity index 92% rename from src/rpc/group/group/quit_group.go rename to internal/rpc/group/quit_group.go index 9d3a35448..5906832a2 100644 --- a/src/rpc/group/group/quit_group.go +++ b/internal/rpc/group/quit_group.go @@ -1,12 +1,12 @@ package group import ( - "Open_IM/src/common/config" - "Open_IM/src/common/db" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbGroup "Open_IM/src/proto/group" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/db" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbGroup "Open_IM/pkg/proto/group" + "Open_IM/pkg/utils" "context" ) diff --git a/src/rpc/group/group/set_group_info.go b/internal/rpc/group/set_group_info.go similarity index 90% rename from src/rpc/group/group/set_group_info.go rename to internal/rpc/group/set_group_info.go index cecec8445..046f8bc4f 100644 --- a/src/rpc/group/group/set_group_info.go +++ b/internal/rpc/group/set_group_info.go @@ -1,12 +1,12 @@ package group import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbGroup "Open_IM/src/proto/group" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbGroup "Open_IM/pkg/proto/group" + "Open_IM/pkg/utils" "context" ) diff --git a/src/rpc/group/group/transfer_group_owner.go b/internal/rpc/group/transfer_group_owner.go similarity index 84% rename from src/rpc/group/group/transfer_group_owner.go rename to internal/rpc/group/transfer_group_owner.go index 088241a46..4595fa1f1 100644 --- a/src/rpc/group/group/transfer_group_owner.go +++ b/internal/rpc/group/transfer_group_owner.go @@ -1,9 +1,9 @@ package group import ( - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - "Open_IM/src/proto/group" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + "Open_IM/pkg/proto/group" "context" ) diff --git a/src/rpc/user/user/get_user_info.go b/internal/rpc/user/get_user_info.go similarity index 92% rename from src/rpc/user/user/get_user_info.go rename to internal/rpc/user/get_user_info.go index f8d3e2065..3f9cec00f 100644 --- a/src/rpc/user/user/get_user_info.go +++ b/internal/rpc/user/get_user_info.go @@ -1,12 +1,12 @@ package user import ( - "Open_IM/src/common/config" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbUser "Open_IM/src/proto/user" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbUser "Open_IM/pkg/proto/user" + "Open_IM/pkg/utils" "context" "google.golang.org/grpc" "net" diff --git a/src/rpc/user/internal_service/get_user_info_to_client.go b/internal/rpc/user/internal_service/get_user_info_to_client.go similarity index 81% rename from src/rpc/user/internal_service/get_user_info_to_client.go rename to internal/rpc/user/internal_service/get_user_info_to_client.go index 8c0b93511..e7281419f 100644 --- a/src/rpc/user/internal_service/get_user_info_to_client.go +++ b/internal/rpc/user/internal_service/get_user_info_to_client.go @@ -1,9 +1,9 @@ package internal_service import ( - "Open_IM/src/common/config" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbUser "Open_IM/src/proto/user" + "Open_IM/pkg/common/config" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbUser "Open_IM/pkg/proto/user" "context" "strings" ) diff --git a/src/rpc/user/user/management_user.go b/internal/rpc/user/management_user.go similarity index 93% rename from src/rpc/user/user/management_user.go rename to internal/rpc/user/management_user.go index 7f5e10e03..f9d5b75a1 100644 --- a/src/rpc/user/user/management_user.go +++ b/internal/rpc/user/management_user.go @@ -7,11 +7,11 @@ package user import ( - "Open_IM/src/common/config" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - pbUser "Open_IM/src/proto/user" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + pbUser "Open_IM/pkg/proto/user" + "Open_IM/pkg/utils" "context" ) diff --git a/src/rpc/user/user/update_user_info.go b/internal/rpc/user/update_user_info.go similarity index 88% rename from src/rpc/user/user/update_user_info.go rename to internal/rpc/user/update_user_info.go index 9c1fc3b08..14fe9f0db 100644 --- a/src/rpc/user/user/update_user_info.go +++ b/internal/rpc/user/update_user_info.go @@ -1,16 +1,16 @@ package user import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/db/mysql_model/im_mysql_model" - "Open_IM/src/common/log" - "Open_IM/src/grpc-etcdv3/getcdv3" - pbChat "Open_IM/src/proto/chat" - pbFriend "Open_IM/src/proto/friend" - pbUser "Open_IM/src/proto/user" - "Open_IM/src/push/logic" - "Open_IM/src/utils" + "Open_IM/internal/push/logic" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/log" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbChat "Open_IM/pkg/proto/chat" + pbFriend "Open_IM/pkg/proto/friend" + pbUser "Open_IM/pkg/proto/user" + "Open_IM/pkg/utils" "context" "strings" ) diff --git a/src/timed_task/timed_task/init.go b/internal/timed_task/init.go similarity index 100% rename from src/timed_task/timed_task/init.go rename to internal/timed_task/init.go diff --git a/src/timed_task/timed_task/timed_task.go b/internal/timed_task/timed_task.go similarity index 95% rename from src/timed_task/timed_task/timed_task.go rename to internal/timed_task/timed_task.go index a2626dd6e..bda907ea7 100644 --- a/src/timed_task/timed_task/timed_task.go +++ b/internal/timed_task/timed_task.go @@ -1,7 +1,7 @@ package timed_task import ( - "Open_IM/src/common/db" + "Open_IM/pkg/common/db" "time" ) diff --git a/internal/utils/cors_middleware_test.go b/internal/utils/cors_middleware_test.go new file mode 100644 index 000000000..248cc1ca0 --- /dev/null +++ b/internal/utils/cors_middleware_test.go @@ -0,0 +1,68 @@ +package utils + +import ( + "Open_IM/pkg/utils" + "net/http" + "net/http/httptest" + "testing" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func init() { + gin.SetMode(gin.TestMode) +} + +func performRequest(r http.Handler, method, origin string) *httptest.ResponseRecorder { + return performRequestWithHeaders(r, method, origin, http.Header{}) +} + +func performRequestWithHeaders(r http.Handler, method, origin string, header http.Header) *httptest.ResponseRecorder { + req, _ := http.NewRequest(method, "/", nil) + // From go/net/http/request.go: + // For incoming requests, the Host header is promoted to the + // Request.Host field and removed from the Header map. + req.Host = header.Get("Host") + header.Del("Host") + if len(origin) > 0 { + header.Set("Origin", origin) + } + req.Header = header + w := httptest.NewRecorder() + r.ServeHTTP(w, req) + return w +} + +func newTestRouter() *gin.Engine { + router := gin.New() + router.Use(utils.CorsHandler()) + router.GET("/", func(c *gin.Context) { + c.String(http.StatusOK, "get") + }) + router.POST("/", func(c *gin.Context) { + c.String(http.StatusOK, "post") + }) + router.PATCH("/", func(c *gin.Context) { + c.String(http.StatusOK, "patch") + }) + + return router +} + +func Test_CorsHandler(t *testing.T) { + router := newTestRouter() + // no CORS request, origin == "" + w := performRequest(router, "GET", "") + assert.Equal(t, "get", w.Body.String()) + assert.Equal(t, w.Header().Get("Access-Control-Allow-Origin"), "*") + assert.Equal(t, w.Header().Get("Access-Control-Allow-Methods"), "*") + assert.Equal(t, w.Header().Get("Access-Control-Allow-Headers"), "*") + assert.Equal(t, w.Header().Get("Access-Control-Expose-Headers"), "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers,Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma,FooBar") + assert.Equal(t, w.Header().Get("Access-Control-Max-Age"), "172800") + assert.Equal(t, w.Header().Get("Access-Control-Allow-Credentials"), "false") + assert.Equal(t, w.Header().Get("content-type"), "application/json") + + w = performRequest(router, "OPTIONS", "") + assert.Equal(t, w.Body.String(), "\"Options Request!\"") +} diff --git a/src/utils/get_server_ip_test.go b/internal/utils/get_server_ip_test.go similarity index 60% rename from src/utils/get_server_ip_test.go rename to internal/utils/get_server_ip_test.go index 54e2142ef..de15537cb 100644 --- a/src/utils/get_server_ip_test.go +++ b/internal/utils/get_server_ip_test.go @@ -1,12 +1,13 @@ package utils import ( + "Open_IM/pkg/utils" "net" "testing" ) func TestServerIP(t *testing.T) { - if net.ParseIP(ServerIP) == nil { + if net.ParseIP(utils.ServerIP) == nil { t.Fail() } } diff --git a/internal/utils/id.go b/internal/utils/id.go new file mode 100644 index 000000000..509578df7 --- /dev/null +++ b/internal/utils/id.go @@ -0,0 +1,28 @@ +package utils + +import ( + "github.com/bwmarrin/snowflake" +) + +func init() { + var err error + idGenerator, err = snowflake.NewNode(getNodeNum()) + if err != nil { + panic(err) + } +} + +func getNodeNum() int64 { + return 1 +} + +var idGenerator *snowflake.Node + +func GenID() string { + return idGenerator.Generate().String() +} + +func GenIDs(count int) []string { + //impl + return []string{} +} diff --git a/internal/utils/id_test.go b/internal/utils/id_test.go new file mode 100644 index 000000000..3c0d5938e --- /dev/null +++ b/internal/utils/id_test.go @@ -0,0 +1,15 @@ +package utils + +import "testing" + +func TestGenID(t *testing.T) { + m := map[string]struct{}{} + for i := 0; i < 2000; i++ { + got := GenID() + if _, ok := m[got]; !ok { + m[got] = struct{}{} + } else { + t.Error("id generate error", got) + } + } +} diff --git a/internal/utils/image_test.go b/internal/utils/image_test.go new file mode 100644 index 000000000..ab328fbc4 --- /dev/null +++ b/internal/utils/image_test.go @@ -0,0 +1,28 @@ +package utils + +import ( + "Open_IM/pkg/utils" + "path/filepath" + "runtime" + "testing" + + "github.com/stretchr/testify/assert" +) + +var ( + _, b, _, _ = runtime.Caller(0) + // Root folder of this project + Root = filepath.Join(filepath.Dir(b), "../..") +) + +func Test_GenSmallImage(t *testing.T) { + println(Root) + err := utils.GenSmallImage(Root+"/docs/open-im-logo.png", Root+"/out-test/open-im-logo-test.png") + assert.Nil(t, err) + + err = utils.GenSmallImage(Root+"/docs/open-im-logo.png", "out-test/open-im-logo-test.png") + assert.Nil(t, err) + + err = utils.GenSmallImage(Root+"/docs/Architecture.jpg", "out-test/Architecture-test.jpg") + assert.Nil(t, err) +} diff --git a/internal/utils/jwt_token_test.go b/internal/utils/jwt_token_test.go new file mode 100644 index 000000000..5b8cdb607 --- /dev/null +++ b/internal/utils/jwt_token_test.go @@ -0,0 +1,82 @@ +package utils + +import ( + "Open_IM/pkg/common/config" + "Open_IM/pkg/utils" + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func Test_BuildClaims(t *testing.T) { + uid := "1" + platform := "PC" + ttl := int64(-1) + claim := utils.BuildClaims(uid, platform, ttl) + now := time.Now().Unix() + + assert.Equal(t, claim.UID, uid, "uid should equal") + assert.Equal(t, claim.Platform, platform, "platform should equal") + assert.Equal(t, claim.RegisteredClaims.ExpiresAt, int64(-1), "StandardClaims.ExpiresAt should be equal") + // time difference within 1s + assert.Equal(t, claim.RegisteredClaims.IssuedAt, now, "StandardClaims.IssuedAt should be equal") + assert.Equal(t, claim.RegisteredClaims.NotBefore, now, "StandardClaims.NotBefore should be equal") + + ttl = int64(60) + now = time.Now().Unix() + claim = utils.BuildClaims(uid, platform, ttl) + // time difference within 1s + assert.Equal(t, claim.RegisteredClaims.ExpiresAt, int64(60)+now, "StandardClaims.ExpiresAt should be equal") + assert.Equal(t, claim.RegisteredClaims.IssuedAt, now, "StandardClaims.IssuedAt should be equal") + assert.Equal(t, claim.RegisteredClaims.NotBefore, now, "StandardClaims.NotBefore should be equal") +} + +func Test_CreateToken(t *testing.T) { + uid := "1" + platform := int32(1) + now := time.Now().Unix() + + tokenString, expiresAt, err := utils.CreateToken(uid, platform) + + assert.NotEmpty(t, tokenString) + assert.Equal(t, expiresAt, 604800+now) + assert.Nil(t, err) +} + +func Test_VerifyToken(t *testing.T) { + uid := "1" + platform := int32(1) + tokenString, _, _ := utils.CreateToken(uid, platform) + result := utils.VerifyToken(tokenString, uid) + assert.True(t, result) + result = utils.VerifyToken(tokenString, "2") + assert.False(t, result) +} + +func Test_ParseRedisInterfaceToken(t *testing.T) { + uid := "1" + platform := int32(1) + tokenString, _, _ := utils.CreateToken(uid, platform) + + claims, err := utils.ParseRedisInterfaceToken([]uint8(tokenString)) + assert.Nil(t, err) + assert.Equal(t, claims.UID, uid) + + // timeout + config.Config.TokenPolicy.AccessExpire = -80 + tokenString, _, _ = utils.CreateToken(uid, platform) + claims, err = utils.ParseRedisInterfaceToken([]uint8(tokenString)) + assert.Equal(t, err, utils.TokenExpired) + assert.Nil(t, claims) +} + +func Test_ParseToken(t *testing.T) { + uid := "1" + platform := int32(1) + tokenString, _, _ := utils.CreateToken(uid, platform) + claims, err := utils.ParseToken(tokenString) + if err == nil { + assert.Equal(t, claims.UID, uid) + } +} diff --git a/internal/utils/md5_test.go b/internal/utils/md5_test.go new file mode 100644 index 000000000..4db7bd854 --- /dev/null +++ b/internal/utils/md5_test.go @@ -0,0 +1,16 @@ +package utils + +import ( + "Open_IM/pkg/utils" + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_Md5(t *testing.T) { + result := utils.Md5("go") + assert.Equal(t, result, "34d1f91fb2e514b8576fab1a75a89a6b") + + result2 := utils.Md5("go") + assert.Equal(t, result, result2) +} diff --git a/internal/utils/platform_number_id_to_name_test.go b/internal/utils/platform_number_id_to_name_test.go new file mode 100644 index 000000000..9fd888f44 --- /dev/null +++ b/internal/utils/platform_number_id_to_name_test.go @@ -0,0 +1,46 @@ +package utils + +import ( + "Open_IM/pkg/utils" + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_PlatformIDToName(t *testing.T) { + assert.Equal(t, utils.PlatformIDToName(1), "IOS") + assert.Equal(t, utils.PlatformIDToName(2), "Android") + assert.Equal(t, utils.PlatformIDToName(3), "Windows") + assert.Equal(t, utils.PlatformIDToName(4), "OSX") + assert.Equal(t, utils.PlatformIDToName(5), "Web") + assert.Equal(t, utils.PlatformIDToName(6), "MiniWeb") + assert.Equal(t, utils.PlatformIDToName(7), "Linux") + + assert.Equal(t, utils.PlatformIDToName(0), "") +} + +func Test_PlatformNameToID(t *testing.T) { + assert.Equal(t, utils.PlatformNameToID("IOS"), int32(1)) + assert.Equal(t, utils.PlatformNameToID("Android"), int32(2)) + assert.Equal(t, utils.PlatformNameToID("Windows"), int32(3)) + assert.Equal(t, utils.PlatformNameToID("OSX"), int32(4)) + assert.Equal(t, utils.PlatformNameToID("Web"), int32(5)) + assert.Equal(t, utils.PlatformNameToID("MiniWeb"), int32(6)) + assert.Equal(t, utils.PlatformNameToID("Linux"), int32(7)) + + assert.Equal(t, utils.PlatformNameToID("UnknownDevice"), int32(0)) + assert.Equal(t, utils.PlatformNameToID(""), int32(0)) +} + +func Test_PlatformNameToClass(t *testing.T) { + assert.Equal(t, utils.PlatformNameToClass("IOS"), "Mobile") + assert.Equal(t, utils.PlatformNameToClass("Android"), "Mobile") + assert.Equal(t, utils.PlatformNameToClass("OSX"), "PC") + assert.Equal(t, utils.PlatformNameToClass("Windows"), "PC") + assert.Equal(t, utils.PlatformNameToClass("Web"), "PC") + assert.Equal(t, utils.PlatformNameToClass("MiniWeb"), "Mobile") + assert.Equal(t, utils.PlatformNameToClass("Linux"), "PC") + + assert.Equal(t, utils.PlatformNameToClass("UnknownDevice"), "") + assert.Equal(t, utils.PlatformNameToClass(""), "") +} diff --git a/src/common/config/config.go b/pkg/common/config/config.go similarity index 93% rename from src/common/config/config.go rename to pkg/common/config/config.go index 6aa28cfd4..6f5723591 100644 --- a/src/common/config/config.go +++ b/pkg/common/config/config.go @@ -3,6 +3,14 @@ package config import ( "gopkg.in/yaml.v3" "io/ioutil" + "path/filepath" + "runtime" +) + +var ( + _, b, _, _ = runtime.Caller(0) + // Root folder of this project + Root = filepath.Join(filepath.Dir(b), "../../..") ) var Config config @@ -153,7 +161,10 @@ type config struct { func init() { //path, _ := os.Getwd() - bytes, err := ioutil.ReadFile("../config/config.yaml") + //bytes, err := ioutil.ReadFile(path + "/config/config.yaml") + // if we cd Open-IM-Server/src/utils and run go test + // it will panic cannot find config/config.yaml + bytes, err := ioutil.ReadFile(Root + "/config/config.yaml") if err != nil { panic(err) } diff --git a/src/common/config/error.go b/pkg/common/config/error.go similarity index 100% rename from src/common/config/error.go rename to pkg/common/config/error.go diff --git a/src/common/constant/constant.go b/pkg/common/constant/constant.go similarity index 100% rename from src/common/constant/constant.go rename to pkg/common/constant/constant.go diff --git a/src/common/db/model.go b/pkg/common/db/model.go similarity index 98% rename from src/common/db/model.go rename to pkg/common/db/model.go index f8be3747a..1c09a7d17 100644 --- a/src/common/db/model.go +++ b/pkg/common/db/model.go @@ -1,7 +1,7 @@ package db import ( - "Open_IM/src/common/config" + "Open_IM/pkg/common/config" "github.com/garyburd/redigo/redis" "gopkg.in/mgo.v2" "time" @@ -38,12 +38,12 @@ func init() { } DB.mgoSession = mgoSession DB.mgoSession.SetMode(mgo.Monotonic, true) - c := DB.mgoSession.DB(config.Config.Mongo.DBDatabase).C(cChat) err = c.EnsureIndexKey("uid") if err != nil { panic(err) } + // redis pool init DB.redisPool = &redis.Pool{ MaxIdle: config.Config.Redis.DBMaxIdle, diff --git a/src/common/db/mongoModel.go b/pkg/common/db/mongoModel.go similarity index 90% rename from src/common/db/mongoModel.go rename to pkg/common/db/mongoModel.go index 5742042bf..93f64ff5f 100644 --- a/src/common/db/mongoModel.go +++ b/pkg/common/db/mongoModel.go @@ -1,11 +1,12 @@ package db import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/log" - pbMsg "Open_IM/src/proto/chat" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/log" + pbMsg "Open_IM/pkg/proto/chat" "errors" + "github.com/garyburd/redigo/redis" "github.com/golang/protobuf/proto" "gopkg.in/mgo.v2/bson" "strconv" @@ -87,6 +88,34 @@ func (d *DataBases) GetMsgBySeqRange(uid string, seqBegin, seqEnd int64) (Single return SingleMsg, GroupMsg, MaxSeq, MinSeq, nil } +func (d *DataBases) GetMinSeqFromMongo(uid string) (MinSeq int64, err error) { + var i int64 + var seqUid string + session := d.mgoSession.Clone() + if session == nil { + return MinSeq, errors.New("session == nil") + } + defer session.Close() + c := session.DB(config.Config.Mongo.DBDatabase).C(cChat) + MaxSeq, err := d.GetUserMaxSeq(uid) + if err != nil && err != redis.ErrNil { + return MinSeq, err + } + NB := MaxSeq / singleGocMsgNum + for i = 0; i <= NB; i++ { + seqUid = indexGen(uid, i) + n, err := c.Find(bson.M{"uid": seqUid}).Count() + if err == nil && n != 0 { + if i == 0 { + MinSeq = 1 + } else { + MinSeq = i * singleGocMsgNum + } + break + } + } + return MinSeq, nil +} func (d *DataBases) GetMsgBySeqList(uid string, seqList []int64) (SingleMsg []*pbMsg.MsgFormat, GroupMsg []*pbMsg.MsgFormat, MaxSeq int64, MinSeq int64, err error) { allCount := 0 singleCount := 0 @@ -316,7 +345,7 @@ func getCurrentTimestampByMill() int64 { } func getSeqUid(uid string, seq int64) string { seqSuffix := seq / singleGocMsgNum - return uid + ":" + strconv.FormatInt(seqSuffix, 10) + return indexGen(uid, seqSuffix) } func isContainInt64(target int64, List []int64) bool { @@ -329,3 +358,6 @@ func isContainInt64(target int64, List []int64) bool { return false } +func indexGen(uid string, seqSuffix int64) string { + return uid + ":" + strconv.FormatInt(seqSuffix, 10) +} diff --git a/pkg/common/db/mysql.go b/pkg/common/db/mysql.go new file mode 100644 index 000000000..17370e15f --- /dev/null +++ b/pkg/common/db/mysql.go @@ -0,0 +1,217 @@ +package db + +import ( + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/log" + "fmt" + "github.com/jinzhu/gorm" + _ "github.com/jinzhu/gorm/dialects/mysql" + "sync" + "time" +) + +type mysqlDB struct { + sync.RWMutex + dbMap map[string]*gorm.DB +} + +func initMysqlDB() { + //When there is no open IM database, connect to the mysql built-in database to create openIM database + dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local", + config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], "mysql") + + db, err := gorm.Open("mysql", dsn) + if err != nil { + log.Error("", "", dsn) + panic(err) + } + + //Check the database and table during initialization + sql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s ;", config.Config.Mysql.DBDatabaseName) + err = db.Exec(sql).Error + if err != nil { + panic(err) + } + db.Close() + + dsn = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local", + config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName) + db, err = gorm.Open("mysql", dsn) + if err != nil { + panic(err) + } + + sqlTable := "CREATE TABLE IF NOT EXISTS `user` (" + + " `uid` varchar(64) NOT NULL," + + " `name` varchar(64) DEFAULT NULL," + + " `icon` varchar(1024) DEFAULT NULL," + + " `gender` tinyint(4) unsigned zerofill DEFAULT NULL," + + " `mobile` varchar(32) DEFAULT NULL," + + " `birth` varchar(16) DEFAULT NULL," + + " `email` varchar(64) DEFAULT NULL," + + " `ex` varchar(1024) DEFAULT NULL," + + " `create_time` datetime DEFAULT NULL," + + " PRIMARY KEY (`uid`)," + + " UNIQUE KEY `uk_uid` (`uid`)" + + " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;" + err = db.Exec(sqlTable).Error + if err != nil { + panic(err) + } + + sqlTable = "CREATE TABLE IF NOT EXISTS `friend` (" + + " `owner_id` varchar(64) NOT NULL," + + " `friend_id` varchar(64) NOT NULL," + + " `comment` varchar(255) DEFAULT NULL," + + " `friend_flag` int(11) NOT NULL," + + " `create_time` datetime NOT NULL," + + " PRIMARY KEY (`owner_id`,`friend_id`) USING BTREE" + + " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" + err = db.Exec(sqlTable).Error + if err != nil { + panic(err) + } + + sqlTable = "CREATE TABLE IF NOT EXISTS `friend_request` (" + + " `req_id` varchar(64) NOT NULL," + + " `user_id` varchar(64) NOT NULL," + + " `flag` int(11) NOT NULL DEFAULT '0'," + + " `req_message` varchar(255) DEFAULT NULL," + + " `create_time` datetime NOT NULL," + + " PRIMARY KEY (`user_id`,`req_id`) USING BTREE" + + " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" + err = db.Exec(sqlTable).Error + if err != nil { + panic(err) + } + + sqlTable = "CREATE TABLE IF NOT EXISTS `black_list` (" + + " `uid` varchar(32) NOT NULL COMMENT 'uid'," + + " `begin_disable_time` datetime DEFAULT NULL," + + " `end_disable_time` datetime DEFAULT NULL," + + " `ex` varchar(1024) DEFAULT NULL," + + " PRIMARY KEY (`uid`) USING BTREE" + + " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" + err = db.Exec(sqlTable).Error + if err != nil { + panic(err) + } + + sqlTable = "CREATE TABLE IF NOT EXISTS `user_black_list` (" + + " `owner_id` varchar(64) NOT NULL," + + " `block_id` varchar(64) NOT NULL," + + " `create_time` datetime NOT NULL," + + " PRIMARY KEY (`owner_id`,`block_id`) USING BTREE" + + " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" + err = db.Exec(sqlTable).Error + if err != nil { + panic(err) + } + + sqlTable = "CREATE TABLE IF NOT EXISTS `group` (" + + " `group_id` varchar(64) NOT NULL," + + " `name` varchar(255) DEFAULT NULL," + + " `introduction` varchar(255) DEFAULT NULL," + + " `notification` varchar(255) DEFAULT NULL," + + " `face_url` varchar(255) DEFAULT NULL," + + " `create_time` datetime DEFAULT NULL," + + " `ex` varchar(255) DEFAULT NULL," + + " PRIMARY KEY (`group_id`)" + + " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" + err = db.Exec(sqlTable).Error + if err != nil { + panic(err) + } + + sqlTable = "CREATE TABLE IF NOT EXISTS `group_member` (" + + " `group_id` varchar(64) NOT NULL," + + " `uid` varchar(64) NOT NULL," + + " `nickname` varchar(255) DEFAULT NULL," + + " `user_group_face_url` varchar(255) DEFAULT NULL," + + " `administrator_level` int(11) NOT NULL," + + " `join_time` datetime NOT NULL," + + " PRIMARY KEY (`group_id`,`uid`) USING BTREE" + + " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" + err = db.Exec(sqlTable).Error + if err != nil { + panic(err) + } + + sqlTable = "CREATE TABLE IF NOT EXISTS `group_request` (" + + " `id` int(11) NOT NULL AUTO_INCREMENT," + + " `group_id` varchar(64) NOT NULL," + + " `from_user_id` varchar(255) NOT NULL," + + " `to_user_id` varchar(255) NOT NULL," + + " `flag` int(10) NOT NULL DEFAULT '0'," + + " `req_msg` varchar(255) DEFAULT ''," + + " `handled_msg` varchar(255) DEFAULT ''," + + " `create_time` datetime NOT NULL," + + " `from_user_nickname` varchar(255) DEFAULT ''," + + " `to_user_nickname` varchar(255) DEFAULT NULL," + + " `from_user_face_url` varchar(255) DEFAULT ''," + + " `to_user_face_url` varchar(255) DEFAULT ''," + + " `handled_user` varchar(255) DEFAULT ''," + + " PRIMARY KEY (`id`)" + + " ) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8mb4;" + err = db.Exec(sqlTable).Error + if err != nil { + panic(err) + } + + sqlTable = "CREATE TABLE IF NOT EXISTS `chat_log` (" + + " `msg_id` varchar(128) NOT NULL," + + " `send_id` varchar(255) NOT NULL," + + " `session_type` int(11) NOT NULL," + + " `recv_id` varchar(255) NOT NULL," + + " `content_type` int(11) NOT NULL," + + " `msg_from` int(11) NOT NULL," + + " `content` varchar(1000) NOT NULL," + + " `remark` varchar(100) DEFAULT NULL," + + " `sender_platform_id` int(11) NOT NULL," + + " `send_time` datetime NOT NULL," + + " PRIMARY KEY (`msg_id`) USING BTREE" + + " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" + err = db.Exec(sqlTable).Error + if err != nil { + panic(err) + } + +} + +func (m *mysqlDB) DefaultGormDB() (*gorm.DB, error) { + return m.GormDB(config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName) +} + +func (m *mysqlDB) GormDB(dbAddress, dbName string) (*gorm.DB, error) { + m.Lock() + defer m.Unlock() + + k := key(dbAddress, dbName) + if _, ok := m.dbMap[k]; !ok { + if err := m.open(dbAddress, dbName); err != nil { + return nil, err + } + } + return m.dbMap[k], nil +} + +func (m *mysqlDB) open(dbAddress, dbName string) error { + dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local", + config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, dbAddress, dbName) + db, err := gorm.Open("mysql", dsn) + if err != nil { + return err + } + + db.SingularTable(true) + db.DB().SetMaxOpenConns(config.Config.Mysql.DBMaxOpenConns) + db.DB().SetMaxIdleConns(config.Config.Mysql.DBMaxIdleConns) + db.DB().SetConnMaxLifetime(time.Duration(config.Config.Mysql.DBMaxLifeTime) * time.Second) + + if m.dbMap == nil { + m.dbMap = make(map[string]*gorm.DB) + } + k := key(dbAddress, dbName) + m.dbMap[k] = db + return nil +} diff --git a/src/common/db/mysql_model/im_mysql_model/friend_model.go b/pkg/common/db/mysql_model/im_mysql_model/friend_model.go similarity index 98% rename from src/common/db/mysql_model/im_mysql_model/friend_model.go rename to pkg/common/db/mysql_model/im_mysql_model/friend_model.go index 5a1378465..ce029a0bb 100644 --- a/src/common/db/mysql_model/im_mysql_model/friend_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/friend_model.go @@ -1,7 +1,7 @@ package im_mysql_model import ( - "Open_IM/src/common/db" + "Open_IM/pkg/common/db" _ "github.com/jinzhu/gorm/dialects/mysql" "time" ) diff --git a/src/common/db/mysql_model/im_mysql_model/friend_request_model.go b/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go similarity index 98% rename from src/common/db/mysql_model/im_mysql_model/friend_request_model.go rename to pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go index 5125b62bd..1a7308cb9 100644 --- a/src/common/db/mysql_model/im_mysql_model/friend_request_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go @@ -1,7 +1,7 @@ package im_mysql_model import ( - "Open_IM/src/common/db" + "Open_IM/pkg/common/db" "time" ) diff --git a/src/common/db/mysql_model/im_mysql_model/group_member_model.go b/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go similarity index 99% rename from src/common/db/mysql_model/im_mysql_model/group_member_model.go rename to pkg/common/db/mysql_model/im_mysql_model/group_member_model.go index 19a3cd2c4..60ad86e85 100644 --- a/src/common/db/mysql_model/im_mysql_model/group_member_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go @@ -1,7 +1,7 @@ package im_mysql_model import ( - "Open_IM/src/common/db" + "Open_IM/pkg/common/db" "time" ) diff --git a/src/common/db/mysql_model/im_mysql_model/group_model.go b/pkg/common/db/mysql_model/im_mysql_model/group_model.go similarity index 99% rename from src/common/db/mysql_model/im_mysql_model/group_model.go rename to pkg/common/db/mysql_model/im_mysql_model/group_model.go index 85eab55f2..2988741e5 100644 --- a/src/common/db/mysql_model/im_mysql_model/group_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/group_model.go @@ -1,9 +1,9 @@ package im_mysql_model import ( - "Open_IM/src/common/db" - "Open_IM/src/common/log" - "Open_IM/src/proto/group" + "Open_IM/pkg/common/db" + "Open_IM/pkg/common/log" + "Open_IM/pkg/proto/group" "errors" "time" ) diff --git a/src/common/db/mysql_model/im_mysql_model/group_request_model.go b/pkg/common/db/mysql_model/im_mysql_model/group_request_model.go similarity index 98% rename from src/common/db/mysql_model/im_mysql_model/group_request_model.go rename to pkg/common/db/mysql_model/im_mysql_model/group_request_model.go index 6451ed863..da793d331 100644 --- a/src/common/db/mysql_model/im_mysql_model/group_request_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/group_request_model.go @@ -1,7 +1,7 @@ package im_mysql_model import ( - "Open_IM/src/common/db" + "Open_IM/pkg/common/db" "time" ) diff --git a/src/common/db/mysql_model/im_mysql_model/model_struct.go b/pkg/common/db/mysql_model/im_mysql_model/model_struct.go similarity index 97% rename from src/common/db/mysql_model/im_mysql_model/model_struct.go rename to pkg/common/db/mysql_model/im_mysql_model/model_struct.go index 87993df65..d8576ac19 100644 --- a/src/common/db/mysql_model/im_mysql_model/model_struct.go +++ b/pkg/common/db/mysql_model/im_mysql_model/model_struct.go @@ -3,7 +3,7 @@ package im_mysql_model import "time" type User struct { - UID string `gorm:"column:uid"` + UID string `gorm:"column:uid;primaryKey;"` Name string `gorm:"column:name"` Icon string `gorm:"column:icon"` Gender int32 `gorm:"column:gender"` diff --git a/src/common/db/mysql_model/im_mysql_model/user_black_list_model.go b/pkg/common/db/mysql_model/im_mysql_model/user_black_list_model.go similarity index 98% rename from src/common/db/mysql_model/im_mysql_model/user_black_list_model.go rename to pkg/common/db/mysql_model/im_mysql_model/user_black_list_model.go index 9d2e54f9d..907b0f223 100644 --- a/src/common/db/mysql_model/im_mysql_model/user_black_list_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/user_black_list_model.go @@ -1,7 +1,7 @@ package im_mysql_model import ( - "Open_IM/src/common/db" + "Open_IM/pkg/common/db" "time" ) diff --git a/src/common/db/mysql_model/im_mysql_model/user_model.go b/pkg/common/db/mysql_model/im_mysql_model/user_model.go similarity index 96% rename from src/common/db/mysql_model/im_mysql_model/user_model.go rename to pkg/common/db/mysql_model/im_mysql_model/user_model.go index ddefc8554..f378fdbb5 100644 --- a/src/common/db/mysql_model/im_mysql_model/user_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/user_model.go @@ -1,10 +1,10 @@ package im_mysql_model import ( - "Open_IM/src/common/config" - "Open_IM/src/common/db" - pbAuth "Open_IM/src/proto/auth" - "Open_IM/src/utils" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/db" + pbAuth "Open_IM/pkg/proto/auth" + "Open_IM/pkg/utils" "fmt" _ "github.com/jinzhu/gorm/dialects/mysql" "time" diff --git a/src/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go b/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go similarity index 95% rename from src/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go rename to pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go index 58a02e751..73defd89d 100644 --- a/src/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go +++ b/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go @@ -7,9 +7,9 @@ package im_mysql_msg_model import ( - "Open_IM/src/common/db" - pbMsg "Open_IM/src/proto/chat" - "Open_IM/src/utils" + "Open_IM/pkg/common/db" + pbMsg "Open_IM/pkg/proto/chat" + "Open_IM/pkg/utils" "database/sql" "time" ) diff --git a/src/common/db/mysql_model/im_mysql_msg_model/hash_code.go b/pkg/common/db/mysql_model/im_mysql_msg_model/hash_code.go similarity index 94% rename from src/common/db/mysql_model/im_mysql_msg_model/hash_code.go rename to pkg/common/db/mysql_model/im_mysql_msg_model/hash_code.go index b349e7787..a631462ce 100644 --- a/src/common/db/mysql_model/im_mysql_msg_model/hash_code.go +++ b/pkg/common/db/mysql_model/im_mysql_msg_model/hash_code.go @@ -1,8 +1,8 @@ package im_mysql_msg_model import ( - "Open_IM/src/common/config" - "Open_IM/src/common/db" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/db" "hash/crc32" "strconv" ) diff --git a/src/common/db/mysql_model/im_mysql_msg_model/receive_model.go b/pkg/common/db/mysql_model/im_mysql_msg_model/receive_model.go similarity index 100% rename from src/common/db/mysql_model/im_mysql_msg_model/receive_model.go rename to pkg/common/db/mysql_model/im_mysql_msg_model/receive_model.go diff --git a/src/common/db/redisModel.go b/pkg/common/db/redisModel.go similarity index 81% rename from src/common/db/redisModel.go rename to pkg/common/db/redisModel.go index 385165687..b31fde8c1 100644 --- a/src/common/db/redisModel.go +++ b/pkg/common/db/redisModel.go @@ -1,7 +1,7 @@ package db import ( - log2 "Open_IM/src/common/log" + log2 "Open_IM/pkg/common/log" "github.com/garyburd/redigo/redis" ) @@ -9,7 +9,7 @@ const ( userIncrSeq = "REDIS_USER_INCR_SEQ:" // user incr seq appleDeviceToken = "DEVICE_TOKEN" lastGetSeq = "LAST_GET_SEQ" - userMinSeq = "REDIS_USER_Min_SEQ:" + userMinSeq = "REDIS_USER_MIN_SEQ:" ) func (d *DataBases) Exec(cmd string, key interface{}, args ...interface{}) (interface{}, error) { @@ -32,55 +32,55 @@ func (d *DataBases) Exec(cmd string, key interface{}, args ...interface{}) (inte return con.Do(cmd, params...) } -//执行用户消息的seq自增操作 +//Perform seq auto-increment operation of user messages func (d *DataBases) IncrUserSeq(uid string) (int64, error) { key := userIncrSeq + uid return redis.Int64(d.Exec("INCR", key)) } -//获取最大的Seq +//Get the largest Seq func (d *DataBases) GetUserMaxSeq(uid string) (int64, error) { key := userIncrSeq + uid return redis.Int64(d.Exec("GET", key)) } -//设置用户最小的seq -func (d *DataBases) SetUserMinSeq(uid string) (err error) { +//Set the user's minimum seq +func (d *DataBases) SetUserMinSeq(uid string, minSeq int64) (err error) { key := userMinSeq + uid - _, err = d.Exec("SET", key) + _, err = d.Exec("SET", key, minSeq) return err } -//获取最小的Seq +//Get the smallest Seq func (d *DataBases) GetUserMinSeq(uid string) (int64, error) { key := userMinSeq + uid return redis.Int64(d.Exec("GET", key)) } -//存储苹果的设备token到redis +//Store Apple's device token to redis func (d *DataBases) SetAppleDeviceToken(accountAddress, value string) (err error) { key := appleDeviceToken + accountAddress _, err = d.Exec("SET", key, value) return err } -//删除苹果设备token +//Delete Apple device token func (d *DataBases) DelAppleDeviceToken(accountAddress string) (err error) { key := appleDeviceToken + accountAddress _, err = d.Exec("DEL", key) return err } -//记录用户上一次主动拉取Seq的值 +//Record the last time the user actively pulled the value of Seq func (d *DataBases) SetLastGetSeq(uid string) (err error) { key := lastGetSeq + uid _, err = d.Exec("SET", key) return err } -//获取用户上一次主动拉取Seq的值 +//Get the value of the user's last active pull Seq func (d *DataBases) GetLastGetSeq(uid string) (int64, error) { - key := userIncrSeq + uid + key := lastGetSeq + uid return redis.Int64(d.Exec("GET", key)) } diff --git a/src/common/http/http_client.go b/pkg/common/http/http_client.go similarity index 100% rename from src/common/http/http_client.go rename to pkg/common/http/http_client.go diff --git a/src/common/kafka/consumer.go b/pkg/common/kafka/consumer.go similarity index 100% rename from src/common/kafka/consumer.go rename to pkg/common/kafka/consumer.go diff --git a/src/common/kafka/consumer_group.go b/pkg/common/kafka/consumer_group.go similarity index 100% rename from src/common/kafka/consumer_group.go rename to pkg/common/kafka/consumer_group.go diff --git a/src/common/kafka/producer.go b/pkg/common/kafka/producer.go similarity index 97% rename from src/common/kafka/producer.go rename to pkg/common/kafka/producer.go index 2d9299b60..c82df975f 100644 --- a/src/common/kafka/producer.go +++ b/pkg/common/kafka/producer.go @@ -1,7 +1,7 @@ package kafka import ( - log2 "Open_IM/src/common/log" + log2 "Open_IM/pkg/common/log" "github.com/Shopify/sarama" "github.com/golang/protobuf/proto" ) diff --git a/src/common/log/es_hk.go b/pkg/common/log/es_hk.go similarity index 95% rename from src/common/log/es_hk.go rename to pkg/common/log/es_hk.go index c54130968..061773e5d 100644 --- a/src/common/log/es_hk.go +++ b/pkg/common/log/es_hk.go @@ -1,5 +1,5 @@ /* -** description("将日志发送到elasticsearch的hook"). +** description("Send logs to elasticsearch hook"). ** copyright('tuoyun,www.tuoyun.net'). ** author("fg,Gordon@tuoyun.net"). ** time(2021/3/26 17:05). @@ -7,7 +7,7 @@ package log import ( - "Open_IM/src/common/config" + "Open_IM/pkg/common/config" "context" "fmt" elasticV7 "github.com/olivere/elastic/v7" @@ -18,13 +18,13 @@ import ( "time" ) -//esHook 自定义的ES hook +//esHook CUSTOMIZED ES hook type esHook struct { moduleName string client *elasticV7.Client } -//newEsHook 初始化 +//newEsHook Initialization func newEsHook(moduleName string) *esHook { //https://github.com/sohlich/elogrus //client, err := elastic.NewClient(elastic.SetURL("http://localhost:9200")) diff --git a/src/common/log/file_line_hk.go b/pkg/common/log/file_line_hk.go similarity index 92% rename from src/common/log/file_line_hk.go rename to pkg/common/log/file_line_hk.go index e6b690eb7..7eeb6ea82 100644 --- a/src/common/log/file_line_hk.go +++ b/pkg/common/log/file_line_hk.go @@ -1,5 +1,5 @@ /* -** description("得到调用文件名字和行号的hook"). +** description("get the name and line number of the calling file hook"). ** copyright('tuoyun,www.tuoyun.net'). ** author("fg,Gordon@tuoyun.net"). ** time(2021/3/16 11:26). diff --git a/src/common/log/logrus.go b/pkg/common/log/logrus.go similarity index 99% rename from src/common/log/logrus.go rename to pkg/common/log/logrus.go index 22720c618..b88a6f6d3 100644 --- a/src/common/log/logrus.go +++ b/pkg/common/log/logrus.go @@ -1,7 +1,7 @@ package log import ( - "Open_IM/src/common/config" + "Open_IM/pkg/common/config" "bufio" "fmt" nested "github.com/antonfisher/nested-logrus-formatter" diff --git a/src/common/log/time_format.go b/pkg/common/log/time_format.go similarity index 76% rename from src/common/log/time_format.go rename to pkg/common/log/time_format.go index 4ae1c56ef..e1bfc4a8c 100644 --- a/src/common/log/time_format.go +++ b/pkg/common/log/time_format.go @@ -12,34 +12,34 @@ import ( ) const ( - TimeOffset = 8 * 3600 //8个小时的偏移量 - HalfOffset = 12 * 3600 //半天的小时偏移量 + TimeOffset = 8 * 3600 //8 hour offset + HalfOffset = 12 * 3600 //Half-day hourly offset ) -//获取当前的时间戳 +//Get the current timestamp func GetCurrentTimestamp() int64 { return time.Now().Unix() } -//获取当天0点的时间戳 +//Get the current 0 o'clock timestamp func GetCurDayZeroTimestamp() int64 { timeStr := time.Now().Format("2006-01-02") t, _ := time.Parse("2006-01-02", timeStr) return t.Unix() - TimeOffset } -//获取当天12点的时间戳 +//Get the timestamp at 12 o'clock on the day func GetCurDayHalfTimestamp() int64 { return GetCurDayZeroTimestamp() + HalfOffset } -//获取当天0点格式化时间,格式为"2006-01-02_00-00-00" +//Get the formatted time at 0 o'clock of the day, the format is "2006-01-02_00-00-00" func GetCurDayZeroTimeFormat() string { return time.Unix(GetCurDayZeroTimestamp(), 0).Format("2006-01-02_15-04-05") } -//获取当天12点格式化时间,格式为"2006-01-02_12-00-00" +//Get the formatted time at 12 o'clock of the day, the format is "2006-01-02_12-00-00" func GetCurDayHalfTimeFormat() string { return time.Unix(GetCurDayZeroTimestamp()+HalfOffset, 0).Format("2006-01-02_15-04-05") } diff --git a/src/common/multi_terminal_login/multi_terminal_login.go b/pkg/common/multi_terminal_login/multi_terminal_login.go similarity index 91% rename from src/common/multi_terminal_login/multi_terminal_login.go rename to pkg/common/multi_terminal_login/multi_terminal_login.go index 8da527274..ba0c0525c 100644 --- a/src/common/multi_terminal_login/multi_terminal_login.go +++ b/pkg/common/multi_terminal_login/multi_terminal_login.go @@ -1,13 +1,13 @@ package multi_terminal_login import ( - "Open_IM/src/common/config" - "Open_IM/src/common/constant" - "Open_IM/src/common/db" - pbChat "Open_IM/src/proto/chat" - "Open_IM/src/push/content_struct" - "Open_IM/src/push/logic" - "Open_IM/src/utils" + "Open_IM/internal/push/content_struct" + "Open_IM/internal/push/logic" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/db" + pbChat "Open_IM/pkg/proto/chat" + "Open_IM/pkg/utils" ) func MultiTerminalLoginChecker(uid, token string, platformID int32) error { diff --git a/src/grpc-etcdv3/getcdv3/pool.go b/pkg/grpc-etcdv3/getcdv3/pool.go similarity index 100% rename from src/grpc-etcdv3/getcdv3/pool.go rename to pkg/grpc-etcdv3/getcdv3/pool.go diff --git a/src/grpc-etcdv3/getcdv3/register.go b/pkg/grpc-etcdv3/getcdv3/register.go similarity index 100% rename from src/grpc-etcdv3/getcdv3/register.go rename to pkg/grpc-etcdv3/getcdv3/register.go diff --git a/src/grpc-etcdv3/getcdv3/resolver.go b/pkg/grpc-etcdv3/getcdv3/resolver.go similarity index 100% rename from src/grpc-etcdv3/getcdv3/resolver.go rename to pkg/grpc-etcdv3/getcdv3/resolver.go diff --git a/src/proto/auth/auth.pb.go b/pkg/proto/auth/auth.pb.go similarity index 100% rename from src/proto/auth/auth.pb.go rename to pkg/proto/auth/auth.pb.go diff --git a/src/proto/auth/auth.proto b/pkg/proto/auth/auth.proto similarity index 100% rename from src/proto/auth/auth.proto rename to pkg/proto/auth/auth.proto diff --git a/src/proto/auto_proto.sh b/pkg/proto/auto_proto.sh similarity index 100% rename from src/proto/auto_proto.sh rename to pkg/proto/auto_proto.sh diff --git a/src/proto/chat/chat.pb.go b/pkg/proto/chat/chat.pb.go similarity index 100% rename from src/proto/chat/chat.pb.go rename to pkg/proto/chat/chat.pb.go diff --git a/src/proto/chat/chat.proto b/pkg/proto/chat/chat.proto similarity index 100% rename from src/proto/chat/chat.proto rename to pkg/proto/chat/chat.proto diff --git a/src/proto/friend/friend.pb.go b/pkg/proto/friend/friend.pb.go similarity index 100% rename from src/proto/friend/friend.pb.go rename to pkg/proto/friend/friend.pb.go diff --git a/src/proto/friend/friend.proto b/pkg/proto/friend/friend.proto similarity index 100% rename from src/proto/friend/friend.proto rename to pkg/proto/friend/friend.proto diff --git a/src/proto/group/group.pb.go b/pkg/proto/group/group.pb.go similarity index 100% rename from src/proto/group/group.pb.go rename to pkg/proto/group/group.pb.go diff --git a/src/proto/group/group.proto b/pkg/proto/group/group.proto similarity index 100% rename from src/proto/group/group.proto rename to pkg/proto/group/group.proto diff --git a/src/proto/proto_dir.cfg b/pkg/proto/proto_dir.cfg similarity index 100% rename from src/proto/proto_dir.cfg rename to pkg/proto/proto_dir.cfg diff --git a/src/proto/push/push.pb.go b/pkg/proto/push/push.pb.go similarity index 100% rename from src/proto/push/push.pb.go rename to pkg/proto/push/push.pb.go diff --git a/src/proto/push/push.proto b/pkg/proto/push/push.proto similarity index 100% rename from src/proto/push/push.proto rename to pkg/proto/push/push.proto diff --git a/src/proto/relay/relay.pb.go b/pkg/proto/relay/relay.pb.go similarity index 100% rename from src/proto/relay/relay.pb.go rename to pkg/proto/relay/relay.pb.go diff --git a/src/proto/relay/relay.proto b/pkg/proto/relay/relay.proto similarity index 100% rename from src/proto/relay/relay.proto rename to pkg/proto/relay/relay.proto diff --git a/src/proto/sdk_ws/ws.pb.go b/pkg/proto/sdk_ws/ws.pb.go similarity index 100% rename from src/proto/sdk_ws/ws.pb.go rename to pkg/proto/sdk_ws/ws.pb.go diff --git a/src/proto/sdk_ws/ws.proto b/pkg/proto/sdk_ws/ws.proto similarity index 100% rename from src/proto/sdk_ws/ws.proto rename to pkg/proto/sdk_ws/ws.proto diff --git a/src/proto/user/user.pb.go b/pkg/proto/user/user.pb.go similarity index 100% rename from src/proto/user/user.pb.go rename to pkg/proto/user/user.pb.go diff --git a/src/proto/user/user.proto b/pkg/proto/user/user.proto similarity index 100% rename from src/proto/user/user.proto rename to pkg/proto/user/user.proto diff --git a/src/utils/cors_middleware.go b/pkg/utils/cors_middleware.go similarity index 99% rename from src/utils/cors_middleware.go rename to pkg/utils/cors_middleware.go index 1d75c4ead..6809d786d 100644 --- a/src/utils/cors_middleware.go +++ b/pkg/utils/cors_middleware.go @@ -1,8 +1,9 @@ package utils import ( - "github.com/gin-gonic/gin" "net/http" + + "github.com/gin-gonic/gin" ) func CorsHandler() gin.HandlerFunc { diff --git a/src/utils/file.go b/pkg/utils/file.go similarity index 100% rename from src/utils/file.go rename to pkg/utils/file.go diff --git a/src/utils/get_server_ip.go b/pkg/utils/get_server_ip.go similarity index 94% rename from src/utils/get_server_ip.go rename to pkg/utils/get_server_ip.go index ec5824cb8..b7f6076c2 100644 --- a/src/utils/get_server_ip.go +++ b/pkg/utils/get_server_ip.go @@ -1,7 +1,7 @@ package utils import ( - "Open_IM/src/common/config" + "Open_IM/pkg/common/config" "net" ) diff --git a/src/utils/image.go b/pkg/utils/image.go similarity index 100% rename from src/utils/image.go rename to pkg/utils/image.go diff --git a/pkg/utils/jwt_token.go b/pkg/utils/jwt_token.go new file mode 100644 index 000000000..fd6a69ea0 --- /dev/null +++ b/pkg/utils/jwt_token.go @@ -0,0 +1,153 @@ +package utils + +import ( + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/db" + "errors" + "github.com/golang-jwt/jwt/v4" + "time" +) + +var ( + TokenExpired = errors.New("token is timed out, please log in again") + TokenInvalid = errors.New("token has been invalidated") + TokenNotValidYet = errors.New("token not active yet") + TokenMalformed = errors.New("that's not even a token") + TokenUnknown = errors.New("couldn't handle this token") +) + +type Claims struct { + UID string + Platform string //login platform + jwt.RegisteredClaims +} + +func BuildClaims(uid, platform string, ttl int64) Claims { + now := time.Now() + return Claims{ + UID: uid, + Platform: platform, + RegisteredClaims: jwt.RegisteredClaims{ + ExpiresAt: jwt.NewNumericDate(now.Add(time.Duration(ttl*24) * time.Hour)), //Expiration time + IssuedAt: jwt.NewNumericDate(now), //Issuing time + NotBefore: jwt.NewNumericDate(now), //Begin Effective time + }} +} + +func CreateToken(userID string, platform int32) (string, int64, error) { + claims := BuildClaims(userID, PlatformIDToName(platform), config.Config.TokenPolicy.AccessExpire) + token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) + tokenString, err := token.SignedString([]byte(config.Config.TokenPolicy.AccessSecret)) + + return tokenString, claims.ExpiresAt.Time.Unix(), err +} + +func secret() jwt.Keyfunc { + return func(token *jwt.Token) (interface{}, error) { + return []byte(config.Config.TokenPolicy.AccessSecret), nil + } +} + +func getClaimFromToken(tokensString string) (*Claims, error) { + token, err := jwt.ParseWithClaims(tokensString, &Claims{}, secret()) + if err != nil { + if ve, ok := err.(*jwt.ValidationError); ok { + if ve.Errors&jwt.ValidationErrorMalformed != 0 { + return nil, TokenMalformed + } else if ve.Errors&jwt.ValidationErrorExpired != 0 { + return nil, TokenExpired + } else if ve.Errors&jwt.ValidationErrorNotValidYet != 0 { + return nil, TokenNotValidYet + } else { + return nil, TokenUnknown + } + } + } + if claims, ok := token.Claims.(*Claims); ok && token.Valid { + return claims, nil + } + return nil, err +} + +func ParseToken(tokensString string) (claims *Claims, err error) { + claims, err = getClaimFromToken(tokensString) + + if err != nil { + return nil, err + } + + // 1.check userid and platform class 0 not exists and 1 exists + existsInterface, err := db.DB.ExistsUserIDAndPlatform(claims.UID, Platform2class[claims.Platform]) + if err != nil { + return nil, err + } + exists := existsInterface.(int64) + //get config multi login policy + if config.Config.MultiLoginPolicy.OnlyOneTerminalAccess { + //OnlyOneTerminalAccess policy need to check all terminal + //When only one end is allowed to log in, there is a situation that needs to be paid attention to. After PC login, + //mobile login should check two platform times. One of them is less than the redis storage time, which is the invalid token. + platform := "PC" + if Platform2class[claims.Platform] == "PC" { + platform = "Mobile" + } + + existsInterface, err = db.DB.ExistsUserIDAndPlatform(claims.UID, platform) + if err != nil { + return nil, err + } + + exists = existsInterface.(int64) + if exists == 1 { + res, err := MakeTheTokenInvalid(claims, platform) + if err != nil { + return nil, err + } + if res { + return nil, TokenInvalid + } + } + } + // config.Config.MultiLoginPolicy.MobileAndPCTerminalAccessButOtherTerminalKickEachOther == true + // or PC/Mobile validate success + // final check + if exists == 1 { + res, err := MakeTheTokenInvalid(claims, Platform2class[claims.Platform]) + if err != nil { + return nil, err + } + if res { + return nil, TokenInvalid + } + } + return claims, nil +} + +func MakeTheTokenInvalid(currentClaims *Claims, platformClass string) (bool, error) { + storedRedisTokenInterface, err := db.DB.GetPlatformToken(currentClaims.UID, platformClass) + if err != nil { + return false, err + } + storedRedisPlatformClaims, err := ParseRedisInterfaceToken(storedRedisTokenInterface) + if err != nil { + return false, err + } + //if issue time less than redis token then make this token invalid + if currentClaims.IssuedAt.Time.Unix() < storedRedisPlatformClaims.IssuedAt.Time.Unix() { + return true, TokenInvalid + } + return false, nil +} + +func ParseRedisInterfaceToken(redisToken interface{}) (*Claims, error) { + return getClaimFromToken(string(redisToken.([]uint8))) +} + +//Validation token, false means failure, true means successful verification +func VerifyToken(token, uid string) bool { + claims, err := ParseToken(token) + if err != nil || claims.UID != uid { + return false + } + return true +} diff --git a/src/utils/map.go b/pkg/utils/map.go similarity index 100% rename from src/utils/map.go rename to pkg/utils/map.go diff --git a/src/utils/md5.go b/pkg/utils/md5.go similarity index 100% rename from src/utils/md5.go rename to pkg/utils/md5.go diff --git a/src/utils/platform_number_id_to_name.go b/pkg/utils/platform_number_id_to_name.go similarity index 100% rename from src/utils/platform_number_id_to_name.go rename to pkg/utils/platform_number_id_to_name.go diff --git a/src/utils/strings.go b/pkg/utils/strings.go similarity index 100% rename from src/utils/strings.go rename to pkg/utils/strings.go diff --git a/src/utils/time_format.go b/pkg/utils/time_format.go similarity index 100% rename from src/utils/time_format.go rename to pkg/utils/time_format.go diff --git a/script/check_all.sh b/script/check_all.sh index 63fe31711..9e6d45db4 100644 --- a/script/check_all.sh +++ b/script/check_all.sh @@ -33,11 +33,21 @@ done #Check launched service process check=$(ps aux | grep -w ./${msg_transfer_name} | grep -v grep | wc -l) if [ $check -eq ${msg_transfer_service_num} ]; then - echo -e ${GREEN_PREFIX}"none port service has been starting,belongs service is openImMsgTransfer"${COLOR_SUFFIX} + echo -e ${GREEN_PREFIX}"none port has been listening,belongs service is openImMsgTransfer"${COLOR_SUFFIX} else echo -e ${RED_PREFIX}"openImMsgTransfer service does not start normally, num err"${COLOR_SUFFIX} echo -e ${RED_PREFIX}"please check ../logs/openIM.log "${COLOR_SUFFIX} exit -1 fi + +check=$(ps aux | grep -w ./${timer_task_name} | grep -v grep | wc -l) +if [ $check -ge 1 ]; then + echo -e ${GREEN_PREFIX}"none port has been listening,belongs service is openImMsgTimer"${COLOR_SUFFIX} +else + echo -e ${RED_PREFIX}"openImMsgTimer service does not start normally"${COLOR_SUFFIX} + echo -e ${RED_PREFIX}"please check ../logs/openIM.log "${COLOR_SUFFIX} + exit -1 +fi + echo -e ${YELLOW_PREFIX}"all services launch success"${COLOR_SUFFIX} diff --git a/script/docker_start_all.sh b/script/docker_start_all.sh index 740b88e85..839a46688 100644 --- a/script/docker_start_all.sh +++ b/script/docker_start_all.sh @@ -9,6 +9,7 @@ need_to_start_server_shell=( push_start.sh msg_transfer_start.sh sdk_svr_start.sh + timer_start.sh ) #fixme The 10 second delay to start the project is for the docker-compose one-click to start openIM when the infrastructure dependencies are not started diff --git a/script/path_info.cfg b/script/path_info.cfg index f67e017c2..b97588e61 100644 --- a/script/path_info.cfg +++ b/script/path_info.cfg @@ -1,27 +1,31 @@ #Don't put the space between "=" msg_gateway_name="open_im_msg_gateway" msg_gateway_binary_root="../bin/" -msg_gateway_source_root="../src/msg_gateway/" +msg_gateway_source_root="../cmd/open_im_msg_gateway/" msg_name="open_im_msg" msg_binary_root="../bin/" -msg_source_root="../src/rpc/chat/" +msg_source_root="../cmd/rpc/open_im_msg/" push_name="open_im_push" push_binary_root="../bin/" -push_source_root="../src/push/" +push_source_root="../cmd/open_im_push/" msg_transfer_name="open_im_msg_transfer" msg_transfer_binary_root="../bin/" -msg_transfer_source_root="../src/msg_transfer/" +msg_transfer_source_root="../cmd/open_im_msg_transfer/" msg_transfer_service_num=2 +timer_task_name="open_im_timer_task" +timer_task_binary_root="../bin/" +timer_task_source_root="../cmd/open_im_timer_task/" + sdk_server_name="open_im_sdk_server" sdk_server_binary_root="../bin/" -sdk_server_source_root="../src/Open-IM-SDK-Core/" +sdk_server_source_root="../cmd/Open-IM-SDK-Core/" #Global configuration file default dir @@ -30,17 +34,18 @@ config_path="../config/config.yaml" #servicefile dir path service_source_root=( #api service file - ../src/api/ + ../cmd/open_im_api/ #rpc service file - ../src/rpc/user/ - ../src/rpc/friend/ - ../src/rpc/group/ - ../src/rpc/auth/ + ../cmd/rpc/open_im_user/ + ../cmd/rpc/open_im_friend/ + ../cmd/rpc/open_im_group/ + ../cmd/rpc/open_im_auth/ ${msg_gateway_source_root} ${msg_transfer_source_root} ${msg_source_root} ${push_source_root} ${sdk_server_source_root} + ${timer_task_source_root} ) #service filename service_names=( @@ -56,6 +61,7 @@ service_names=( ${msg_name} ${push_name} ${sdk_server_name} + ${timer_task_name} ) diff --git a/script/start_all.sh b/script/start_all.sh index 43a02b34d..956bc0d51 100644 --- a/script/start_all.sh +++ b/script/start_all.sh @@ -9,6 +9,7 @@ need_to_start_server_shell=( push_start.sh msg_transfer_start.sh sdk_svr_start.sh + timer_start.sh ) for i in ${need_to_start_server_shell[*]}; do diff --git a/script/start_rpc_service.sh b/script/start_rpc_service.sh index 74f00a3f4..9491a4fe8 100644 --- a/script/start_rpc_service.sh +++ b/script/start_rpc_service.sh @@ -26,7 +26,6 @@ service_port_name=( openImGroupPort openImAuthPort openImOfflineMessagePort - ) for ((i = 0; i < ${#service_filename[*]}; i++)); do diff --git a/script/timer_start.sh b/script/timer_start.sh new file mode 100644 index 000000000..7e2791f11 --- /dev/null +++ b/script/timer_start.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +#Include shell font styles and some basic information +source ./style_info.cfg +source ./path_info.cfg + + + +#Check if the service exists +#If it is exists,kill this process +check=`ps aux | grep -w ./${timer_task_name} | grep -v grep| wc -l` +if [ $check -ge 1 ] +then +oldPid=`ps aux | grep -w ./${timer_task_name} | grep -v grep|awk '{print $2}'` + kill -9 $oldPid +fi +#Waiting port recycling +sleep 1 + +cd ${timer_task_binary_root} +nohup ./${timer_task_name} >>../logs/openIM.log 2>&1 & + + +#Check launched service process +check=`ps aux | grep -w ./${timer_task_name} | grep -v grep| wc -l` +if [ $check -ge 1 ] +then +newPid=`ps aux | grep -w ./${timer_task_name} | grep -v grep|awk '{print $2}'` +allPorts="" + echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS "${COLOR_SUFFIX} + echo -e ${SKY_BLUE_PREFIX}"SERVICE_NAME: "${COLOR_SUFFIX}${YELLOW_PREFIX}${timer_task_name}${COLOR_SUFFIX} + echo -e ${SKY_BLUE_PREFIX}"PID: "${COLOR_SUFFIX}${YELLOW_PREFIX}${newPid}${COLOR_SUFFIX} + echo -e ${SKY_BLUE_PREFIX}"LISTENING_PORT: "${COLOR_SUFFIX}${YELLOW_PREFIX}${allPorts}${COLOR_SUFFIX} +else + echo -e ${YELLOW_PREFIX}${timer_task_name}${COLOR_SUFFIX}${RED_PREFIX}"SERVICE START ERROR, PLEASE CHECK openIM.log"${COLOR_SUFFIX} +fi diff --git a/src/Open-IM-SDK-Core b/src/Open-IM-SDK-Core deleted file mode 160000 index 3d956a1a4..000000000 --- a/src/Open-IM-SDK-Core +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3d956a1a40024f0a5f4959d6e46f6f503a1618ce diff --git a/src/api/Makefile b/src/api/Makefile deleted file mode 100644 index 5ea7e5742..000000000 --- a/src/api/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -.PHONY: all build run gotool install clean help - -BINARY_NAME=open_im_api -BIN_DIR=../../bin/ -LAN_FILE=.go -GO_FILE:=${BINARY_NAME}${LAN_FILE} - -all: gotool build - -build: - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${BINARY_NAME} ${GO_FILE} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install: - make build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi - diff --git a/src/common/db/mysql.go b/src/common/db/mysql.go deleted file mode 100644 index a7a163686..000000000 --- a/src/common/db/mysql.go +++ /dev/null @@ -1,136 +0,0 @@ -package db - -import ( - "Open_IM/src/common/config" - "Open_IM/src/common/log" - "fmt" - "github.com/jinzhu/gorm" - _ "github.com/jinzhu/gorm/dialects/mysql" - "sync" - "time" -) - -type mysqlDB struct { - sync.RWMutex - dbMap map[string]*gorm.DB -} - -func initMysqlDB() { - //When there is no open IM database, connect to the mysql built-in database to create openIM database - dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local", - config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], "mysql") - - db, err := gorm.Open("mysql", dsn) - if err != nil { - log.Error("", "", dsn) - panic(err) - } - - //Check the database and table during initialization - sql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s ;", config.Config.Mysql.DBDatabaseName) - err = db.Exec(sql).Error - if err != nil { - panic(err) - } - db.Close() - - dsn = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local", - config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName) - db, err = gorm.Open("mysql", dsn) - if err != nil { - panic(err) - } - - sqlTable := "CREATE TABLE IF NOT EXISTS `user` (\n `uid` varchar(64) NOT NULL,\n `name` varchar(64) DEFAULT NULL,\n `icon` varchar(1024) DEFAULT NULL,\n `gender` int(11) unsigned zerofill DEFAULT NULL,\n `mobile` varchar(32) DEFAULT NULL,\n `birth` varchar(16) DEFAULT NULL,\n `email` varchar(64) DEFAULT NULL,\n `ex` varchar(1024) DEFAULT NULL,\n `create_time` datetime DEFAULT NULL,\n PRIMARY KEY (`uid`),\n UNIQUE KEY `uk_uid` (`uid`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err) - } - - sqlTable = "CREATE TABLE IF NOT EXISTS `friend` (\n `owner_id` varchar(255) NOT NULL,\n `friend_id` varchar(255) NOT NULL,\n `comment` varchar(255) DEFAULT NULL,\n `friend_flag` int(11) NOT NULL,\n `create_time` datetime NOT NULL,\n PRIMARY KEY (`owner_id`,`friend_id`) USING BTREE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err) - } - - sqlTable = "CREATE TABLE IF NOT EXISTS `friend_request` (\n `req_id` varchar(255) NOT NULL,\n `user_id` varchar(255) NOT NULL,\n `flag` int(11) NOT NULL DEFAULT '0',\n `req_message` varchar(255) DEFAULT NULL,\n `create_time` datetime NOT NULL,\n PRIMARY KEY (`user_id`,`req_id`) USING BTREE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err) - } - - sqlTable = "CREATE TABLE IF NOT EXISTS `black_list` (\n `uid` varchar(32) NOT NULL COMMENT 'uid',\n `begin_disable_time` datetime DEFAULT NULL,\n `end_disable_time` datetime DEFAULT NULL,\n `ex` varchar(1024) DEFAULT NULL,\n PRIMARY KEY (`uid`) USING BTREE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err) - } - - sqlTable = "CREATE TABLE IF NOT EXISTS `user_black_list` (\n `owner_id` varchar(255) NOT NULL,\n `block_id` varchar(255) NOT NULL,\n `create_time` datetime NOT NULL,\n PRIMARY KEY (`owner_id`,`block_id`) USING BTREE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err) - } - - sqlTable = "CREATE TABLE IF NOT EXISTS `group` (\n `group_id` varchar(255) NOT NULL,\n `name` varchar(255) DEFAULT NULL,\n `introduction` varchar(255) DEFAULT NULL,\n `notification` varchar(255) DEFAULT NULL,\n `face_url` varchar(255) DEFAULT NULL,\n `create_time` datetime DEFAULT NULL,\n `ex` varchar(255) DEFAULT NULL,\n PRIMARY KEY (`group_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err) - } - - sqlTable = "CREATE TABLE IF NOT EXISTS `group_member` (\n `group_id` varchar(255) NOT NULL,\n `uid` varchar(255) NOT NULL,\n `nickname` varchar(255) DEFAULT NULL,\n `user_group_face_url` varchar(255) DEFAULT NULL,\n `administrator_level` int(11) NOT NULL,\n `join_time` datetime NOT NULL,\n PRIMARY KEY (`group_id`,`uid`) USING BTREE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err) - } - - sqlTable = "CREATE TABLE IF NOT EXISTS `group_request` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `group_id` varchar(255) NOT NULL,\n `from_user_id` varchar(255) NOT NULL,\n `to_user_id` varchar(255) NOT NULL,\n `flag` int(10) NOT NULL DEFAULT '0',\n `req_msg` varchar(255) DEFAULT '',\n `handled_msg` varchar(255) DEFAULT '',\n `create_time` datetime NOT NULL,\n `from_user_nickname` varchar(255) DEFAULT '',\n `to_user_nickname` varchar(255) DEFAULT NULL,\n `from_user_face_url` varchar(255) DEFAULT '',\n `to_user_face_url` varchar(255) DEFAULT '',\n `handled_user` varchar(255) DEFAULT '',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8mb4;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err) - } - - sqlTable = "CREATE TABLE IF NOT EXISTS `chat_log` (\n `msg_id` varchar(128) NOT NULL,\n `send_id` varchar(255) NOT NULL,\n `session_type` int(11) NOT NULL,\n `recv_id` varchar(255) NOT NULL,\n `content_type` int(11) NOT NULL,\n `msg_from` int(11) NOT NULL,\n `content` varchar(1000) NOT NULL,\n `remark` varchar(100) DEFAULT NULL,\n `sender_platform_id` int(11) NOT NULL,\n `send_time` datetime NOT NULL,\n PRIMARY KEY (`msg_id`) USING BTREE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err) - } - -} - -func (m *mysqlDB) DefaultGormDB() (*gorm.DB, error) { - return m.GormDB(config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName) -} - -func (m *mysqlDB) GormDB(dbAddress, dbName string) (*gorm.DB, error) { - m.Lock() - defer m.Unlock() - - k := key(dbAddress, dbName) - if _, ok := m.dbMap[k]; !ok { - if err := m.open(dbAddress, dbName); err != nil { - return nil, err - } - } - return m.dbMap[k], nil -} - -func (m *mysqlDB) open(dbAddress, dbName string) error { - dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local", - config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, dbAddress, dbName) - db, err := gorm.Open("mysql", dsn) - if err != nil { - return err - } - - db.SingularTable(true) - db.DB().SetMaxOpenConns(config.Config.Mysql.DBMaxOpenConns) - db.DB().SetMaxIdleConns(config.Config.Mysql.DBMaxIdleConns) - db.DB().SetConnMaxLifetime(time.Duration(config.Config.Mysql.DBMaxLifeTime) * time.Second) - - if m.dbMap == nil { - m.dbMap = make(map[string]*gorm.DB) - } - k := key(dbAddress, dbName) - m.dbMap[k] = db - return nil -} diff --git a/src/rpc/auth/Makefile b/src/rpc/auth/Makefile deleted file mode 100644 index 12c10351d..000000000 --- a/src/rpc/auth/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -.PHONY: all build run gotool install clean help - -BINARY_NAME=open_im_auth -BIN_DIR=../../../bin/ -LAN_FILE=.go -GO_FILE:=${BINARY_NAME}${LAN_FILE} - -all: gotool build - -build: - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${BINARY_NAME} ${GO_FILE} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install: - make build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi - diff --git a/src/rpc/chat/open_im_msg.go b/src/rpc/chat/open_im_msg.go deleted file mode 100644 index e1a0a11a4..000000000 --- a/src/rpc/chat/open_im_msg.go +++ /dev/null @@ -1,14 +0,0 @@ -package main - -import ( - rpcChat "Open_IM/src/rpc/chat/chat" - "Open_IM/src/utils" - "flag" -) - -func main() { - rpcPort := flag.String("port", "", "rpc listening port") - flag.Parse() - rpcServer := rpcChat.NewRpcChatServer(utils.StringToInt(*rpcPort)) - rpcServer.Run() -} diff --git a/src/rpc/friend/Makefile b/src/rpc/friend/Makefile deleted file mode 100644 index c1291dc82..000000000 --- a/src/rpc/friend/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -.PHONY: all build run gotool install clean help - -BINARY_NAME=open_im_friend -BIN_DIR=../../../bin/ -LAN_FILE=.go -GO_FILE:=${BINARY_NAME}${LAN_FILE} - -all: gotool build - -build: - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${BINARY_NAME} ${GO_FILE} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install: - make build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi - - diff --git a/src/rpc/group/Makefile b/src/rpc/group/Makefile deleted file mode 100644 index 2ada2e2a6..000000000 --- a/src/rpc/group/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -.PHONY: all build run gotool install clean help - -BINARY_NAME=open_im_group -BIN_DIR=../../../bin/ -LAN_FILE=.go -GO_FILE:=${BINARY_NAME}${LAN_FILE} - -all: gotool build - -build: - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${BINARY_NAME} ${GO_FILE} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install: - make build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi - - diff --git a/src/rpc/user/Makefile b/src/rpc/user/Makefile deleted file mode 100644 index d3f837791..000000000 --- a/src/rpc/user/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -.PHONY: all build run gotool install clean help - -BINARY_NAME=open_im_user -BIN_DIR=../../../bin/ -LAN_FILE=.go -GO_FILE:=${BINARY_NAME}${LAN_FILE} - -all: gotool build - -build: - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${BINARY_NAME} ${GO_FILE} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install: - make build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi - - diff --git a/src/timed_task/open_im_timed_task.go b/src/timed_task/open_im_timed_task.go deleted file mode 100644 index f6cd87a67..000000000 --- a/src/timed_task/open_im_timed_task.go +++ /dev/null @@ -1,42 +0,0 @@ -package main - -import ( - "Open_IM/src/common/config" - "Open_IM/src/common/db" - "fmt" - "time" -) - -func main() { - for { - fmt.Println("start delete mongodb expired record") - timeUnixBegin := time.Now().Unix() - count, _ := db.DB.MgoUserCount() - fmt.Println("mongodb record count: ", count) - for i := 0; i < count; i++ { - time.Sleep(1 * time.Millisecond) - uid, _ := db.DB.MgoSkipUID(i) - fmt.Println("operate uid: ", uid) - err := db.DB.DelUserChat(uid) - if err != nil { - fmt.Println("operate uid failed: ", uid, err.Error()) - } - } - - timeUnixEnd := time.Now().Unix() - costTime := timeUnixEnd - timeUnixBegin - if costTime > int64(config.Config.Mongo.DBRetainChatRecords*24*3600) { - continue - } else { - sleepTime := 0 - if int64(config.Config.Mongo.DBRetainChatRecords*24*3600)-costTime > 24*3600 { - sleepTime = 24 * 3600 - } else { - sleepTime = config.Config.Mongo.DBRetainChatRecords*24*3600 - int(costTime) - } - fmt.Println("sleep: ", sleepTime) - time.Sleep(time.Duration(sleepTime) * time.Second) - } - } - -} diff --git a/src/utils/jwt_token.go b/src/utils/jwt_token.go deleted file mode 100644 index 264da2483..000000000 --- a/src/utils/jwt_token.go +++ /dev/null @@ -1,193 +0,0 @@ -package utils - -import ( - "Open_IM/src/common/config" - "Open_IM/src/common/db" - "errors" - "github.com/dgrijalva/jwt-go" - "time" -) - -var ( - TokenExpired = errors.New("token is timed out, please log in again") - TokenInvalid = errors.New("token has been invalidated") - TokenNotValidYet = errors.New("token not active yet") - TokenMalformed = errors.New("that's not even a token") - TokenUnknown = errors.New("couldn't handle this token") -) - -type Claims struct { - UID string - Platform string //login platform - jwt.StandardClaims -} - -func BuildClaims(uid, accountAddr, platform string, ttl int64) Claims { - now := time.Now().Unix() - //if ttl=-1 Permanent token - if ttl == -1 { - return Claims{ - UID: uid, - Platform: platform, - StandardClaims: jwt.StandardClaims{ - ExpiresAt: -1, - IssuedAt: now, - NotBefore: now, - }} - } - return Claims{ - UID: uid, - Platform: platform, - StandardClaims: jwt.StandardClaims{ - ExpiresAt: now + ttl, //Expiration time - IssuedAt: now, //Issuing time - NotBefore: now, //Begin Effective time - }} -} - -func CreateToken(userID, accountAddr string, platform int32) (string, int64, error) { - claims := BuildClaims(userID, accountAddr, PlatformIDToName(platform), config.Config.TokenPolicy.AccessExpire) - token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) - tokenString, err := token.SignedString([]byte(config.Config.TokenPolicy.AccessSecret)) - - return tokenString, claims.ExpiresAt, err -} - -func secret() jwt.Keyfunc { - return func(token *jwt.Token) (interface{}, error) { - return []byte(config.Config.TokenPolicy.AccessSecret), nil - } -} - -func ParseToken(tokensString string) (claims *Claims, err error) { - token, err := jwt.ParseWithClaims(tokensString, &Claims{}, secret()) - if err != nil { - if ve, ok := err.(*jwt.ValidationError); ok { - if ve.Errors&jwt.ValidationErrorMalformed != 0 { - return nil, TokenMalformed - } else if ve.Errors&jwt.ValidationErrorExpired != 0 { - return nil, TokenExpired - } else if ve.Errors&jwt.ValidationErrorNotValidYet != 0 { - return nil, TokenNotValidYet - } else { - return nil, TokenUnknown - } - } - } - if claims, ok := token.Claims.(*Claims); ok && token.Valid { - // 1.check userid and platform class 0 not exists and 1 exists - existsInterface, err := db.DB.ExistsUserIDAndPlatform(claims.UID, Platform2class[claims.Platform]) - if err != nil { - return nil, err - } - exists := existsInterface.(int64) - //get config multi login policy - if config.Config.MultiLoginPolicy.OnlyOneTerminalAccess { - //OnlyOneTerminalAccess policy need to check all terminal - //When only one end is allowed to log in, there is a situation that needs to be paid attention to. After PC login, - //mobile login should check two platform times. One of them is less than the redis storage time, which is the invalid token. - if Platform2class[claims.Platform] == "PC" { - existsInterface, err = db.DB.ExistsUserIDAndPlatform(claims.UID, "Mobile") - if err != nil { - return nil, err - } - exists = existsInterface.(int64) - if exists == 1 { - res, err := MakeTheTokenInvalid(*claims, "Mobile") - if err != nil { - return nil, err - } - if res { - return nil, TokenInvalid - } - } - } else { - existsInterface, err = db.DB.ExistsUserIDAndPlatform(claims.UID, "PC") - if err != nil { - return nil, err - } - exists = existsInterface.(int64) - if exists == 1 { - res, err := MakeTheTokenInvalid(*claims, "PC") - if err != nil { - return nil, err - } - if res { - return nil, TokenInvalid - } - } - } - - if exists == 1 { - res, err := MakeTheTokenInvalid(*claims, Platform2class[claims.Platform]) - if err != nil { - return nil, err - } - if res { - return nil, TokenInvalid - } - } - - } else if config.Config.MultiLoginPolicy.MobileAndPCTerminalAccessButOtherTerminalKickEachOther { - if exists == 1 { - res, err := MakeTheTokenInvalid(*claims, Platform2class[claims.Platform]) - if err != nil { - return nil, err - } - if res { - return nil, TokenInvalid - } - } - } - return claims, nil - } - return nil, TokenUnknown -} - -func MakeTheTokenInvalid(currentClaims Claims, platformClass string) (bool, error) { - storedRedisTokenInterface, err := db.DB.GetPlatformToken(currentClaims.UID, platformClass) - if err != nil { - return false, err - } - storedRedisPlatformClaims, err := ParseRedisInterfaceToken(storedRedisTokenInterface) - if err != nil { - return false, err - } - //if issue time less than redis token then make this token invalid - if currentClaims.IssuedAt < storedRedisPlatformClaims.IssuedAt { - return true, TokenInvalid - } - return false, nil -} -func ParseRedisInterfaceToken(redisToken interface{}) (*Claims, error) { - token, err := jwt.ParseWithClaims(string(redisToken.([]uint8)), &Claims{}, secret()) - if err != nil { - if ve, ok := err.(*jwt.ValidationError); ok { - if ve.Errors&jwt.ValidationErrorMalformed != 0 { - return nil, TokenMalformed - } else if ve.Errors&jwt.ValidationErrorExpired != 0 { - return nil, TokenExpired - } else if ve.Errors&jwt.ValidationErrorNotValidYet != 0 { - return nil, TokenNotValidYet - } else { - return nil, TokenInvalid - } - } - } - if claims, ok := token.Claims.(*Claims); ok && token.Valid { - return claims, nil - } - return nil, err -} - -//Validation token, false means failure, true means successful verification -func VerifyToken(token, uid string) bool { - claims, err := ParseToken(token) - if err != nil { - return false - } else if claims.UID != uid { - return false - } else { - return true - } -}