refactor: 3.7.0 code conventions. (#2148)

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* feat: add code lint

* feat: add code lint

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Script Refactoring

* feat: code format

* Script Refactoring

* Script Refactoring

* Script Refactoring

* Adjust MinIO configuration settings

* Adjust configuration settings

* Adjust configuration settings

* refactor: config change.

* refactor: webhooks update.

* Adjust configuration settings

* refactor: webhooks update.

* Adjust configuration settings

* Adjust configuration settings

* Adjust configuration settings

* feat: s3 api addr

* refactor: webhooks update.

* Adjust configuration settings

* Adjust configuration settings

* Adjust configuration settings

* Adjust configuration settings

* Adjust configuration settings

* Adjust configuration settings

* Adjust configuration settings

* refactor: webhooks update.

* refactor: kafka update.

* Simplify the Docker Compose configuration, remove unnecessary environment variables, and eliminate the gateway service.

* refactor: kafka update.

* refactor: kafka update.

* Simplify the Docker Compose configuration, remove unnecessary environment variables, and eliminate the gateway service.

* Simplify the Docker Compose configuration, remove unnecessary environment variables, and eliminate the gateway service.

* Windows can compile and run.

* Windows can compile and run.

* refactor: kafka update.

* feat: msg cache split

* refactor: webhooks update

* refactor: webhooks update

* refactor: friends update

* refactor: group update

* refactor: third update

* refactor: api update

* refactor: crontab update

* refactor: msggateway update

* mage

* mage

* refactor: all module update.

* check

* refactor: all module update.

* load config

* load config

* load config

* load config

* refactor: all module update.

* refactor: all module update.

* refactor: all module update.

* refactor: all module update.

* refactor: all module update.

* Optimize Docker configuration and script.

* refactor: all module update.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* refactor: all module update.

* Optimize Docker configuration and script.

* refactor: all module update.

* refactor: all module update.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* update tools

* update tools

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* update protocol

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* refactor: all module update.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* Optimize Docker configuration and script.

* refactor: api remove token auth by redis directly.

* Code Refactoring

* refactor: websocket auth change to call rpc of auth.

* refactor: kick online user and remove token change to call auth rpc.

* refactor: kick online user and remove token change to call auth rpc.

* refactor: remove msggateway redis.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor webhook

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor webhook

* refactor: cmd update.

* refactor: cmd update.

* fix: runtime: goroutine stack exceeds

* refactor: cmd update.

* refactor notification

* refactor notification

* refactor

* refactor: cmd update.

* refactor: cmd update.

* refactor

* refactor

* refactor

* protojson

* protojson

* protojson

* go mod

* wrapperspb

* refactor: cmd update.

* refactor: cmd update.

* refactor: cmd update.

* refactor: context update.

* refactor: websocket update info.

* refactor: websocket update info.

* refactor: websocket update info.

* refactor: websocket update info.

* refactor: api name change.

* refactor: debug info.

* refactor: debug info.

* refactor: debug info.

* fix: update file

* refactor

* refactor

* refactor: debug info.

* refactor: debug info.

* refactor: debug info.

* refactor: debug info.

* refactor: debug info.

* refactor: debug info.

* fix: callback update.

* fix: callback update.

* refactor

* fix: update message.

* fix: msg cache timeout.

* refactor

* refactor

* fix: push update.

* fix: push update.

* fix: push update.

* fix: push update.

* fix: push update.

* fix: push update.

* fix: push update.

* fix: websocket handle error remove when upgrade error.

---------

Co-authored-by: skiffer-git <44203734@qq.com>
Co-authored-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
Co-authored-by: withchao <993506633@qq.com>
This commit is contained in:
OpenIM-Gordon
2024-04-19 22:23:08 +08:00
committed by GitHub
parent cca5336a8a
commit b76816bc14
438 changed files with 11525 additions and 15033 deletions
+2 -3
View File
@@ -16,8 +16,7 @@ package dummy
import (
"context"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
)
func NewClient() *Dummy {
@@ -27,6 +26,6 @@ func NewClient() *Dummy {
type Dummy struct {
}
func (d *Dummy) Push(ctx context.Context, userIDs []string, title, content string, opts *offlinepush.Opts) error {
func (d *Dummy) Push(ctx context.Context, userIDs []string, title, content string, opts *options.Opts) error {
return nil
}
+14 -10
View File
@@ -16,14 +16,15 @@ package fcm
import (
"context"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
"path/filepath"
firebase "firebase.google.com/go"
"firebase.google.com/go/messaging"
"github.com/OpenIMSDK/protocol/constant"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
"github.com/openimsdk/protocol/constant"
"github.com/openimsdk/tools/errs"
"github.com/redis/go-redis/v9"
"google.golang.org/api/option"
)
@@ -34,29 +35,32 @@ var Terminal = []int{constant.IOSPlatformID, constant.AndroidPlatformID, constan
type Fcm struct {
fcmMsgCli *messaging.Client
cache cache.MsgModel
cache cache.ThirdCache
}
// NewClient initializes a new FCM client using the Firebase Admin SDK.
// It requires the FCM service account credentials file located within the project's configuration directory.
func NewClient(globalConfig *config.GlobalConfig, cache cache.MsgModel) *Fcm {
projectRoot := config.GetProjectRoot()
credentialsFilePath := filepath.Join(projectRoot, "config", globalConfig.Push.Fcm.ServiceAccount)
func NewClient(pushConf *config.Push, cache cache.ThirdCache) (*Fcm, error) {
projectRoot, err := config.GetProjectRoot()
if err != nil {
return nil, err
}
credentialsFilePath := filepath.Join(projectRoot, "config", pushConf.FCM.ServiceAccount)
opt := option.WithCredentialsFile(credentialsFilePath)
fcmApp, err := firebase.NewApp(context.Background(), nil, opt)
if err != nil {
return nil
return nil, errs.Wrap(err)
}
ctx := context.Background()
fcmMsgClient, err := fcmApp.Messaging(ctx)
if err != nil {
return nil
return nil, errs.Wrap(err)
}
return &Fcm{fcmMsgCli: fcmMsgClient, cache: cache}
return &Fcm{fcmMsgCli: fcmMsgClient, cache: cache}, nil
}
func (f *Fcm) Push(ctx context.Context, userIDs []string, title, content string, opts *offlinepush.Opts) error {
func (f *Fcm) Push(ctx context.Context, userIDs []string, title, content string, opts *options.Opts) error {
// accounts->registrationToken
allTokens := make(map[string][]string, 0)
for _, account := range userIDs {
+3 -3
View File
@@ -133,13 +133,13 @@ type Payload struct {
IsSignal bool `json:"isSignal"`
}
func newPushReq(config *config.GlobalConfig, title, content string) PushReq {
func newPushReq(pushConf *config.Push, title, content string) PushReq {
pushReq := PushReq{PushMessage: &PushMessage{Notification: &Notification{
Title: title,
Body: content,
ClickType: "startapp",
ChannelID: config.Push.GeTui.ChannelID,
ChannelName: config.Push.GeTui.ChannelName,
ChannelID: pushConf.GeTui.ChannelID,
ChannelName: pushConf.GeTui.ChannelName,
}}}
return pushReq
}
+22 -21
View File
@@ -18,25 +18,24 @@ import (
"context"
"crypto/sha256"
"encoding/hex"
"errors"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
"strconv"
"sync"
"time"
"github.com/OpenIMSDK/tools/errs"
"github.com/OpenIMSDK/tools/log"
"github.com/OpenIMSDK/tools/mcontext"
"github.com/OpenIMSDK/tools/utils/splitter"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
http2 "github.com/openimsdk/open-im-server/v3/pkg/common/http"
"github.com/openimsdk/tools/errs"
"github.com/openimsdk/tools/log"
"github.com/openimsdk/tools/mcontext"
"github.com/openimsdk/tools/utils/httputil"
"github.com/openimsdk/tools/utils/splitter"
"github.com/redis/go-redis/v9"
)
var (
ErrTokenExpire = errors.New("token expire")
ErrUserIDEmpty = errors.New("userIDs is empty")
ErrTokenExpire = errs.New("token expire")
ErrUserIDEmpty = errs.New("userIDs is empty")
)
const (
@@ -45,32 +44,34 @@ const (
taskURL = "/push/list/message"
batchPushURL = "/push/list/alias"
// codes.
// Codes.
tokenExpireCode = 10001
tokenExpireTime = 60 * 60 * 23
taskIDTTL = 1000 * 60 * 60 * 24
)
type Client struct {
cache cache.MsgModel
cache cache.ThirdCache
tokenExpireTime int64
taskIDTTL int64
config *config.GlobalConfig
pushConf *config.Push
httpClient *httputil.HTTPClient
}
func NewClient(config *config.GlobalConfig, cache cache.MsgModel) *Client {
func NewClient(pushConf *config.Push, cache cache.ThirdCache) *Client {
return &Client{cache: cache,
tokenExpireTime: tokenExpireTime,
taskIDTTL: taskIDTTL,
config: config,
pushConf: pushConf,
httpClient: httputil.NewHTTPClient(httputil.NewClientConfig()),
}
}
func (g *Client) Push(ctx context.Context, userIDs []string, title, content string, opts *offlinepush.Opts) error {
func (g *Client) Push(ctx context.Context, userIDs []string, title, content string, opts *options.Opts) error {
token, err := g.cache.GetGetuiToken(ctx)
if err != nil {
if errs.Unwrap(err) == redis.Nil {
log.ZInfo(ctx, "getui token not exist in redis")
log.ZDebug(ctx, "getui token not exist in redis")
token, err = g.getTokenAndSave2Redis(ctx)
if err != nil {
return err
@@ -79,7 +80,7 @@ func (g *Client) Push(ctx context.Context, userIDs []string, title, content stri
return err
}
}
pushReq := newPushReq(g.config, title, content)
pushReq := newPushReq(g.pushConf, title, content)
pushReq.setPushChannel(title, content)
if len(userIDs) > 1 {
maxNum := 999
@@ -114,13 +115,13 @@ func (g *Client) Push(ctx context.Context, userIDs []string, title, content stri
func (g *Client) Auth(ctx context.Context, timeStamp int64) (token string, expireTime int64, err error) {
h := sha256.New()
h.Write(
[]byte(g.config.Push.GeTui.AppKey + strconv.Itoa(int(timeStamp)) + g.config.Push.GeTui.MasterSecret),
[]byte(g.pushConf.GeTui.AppKey + strconv.Itoa(int(timeStamp)) + g.pushConf.GeTui.MasterSecret),
)
sign := hex.EncodeToString(h.Sum(nil))
reqAuth := AuthReq{
Sign: sign,
Timestamp: strconv.Itoa(int(timeStamp)),
AppKey: g.config.Push.GeTui.AppKey,
AppKey: g.pushConf.GeTui.AppKey,
}
respAuth := AuthResp{}
err = g.request(ctx, authURL, reqAuth, "", &respAuth)
@@ -163,7 +164,7 @@ func (g *Client) request(ctx context.Context, url string, input any, token strin
header := map[string]string{"token": token}
resp := &Resp{}
resp.Data = output
return g.postReturn(ctx, g.config.Push.GeTui.PushUrl+url, header, input, resp, 3)
return g.postReturn(ctx, g.pushConf.GeTui.PushUrl+url, header, input, resp, 3)
}
func (g *Client) postReturn(
@@ -174,7 +175,7 @@ func (g *Client) postReturn(
output RespI,
timeout int,
) error {
err := http2.PostReturn(ctx, url, header, input, output, timeout)
err := g.httpClient.PostReturn(ctx, url, header, input, output, timeout)
if err != nil {
return err
}
@@ -32,8 +32,8 @@ func (a *Audience) set(key string, v []string) {
a.audience = make(map[string][]string)
a.Object = a.audience
}
//v, ok = this.audience[key]
//if ok {
// v, ok = this.audience[key]
// if ok {
// return
//}
a.audience[key] = v
@@ -56,8 +56,8 @@ func (n *Notification) SetExtras(extras Extras) {
n.Android.Extras = extras
}
func (n *Notification) SetAndroidIntent(config *config.GlobalConfig) {
n.Android.Intent.URL = config.Push.Jpns.PushIntent
func (n *Notification) SetAndroidIntent(pushConf *config.Push) {
n.Android.Intent.URL = pushConf.JPNS.PushIntent
}
func (n *Notification) IOSEnableMutableContent() {
@@ -15,9 +15,9 @@
package body
import (
"errors"
"github.com/openimsdk/tools/errs"
"github.com/OpenIMSDK/protocol/constant"
"github.com/openimsdk/protocol/constant"
)
const (
@@ -39,7 +39,7 @@ func (p *Platform) Set(os string) error {
} else {
switch p.Os.(type) {
case string:
return errors.New("platform is all")
return errs.New("platform is all")
default:
}
}
@@ -61,7 +61,7 @@ func (p *Platform) Set(os string) error {
p.osArry = append(p.osArry, os)
p.Os = p.osArry
default:
return errors.New("unknow platform")
return errs.New("unknow platform")
}
return nil
@@ -74,7 +74,7 @@ func (p *Platform) SetPlatform(platform string) error {
case constant.IOSPlatformStr:
return p.SetIOS()
default:
return errors.New("platform err")
return errs.New("platform err")
}
}
+14 -11
View File
@@ -18,19 +18,22 @@ import (
"context"
"encoding/base64"
"fmt"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/jpush/body"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
http2 "github.com/openimsdk/open-im-server/v3/pkg/common/http"
"github.com/openimsdk/tools/utils/httputil"
)
type JPush struct {
config *config.GlobalConfig
pushConf *config.Push
httpClient *httputil.HTTPClient
}
func NewClient(config *config.GlobalConfig) *JPush {
return &JPush{config: config}
func NewClient(pushConf *config.Push) *JPush {
return &JPush{pushConf: pushConf,
httpClient: httputil.NewHTTPClient(httputil.NewClientConfig()),
}
}
func (j *JPush) Auth(apiKey, secretKey string, timeStamp int64) (token string, err error) {
@@ -48,7 +51,7 @@ func (j *JPush) getAuthorization(appKey string, masterSecret string) string {
return Authorization
}
func (j *JPush) Push(ctx context.Context, userIDs []string, title, content string, opts *offlinepush.Opts) error {
func (j *JPush) Push(ctx context.Context, userIDs []string, title, content string, opts *options.Opts) error {
var pf body.Platform
pf.SetAll()
var au body.Audience
@@ -61,12 +64,12 @@ func (j *JPush) Push(ctx context.Context, userIDs []string, title, content strin
no.IOSEnableMutableContent()
no.SetExtras(extras)
no.SetAlert(title)
no.SetAndroidIntent(j.config)
no.SetAndroidIntent(j.pushConf)
var msg body.Message
msg.SetMsgContent(content)
var opt body.Options
opt.SetApnsProduction(j.config.IOSPush.Production)
opt.SetApnsProduction(j.pushConf.IOSPush.Production)
var pushObj body.PushObj
pushObj.SetPlatform(&pf)
pushObj.SetAudience(&au)
@@ -78,11 +81,11 @@ func (j *JPush) Push(ctx context.Context, userIDs []string, title, content strin
}
func (j *JPush) request(ctx context.Context, po body.PushObj, resp any, timeout int) error {
return http2.PostReturn(
return j.httpClient.PostReturn(
ctx,
j.config.Push.Jpns.PushUrl,
j.pushConf.JPNS.PushURL,
map[string]string{
"Authorization": j.getAuthorization(j.config.Push.Jpns.AppKey, j.config.Push.Jpns.MasterSecret),
"Authorization": j.getAuthorization(j.pushConf.JPNS.AppKey, j.pushConf.JPNS.MasterSecret),
},
po,
resp,
@@ -1,37 +0,0 @@
// Copyright © 2023 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package offlinepush
import (
"context"
)
// OfflinePusher Offline Pusher.
type OfflinePusher interface {
Push(ctx context.Context, userIDs []string, title, content string, opts *Opts) error
}
// Opts opts.
type Opts struct {
Signal *Signal
IOSPushSound string
IOSBadgeCount bool
Ex string
}
// Signal message id.
type Signal struct {
ClientMsgID string
}
@@ -0,0 +1,52 @@
// Copyright © 2023 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package offlinepush
import (
"context"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/dummy"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/fcm"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/getui"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/jpush"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
)
const (
geTUI = "getui"
firebase = "fcm"
jPush = "jpush"
)
// OfflinePusher Offline Pusher.
type OfflinePusher interface {
Push(ctx context.Context, userIDs []string, title, content string, opts *options.Opts) error
}
func NewOfflinePusher(pushConf *config.Push, cache cache.ThirdCache) (OfflinePusher, error) {
var offlinePusher OfflinePusher
switch pushConf.Enable {
case geTUI:
offlinePusher = getui.NewClient(pushConf, cache)
case firebase:
return fcm.NewClient(pushConf, cache)
case jPush:
offlinePusher = jpush.NewClient(pushConf)
default:
offlinePusher = dummy.NewClient()
}
return offlinePusher, nil
}
@@ -0,0 +1,14 @@
package options
// Opts opts.
type Opts struct {
Signal *Signal
IOSPushSound string
IOSBadgeCount bool
Ex string
}
// Signal message id.
type Signal struct {
ClientMsgID string
}