fix: Function params involve heavy amount of copying (#622)
This commit is contained in:
parent
6d65c1ea6e
commit
349c0c8c1d
|
@ -276,8 +276,8 @@ type SectionGRPC struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadConf load config from file and read in environment variables that match
|
// LoadConf load config from file and read in environment variables that match
|
||||||
func LoadConf(confPath ...string) (ConfYaml, error) {
|
func LoadConf(confPath ...string) (*ConfYaml, error) {
|
||||||
var conf ConfYaml
|
conf := &ConfYaml{}
|
||||||
|
|
||||||
viper.SetConfigType("yaml")
|
viper.SetConfigType("yaml")
|
||||||
viper.AutomaticEnv() // read in environment variables that match
|
viper.AutomaticEnv() // read in environment variables that match
|
||||||
|
|
|
@ -19,8 +19,8 @@ func TestMissingFile(t *testing.T) {
|
||||||
|
|
||||||
type ConfigTestSuite struct {
|
type ConfigTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
ConfGorushDefault ConfYaml
|
ConfGorushDefault *ConfYaml
|
||||||
ConfGorush ConfYaml
|
ConfGorush *ConfYaml
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ConfigTestSuite) SetupTest() {
|
func (suite *ConfigTestSuite) SetupTest() {
|
||||||
|
|
10
main.go
10
main.go
|
@ -194,7 +194,7 @@ func main() {
|
||||||
// send android notification
|
// send android notification
|
||||||
if opts.Android.Enabled {
|
if opts.Android.Enabled {
|
||||||
cfg.Android.Enabled = opts.Android.Enabled
|
cfg.Android.Enabled = opts.Android.Enabled
|
||||||
req := notify.PushNotification{
|
req := ¬ify.PushNotification{
|
||||||
Platform: core.PlatFormAndroid,
|
Platform: core.PlatFormAndroid,
|
||||||
Message: message,
|
Message: message,
|
||||||
Title: title,
|
Title: title,
|
||||||
|
@ -227,7 +227,7 @@ func main() {
|
||||||
// send huawei notification
|
// send huawei notification
|
||||||
if opts.Huawei.Enabled {
|
if opts.Huawei.Enabled {
|
||||||
cfg.Huawei.Enabled = opts.Huawei.Enabled
|
cfg.Huawei.Enabled = opts.Huawei.Enabled
|
||||||
req := notify.PushNotification{
|
req := ¬ify.PushNotification{
|
||||||
Platform: core.PlatFormHuawei,
|
Platform: core.PlatFormHuawei,
|
||||||
Message: message,
|
Message: message,
|
||||||
Title: title,
|
Title: title,
|
||||||
|
@ -264,7 +264,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.Ios.Enabled = opts.Ios.Enabled
|
cfg.Ios.Enabled = opts.Ios.Enabled
|
||||||
req := notify.PushNotification{
|
req := ¬ify.PushNotification{
|
||||||
Platform: core.PlatFormIos,
|
Platform: core.PlatFormIos,
|
||||||
Message: message,
|
Message: message,
|
||||||
Title: title,
|
Title: title,
|
||||||
|
@ -459,7 +459,7 @@ func usage() {
|
||||||
|
|
||||||
// handles pinging the endpoint and returns an error if the
|
// handles pinging the endpoint and returns an error if the
|
||||||
// agent is in an unhealthy state.
|
// agent is in an unhealthy state.
|
||||||
func pinger(cfg config.ConfYaml) error {
|
func pinger(cfg *config.ConfYaml) error {
|
||||||
transport := &http.Transport{
|
transport := &http.Transport{
|
||||||
Dial: (&net.Dialer{
|
Dial: (&net.Dialer{
|
||||||
Timeout: 5 * time.Second,
|
Timeout: 5 * time.Second,
|
||||||
|
@ -481,7 +481,7 @@ func pinger(cfg config.ConfYaml) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createPIDFile(cfg config.ConfYaml) error {
|
func createPIDFile(cfg *config.ConfYaml) error {
|
||||||
if !cfg.Core.PID.Enabled {
|
if !cfg.Core.PID.Enabled {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ func (p *PushNotification) IsTopic() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckMessage for check request message
|
// CheckMessage for check request message
|
||||||
func CheckMessage(req PushNotification) error {
|
func CheckMessage(req *PushNotification) error {
|
||||||
var msg string
|
var msg string
|
||||||
|
|
||||||
// ignore send topic mesaage from FCM
|
// ignore send topic mesaage from FCM
|
||||||
|
@ -195,7 +195,7 @@ func SetProxy(proxy string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckPushConf provide check your yml config.
|
// CheckPushConf provide check your yml config.
|
||||||
func CheckPushConf(cfg config.ConfYaml) error {
|
func CheckPushConf(cfg *config.ConfYaml) error {
|
||||||
if !cfg.Ios.Enabled && !cfg.Android.Enabled && !cfg.Huawei.Enabled {
|
if !cfg.Ios.Enabled && !cfg.Android.Enabled && !cfg.Huawei.Enabled {
|
||||||
return errors.New("Please enable iOS, Android or Huawei config in yml config")
|
return errors.New("Please enable iOS, Android or Huawei config in yml config")
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ func CheckPushConf(cfg config.ConfYaml) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendNotification send notification
|
// SendNotification send notification
|
||||||
func SendNotification(req queue.QueuedMessage, cfg config.ConfYaml) (resp *ResponsePush, err error) {
|
func SendNotification(req queue.QueuedMessage, cfg *config.ConfYaml) (resp *ResponsePush, err error) {
|
||||||
v, ok := req.(*PushNotification)
|
v, ok := req.(*PushNotification)
|
||||||
if !ok {
|
if !ok {
|
||||||
if err = json.Unmarshal(req.Bytes(), &v); err != nil {
|
if err = json.Unmarshal(req.Bytes(), &v); err != nil {
|
||||||
|
@ -243,11 +243,11 @@ func SendNotification(req queue.QueuedMessage, cfg config.ConfYaml) (resp *Respo
|
||||||
|
|
||||||
switch v.Platform {
|
switch v.Platform {
|
||||||
case core.PlatFormIos:
|
case core.PlatFormIos:
|
||||||
resp, err = PushToIOS(*v, cfg)
|
resp, err = PushToIOS(v, cfg)
|
||||||
case core.PlatFormAndroid:
|
case core.PlatFormAndroid:
|
||||||
resp, err = PushToAndroid(*v, cfg)
|
resp, err = PushToAndroid(v, cfg)
|
||||||
case core.PlatFormHuawei:
|
case core.PlatFormHuawei:
|
||||||
resp, err = PushToHuawei(*v, cfg)
|
resp, err = PushToHuawei(v, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Core.FeedbackURL != "" {
|
if cfg.Core.FeedbackURL != "" {
|
||||||
|
@ -263,7 +263,7 @@ func SendNotification(req queue.QueuedMessage, cfg config.ConfYaml) (resp *Respo
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run send notification
|
// Run send notification
|
||||||
var Run = func(cfg config.ConfYaml) func(ctx context.Context, msg queue.QueuedMessage) error {
|
var Run = func(cfg *config.ConfYaml) func(ctx context.Context, msg queue.QueuedMessage) error {
|
||||||
return func(ctx context.Context, msg queue.QueuedMessage) error {
|
return func(ctx context.Context, msg queue.QueuedMessage) error {
|
||||||
_, err := SendNotification(msg, cfg)
|
_, err := SendNotification(msg, cfg)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -52,7 +52,7 @@ type Sound struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitAPNSClient use for initialize APNs Client.
|
// InitAPNSClient use for initialize APNs Client.
|
||||||
func InitAPNSClient(cfg config.ConfYaml) error {
|
func InitAPNSClient(cfg *config.ConfYaml) error {
|
||||||
if cfg.Ios.Enabled {
|
if cfg.Ios.Enabled {
|
||||||
var err error
|
var err error
|
||||||
var authKey *ecdsa.PrivateKey
|
var authKey *ecdsa.PrivateKey
|
||||||
|
@ -141,7 +141,7 @@ func InitAPNSClient(cfg config.ConfYaml) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newApnsClient(cfg config.ConfYaml, certificate tls.Certificate) (*apns2.Client, error) {
|
func newApnsClient(cfg *config.ConfYaml, certificate tls.Certificate) (*apns2.Client, error) {
|
||||||
var client *apns2.Client
|
var client *apns2.Client
|
||||||
|
|
||||||
if cfg.Ios.Production {
|
if cfg.Ios.Production {
|
||||||
|
@ -181,7 +181,7 @@ func newApnsClient(cfg config.ConfYaml, certificate tls.Certificate) (*apns2.Cli
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newApnsTokenClient(cfg config.ConfYaml, token *token.Token) (*apns2.Client, error) {
|
func newApnsTokenClient(cfg *config.ConfYaml, token *token.Token) (*apns2.Client, error) {
|
||||||
var client *apns2.Client
|
var client *apns2.Client
|
||||||
|
|
||||||
if cfg.Ios.Production {
|
if cfg.Ios.Production {
|
||||||
|
@ -217,7 +217,7 @@ func configureHTTP2ConnHealthCheck(h2Transport *http2.Transport) {
|
||||||
h2Transport.PingTimeout = 1 * time.Second
|
h2Transport.PingTimeout = 1 * time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
func iosAlertDictionary(payload *payload.Payload, req PushNotification) *payload.Payload {
|
func iosAlertDictionary(payload *payload.Payload, req *PushNotification) *payload.Payload {
|
||||||
// Alert dictionary
|
// Alert dictionary
|
||||||
|
|
||||||
if len(req.Title) > 0 {
|
if len(req.Title) > 0 {
|
||||||
|
@ -288,7 +288,7 @@ func iosAlertDictionary(payload *payload.Payload, req PushNotification) *payload
|
||||||
// GetIOSNotification use for define iOS notification.
|
// GetIOSNotification use for define iOS notification.
|
||||||
// The iOS Notification Payload
|
// The iOS Notification Payload
|
||||||
// ref: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW1
|
// ref: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW1
|
||||||
func GetIOSNotification(req PushNotification) *apns2.Notification {
|
func GetIOSNotification(req *PushNotification) *apns2.Notification {
|
||||||
notification := &apns2.Notification{
|
notification := &apns2.Notification{
|
||||||
ApnsID: req.ApnsID,
|
ApnsID: req.ApnsID,
|
||||||
Topic: req.Topic,
|
Topic: req.Topic,
|
||||||
|
@ -371,7 +371,7 @@ func GetIOSNotification(req PushNotification) *apns2.Notification {
|
||||||
return notification
|
return notification
|
||||||
}
|
}
|
||||||
|
|
||||||
func getApnsClient(cfg config.ConfYaml, req PushNotification) (client *apns2.Client) {
|
func getApnsClient(cfg *config.ConfYaml, req *PushNotification) (client *apns2.Client) {
|
||||||
if req.Production {
|
if req.Production {
|
||||||
client = ApnsClient.Production()
|
client = ApnsClient.Production()
|
||||||
} else if req.Development {
|
} else if req.Development {
|
||||||
|
@ -387,7 +387,7 @@ func getApnsClient(cfg config.ConfYaml, req PushNotification) (client *apns2.Cli
|
||||||
}
|
}
|
||||||
|
|
||||||
// PushToIOS provide send notification to APNs server.
|
// PushToIOS provide send notification to APNs server.
|
||||||
func PushToIOS(req PushNotification, cfg config.ConfYaml) (resp *ResponsePush, err error) {
|
func PushToIOS(req *PushNotification, cfg *config.ConfYaml) (resp *ResponsePush, err error) {
|
||||||
logx.LogAccess.Debug("Start push notification for iOS")
|
logx.LogAccess.Debug("Start push notification for iOS")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -59,7 +59,7 @@ func TestIOSNotificationStructure(t *testing.T) {
|
||||||
expectBadge := 0
|
expectBadge := 0
|
||||||
message := "Welcome notification Server"
|
message := "Welcome notification Server"
|
||||||
expiration := int64(time.Now().Unix())
|
expiration := int64(time.Now().Unix())
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
ApnsID: test,
|
ApnsID: test,
|
||||||
Topic: test,
|
Topic: test,
|
||||||
Expiration: &expiration,
|
Expiration: &expiration,
|
||||||
|
@ -124,7 +124,7 @@ func TestIOSSoundAndVolume(t *testing.T) {
|
||||||
|
|
||||||
test := "test"
|
test := "test"
|
||||||
message := "Welcome notification Server"
|
message := "Welcome notification Server"
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
ApnsID: test,
|
ApnsID: test,
|
||||||
Topic: test,
|
Topic: test,
|
||||||
Priority: "normal",
|
Priority: "normal",
|
||||||
|
@ -175,7 +175,7 @@ func TestIOSSoundAndVolume(t *testing.T) {
|
||||||
assert.Equal(t, int64(1), soundCritical)
|
assert.Equal(t, int64(1), soundCritical)
|
||||||
assert.Equal(t, "foobar", soundName)
|
assert.Equal(t, "foobar", soundName)
|
||||||
|
|
||||||
req = PushNotification{
|
req = &PushNotification{
|
||||||
ApnsID: test,
|
ApnsID: test,
|
||||||
Topic: test,
|
Topic: test,
|
||||||
Priority: "normal",
|
Priority: "normal",
|
||||||
|
@ -202,7 +202,7 @@ func TestIOSSoundAndVolume(t *testing.T) {
|
||||||
assert.Equal(t, int64(3), soundCritical)
|
assert.Equal(t, int64(3), soundCritical)
|
||||||
assert.Equal(t, "test", soundName)
|
assert.Equal(t, "test", soundName)
|
||||||
|
|
||||||
req = PushNotification{
|
req = &PushNotification{
|
||||||
ApnsID: test,
|
ApnsID: test,
|
||||||
Topic: test,
|
Topic: test,
|
||||||
Priority: "normal",
|
Priority: "normal",
|
||||||
|
@ -227,7 +227,7 @@ func TestIOSSummaryArg(t *testing.T) {
|
||||||
|
|
||||||
test := "test"
|
test := "test"
|
||||||
message := "Welcome notification Server"
|
message := "Welcome notification Server"
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
ApnsID: test,
|
ApnsID: test,
|
||||||
Topic: test,
|
Topic: test,
|
||||||
Priority: "normal",
|
Priority: "normal",
|
||||||
|
@ -261,7 +261,7 @@ func TestSendZeroValueForBadgeKey(t *testing.T) {
|
||||||
|
|
||||||
test := "test"
|
test := "test"
|
||||||
message := "Welcome notification Server"
|
message := "Welcome notification Server"
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
ApnsID: test,
|
ApnsID: test,
|
||||||
Topic: test,
|
Topic: test,
|
||||||
Priority: "normal",
|
Priority: "normal",
|
||||||
|
@ -334,7 +334,7 @@ func TestCheckSilentNotification(t *testing.T) {
|
||||||
var dat map[string]interface{}
|
var dat map[string]interface{}
|
||||||
|
|
||||||
test := "test"
|
test := "test"
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
ApnsID: test,
|
ApnsID: test,
|
||||||
Topic: test,
|
Topic: test,
|
||||||
CollapseID: test,
|
CollapseID: test,
|
||||||
|
@ -381,7 +381,7 @@ func TestAlertStringExample2ForIos(t *testing.T) {
|
||||||
title := "Game Request"
|
title := "Game Request"
|
||||||
body := "Bob wants to play poker"
|
body := "Bob wants to play poker"
|
||||||
actionLocKey := "PLAY"
|
actionLocKey := "PLAY"
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
ApnsID: test,
|
ApnsID: test,
|
||||||
Topic: test,
|
Topic: test,
|
||||||
Priority: "normal",
|
Priority: "normal",
|
||||||
|
@ -424,7 +424,7 @@ func TestAlertStringExample3ForIos(t *testing.T) {
|
||||||
test := "test"
|
test := "test"
|
||||||
badge := 9
|
badge := 9
|
||||||
sound := "bingbong.aiff"
|
sound := "bingbong.aiff"
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
ApnsID: test,
|
ApnsID: test,
|
||||||
Topic: test,
|
Topic: test,
|
||||||
Priority: "normal",
|
Priority: "normal",
|
||||||
|
@ -455,7 +455,7 @@ func TestMessageAndTitle(t *testing.T) {
|
||||||
test := "test"
|
test := "test"
|
||||||
message := "Welcome notification Server"
|
message := "Welcome notification Server"
|
||||||
title := "Welcome notification Server title"
|
title := "Welcome notification Server title"
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
ApnsID: test,
|
ApnsID: test,
|
||||||
Topic: test,
|
Topic: test,
|
||||||
Priority: "normal",
|
Priority: "normal",
|
||||||
|
@ -509,7 +509,7 @@ func TestIOSAlertNotificationStructure(t *testing.T) {
|
||||||
var dat map[string]interface{}
|
var dat map[string]interface{}
|
||||||
|
|
||||||
test := "test"
|
test := "test"
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
Message: "Welcome",
|
Message: "Welcome",
|
||||||
Title: test,
|
Title: test,
|
||||||
Alert: Alert{
|
Alert: Alert{
|
||||||
|
@ -725,7 +725,7 @@ func TestPushToIOS(t *testing.T) {
|
||||||
err = status.InitAppStatus(cfg)
|
err = status.InitAppStatus(cfg)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
Tokens: []string{"11aa01229f15f0f0c52029d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef7", "11aa01229f15f0f0c52029d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef1"},
|
Tokens: []string{"11aa01229f15f0f0c52029d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef7", "11aa01229f15f0f0c52029d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef1"},
|
||||||
Platform: 1,
|
Platform: 1,
|
||||||
Message: "Welcome",
|
Message: "Welcome",
|
||||||
|
@ -745,19 +745,19 @@ func TestApnsHostFromRequest(t *testing.T) {
|
||||||
err = status.InitAppStatus(cfg)
|
err = status.InitAppStatus(cfg)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
Production: true,
|
Production: true,
|
||||||
}
|
}
|
||||||
client := getApnsClient(cfg, req)
|
client := getApnsClient(cfg, req)
|
||||||
assert.Equal(t, apns2.HostProduction, client.Host)
|
assert.Equal(t, apns2.HostProduction, client.Host)
|
||||||
|
|
||||||
req = PushNotification{
|
req = &PushNotification{
|
||||||
Development: true,
|
Development: true,
|
||||||
}
|
}
|
||||||
client = getApnsClient(cfg, req)
|
client = getApnsClient(cfg, req)
|
||||||
assert.Equal(t, apns2.HostDevelopment, client.Host)
|
assert.Equal(t, apns2.HostDevelopment, client.Host)
|
||||||
|
|
||||||
req = PushNotification{}
|
req = &PushNotification{}
|
||||||
cfg.Ios.Production = true
|
cfg.Ios.Production = true
|
||||||
client = getApnsClient(cfg, req)
|
client = getApnsClient(cfg, req)
|
||||||
assert.Equal(t, apns2.HostProduction, client.Host)
|
assert.Equal(t, apns2.HostProduction, client.Host)
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// InitFCMClient use for initialize FCM Client.
|
// InitFCMClient use for initialize FCM Client.
|
||||||
func InitFCMClient(cfg config.ConfYaml, key string) (*fcm.Client, error) {
|
func InitFCMClient(cfg *config.ConfYaml, key string) (*fcm.Client, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if key == "" && cfg.Android.APIKey == "" {
|
if key == "" && cfg.Android.APIKey == "" {
|
||||||
|
@ -35,7 +35,7 @@ func InitFCMClient(cfg config.ConfYaml, key string) (*fcm.Client, error) {
|
||||||
// GetAndroidNotification use for define Android notification.
|
// GetAndroidNotification use for define Android notification.
|
||||||
// HTTP Connection Server Reference for Android
|
// HTTP Connection Server Reference for Android
|
||||||
// https://firebase.google.com/docs/cloud-messaging/http-server-ref
|
// https://firebase.google.com/docs/cloud-messaging/http-server-ref
|
||||||
func GetAndroidNotification(req PushNotification) *fcm.Message {
|
func GetAndroidNotification(req *PushNotification) *fcm.Message {
|
||||||
notification := &fcm.Message{
|
notification := &fcm.Message{
|
||||||
To: req.To,
|
To: req.To,
|
||||||
Condition: req.Condition,
|
Condition: req.Condition,
|
||||||
|
@ -105,7 +105,7 @@ func GetAndroidNotification(req PushNotification) *fcm.Message {
|
||||||
}
|
}
|
||||||
|
|
||||||
// PushToAndroid provide send notification to Android server.
|
// PushToAndroid provide send notification to Android server.
|
||||||
func PushToAndroid(req PushNotification, cfg config.ConfYaml) (resp *ResponsePush, err error) {
|
func PushToAndroid(req *PushNotification, cfg *config.ConfYaml) (resp *ResponsePush, err error) {
|
||||||
logx.LogAccess.Debug("Start push notification for Android")
|
logx.LogAccess.Debug("Start push notification for Android")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -231,7 +231,7 @@ Retry:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func logPush(cfg config.ConfYaml, status, token string, req PushNotification, err error) logx.LogPushEntry {
|
func logPush(cfg *config.ConfYaml, status, token string, req *PushNotification, err error) logx.LogPushEntry {
|
||||||
return logx.LogPush(&logx.InputLog{
|
return logx.LogPush(&logx.InputLog{
|
||||||
ID: req.ID,
|
ID: req.ID,
|
||||||
Status: status,
|
Status: status,
|
||||||
|
|
|
@ -39,7 +39,7 @@ func TestPushToAndroidWrongToken(t *testing.T) {
|
||||||
cfg.Android.Enabled = true
|
cfg.Android.Enabled = true
|
||||||
cfg.Android.APIKey = os.Getenv("ANDROID_API_KEY")
|
cfg.Android.APIKey = os.Getenv("ANDROID_API_KEY")
|
||||||
|
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
Tokens: []string{"aaaaaa", "bbbbb"},
|
Tokens: []string{"aaaaaa", "bbbbb"},
|
||||||
Platform: core.PlatFormAndroid,
|
Platform: core.PlatFormAndroid,
|
||||||
Message: "Welcome",
|
Message: "Welcome",
|
||||||
|
@ -59,7 +59,7 @@ func TestPushToAndroidRightTokenForJSONLog(t *testing.T) {
|
||||||
|
|
||||||
androidToken := os.Getenv("ANDROID_TEST_TOKEN")
|
androidToken := os.Getenv("ANDROID_TEST_TOKEN")
|
||||||
|
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
Tokens: []string{androidToken},
|
Tokens: []string{androidToken},
|
||||||
Platform: core.PlatFormAndroid,
|
Platform: core.PlatFormAndroid,
|
||||||
Message: "Welcome",
|
Message: "Welcome",
|
||||||
|
@ -76,7 +76,7 @@ func TestPushToAndroidRightTokenForStringLog(t *testing.T) {
|
||||||
|
|
||||||
androidToken := os.Getenv("ANDROID_TEST_TOKEN")
|
androidToken := os.Getenv("ANDROID_TEST_TOKEN")
|
||||||
|
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
Tokens: []string{androidToken},
|
Tokens: []string{androidToken},
|
||||||
Platform: core.PlatFormAndroid,
|
Platform: core.PlatFormAndroid,
|
||||||
Message: "Welcome",
|
Message: "Welcome",
|
||||||
|
@ -94,7 +94,7 @@ func TestOverwriteAndroidAPIKey(t *testing.T) {
|
||||||
|
|
||||||
androidToken := os.Getenv("ANDROID_TEST_TOKEN")
|
androidToken := os.Getenv("ANDROID_TEST_TOKEN")
|
||||||
|
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
Tokens: []string{androidToken, "bbbbb"},
|
Tokens: []string{androidToken, "bbbbb"},
|
||||||
Platform: core.PlatFormAndroid,
|
Platform: core.PlatFormAndroid,
|
||||||
Message: "Welcome",
|
Message: "Welcome",
|
||||||
|
@ -110,11 +110,10 @@ func TestOverwriteAndroidAPIKey(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFCMMessage(t *testing.T) {
|
func TestFCMMessage(t *testing.T) {
|
||||||
var req PushNotification
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// the message must specify at least one registration ID
|
// the message must specify at least one registration ID
|
||||||
req = PushNotification{
|
req := &PushNotification{
|
||||||
Message: "Test",
|
Message: "Test",
|
||||||
Tokens: []string{},
|
Tokens: []string{},
|
||||||
}
|
}
|
||||||
|
@ -123,7 +122,7 @@ func TestFCMMessage(t *testing.T) {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
||||||
// the token must not be empty
|
// the token must not be empty
|
||||||
req = PushNotification{
|
req = &PushNotification{
|
||||||
Message: "Test",
|
Message: "Test",
|
||||||
Tokens: []string{""},
|
Tokens: []string{""},
|
||||||
}
|
}
|
||||||
|
@ -132,7 +131,7 @@ func TestFCMMessage(t *testing.T) {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
||||||
// ignore check token length if send topic message
|
// ignore check token length if send topic message
|
||||||
req = PushNotification{
|
req = &PushNotification{
|
||||||
Message: "Test",
|
Message: "Test",
|
||||||
Platform: core.PlatFormAndroid,
|
Platform: core.PlatFormAndroid,
|
||||||
To: "/topics/foo-bar",
|
To: "/topics/foo-bar",
|
||||||
|
@ -142,7 +141,7 @@ func TestFCMMessage(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// "condition": "'dogs' in topics || 'cats' in topics",
|
// "condition": "'dogs' in topics || 'cats' in topics",
|
||||||
req = PushNotification{
|
req = &PushNotification{
|
||||||
Message: "Test",
|
Message: "Test",
|
||||||
Platform: core.PlatFormAndroid,
|
Platform: core.PlatFormAndroid,
|
||||||
Condition: "'dogs' in topics || 'cats' in topics",
|
Condition: "'dogs' in topics || 'cats' in topics",
|
||||||
|
@ -152,7 +151,7 @@ func TestFCMMessage(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// the message may specify at most 1000 registration IDs
|
// the message may specify at most 1000 registration IDs
|
||||||
req = PushNotification{
|
req = &PushNotification{
|
||||||
Message: "Test",
|
Message: "Test",
|
||||||
Platform: core.PlatFormAndroid,
|
Platform: core.PlatFormAndroid,
|
||||||
Tokens: make([]string, 1001),
|
Tokens: make([]string, 1001),
|
||||||
|
@ -164,7 +163,7 @@ func TestFCMMessage(t *testing.T) {
|
||||||
// the message's TimeToLive field must be an integer
|
// the message's TimeToLive field must be an integer
|
||||||
// between 0 and 2419200 (4 weeks)
|
// between 0 and 2419200 (4 weeks)
|
||||||
timeToLive := uint(2419201)
|
timeToLive := uint(2419201)
|
||||||
req = PushNotification{
|
req = &PushNotification{
|
||||||
Message: "Test",
|
Message: "Test",
|
||||||
Platform: core.PlatFormAndroid,
|
Platform: core.PlatFormAndroid,
|
||||||
Tokens: []string{"XXXXXXXXX"},
|
Tokens: []string{"XXXXXXXXX"},
|
||||||
|
@ -176,7 +175,7 @@ func TestFCMMessage(t *testing.T) {
|
||||||
|
|
||||||
// Pass
|
// Pass
|
||||||
timeToLive = uint(86400)
|
timeToLive = uint(86400)
|
||||||
req = PushNotification{
|
req = &PushNotification{
|
||||||
Message: "Test",
|
Message: "Test",
|
||||||
Platform: core.PlatFormAndroid,
|
Platform: core.PlatFormAndroid,
|
||||||
Tokens: []string{"XXXXXXXXX"},
|
Tokens: []string{"XXXXXXXXX"},
|
||||||
|
@ -194,7 +193,7 @@ func TestCheckAndroidMessage(t *testing.T) {
|
||||||
cfg.Android.APIKey = os.Getenv("ANDROID_API_KEY")
|
cfg.Android.APIKey = os.Getenv("ANDROID_API_KEY")
|
||||||
|
|
||||||
timeToLive := uint(2419201)
|
timeToLive := uint(2419201)
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
Tokens: []string{"aaaaaa", "bbbbb"},
|
Tokens: []string{"aaaaaa", "bbbbb"},
|
||||||
Platform: core.PlatFormAndroid,
|
Platform: core.PlatFormAndroid,
|
||||||
Message: "Welcome",
|
Message: "Welcome",
|
||||||
|
@ -207,7 +206,7 @@ func TestCheckAndroidMessage(t *testing.T) {
|
||||||
func TestAndroidNotificationStructure(t *testing.T) {
|
func TestAndroidNotificationStructure(t *testing.T) {
|
||||||
test := "test"
|
test := "test"
|
||||||
timeToLive := uint(100)
|
timeToLive := uint(100)
|
||||||
req := PushNotification{
|
req := &PushNotification{
|
||||||
Tokens: []string{"a", "b"},
|
Tokens: []string{"a", "b"},
|
||||||
Message: "Welcome",
|
Message: "Welcome",
|
||||||
To: test,
|
To: test,
|
||||||
|
@ -250,7 +249,7 @@ func TestAndroidNotificationStructure(t *testing.T) {
|
||||||
assert.Equal(t, 2, notification.Data["b"])
|
assert.Equal(t, 2, notification.Data["b"])
|
||||||
|
|
||||||
// test empty body
|
// test empty body
|
||||||
req = PushNotification{
|
req = &PushNotification{
|
||||||
Tokens: []string{"a", "b"},
|
Tokens: []string{"a", "b"},
|
||||||
To: test,
|
To: test,
|
||||||
Notification: &fcm.Notification{
|
Notification: &fcm.Notification{
|
||||||
|
|
|
@ -36,7 +36,7 @@ func GetPushClient(conf *c.Config) (*client.HMSClient, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitHMSClient use for initialize HMS Client.
|
// InitHMSClient use for initialize HMS Client.
|
||||||
func InitHMSClient(cfg config.ConfYaml, appSecret, appID string) (*client.HMSClient, error) {
|
func InitHMSClient(cfg *config.ConfYaml, appSecret, appID string) (*client.HMSClient, error) {
|
||||||
if appSecret == "" {
|
if appSecret == "" {
|
||||||
return nil, errors.New("Missing Huawei App Secret")
|
return nil, errors.New("Missing Huawei App Secret")
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func InitHMSClient(cfg config.ConfYaml, appSecret, appID string) (*client.HMSCli
|
||||||
// GetHuaweiNotification use for define HMS notification.
|
// GetHuaweiNotification use for define HMS notification.
|
||||||
// HTTP Connection Server Reference for HMS
|
// HTTP Connection Server Reference for HMS
|
||||||
// https://developer.huawei.com/consumer/en/doc/development/HMS-References/push-sendapi
|
// https://developer.huawei.com/consumer/en/doc/development/HMS-References/push-sendapi
|
||||||
func GetHuaweiNotification(req PushNotification) (*model.MessageRequest, error) {
|
func GetHuaweiNotification(req *PushNotification) (*model.MessageRequest, error) {
|
||||||
msgRequest := model.NewNotificationMsgRequest()
|
msgRequest := model.NewNotificationMsgRequest()
|
||||||
|
|
||||||
msgRequest.Message.Android = model.GetDefaultAndroid()
|
msgRequest.Message.Android = model.GetDefaultAndroid()
|
||||||
|
@ -166,7 +166,7 @@ func GetHuaweiNotification(req PushNotification) (*model.MessageRequest, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PushToHuawei provide send notification to Android server.
|
// PushToHuawei provide send notification to Android server.
|
||||||
func PushToHuawei(req PushNotification, cfg config.ConfYaml) (resp *ResponsePush, err error) {
|
func PushToHuawei(req *PushNotification, cfg *config.ConfYaml) (resp *ResponsePush, err error) {
|
||||||
logx.LogAccess.Debug("Start push notification for Huawei")
|
logx.LogAccess.Debug("Start push notification for Huawei")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -63,7 +63,7 @@ func versionHandler(c *gin.Context) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func pushHandler(cfg config.ConfYaml, q *queue.Queue) gin.HandlerFunc {
|
func pushHandler(cfg *config.ConfYaml, q *queue.Queue) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
var form notify.RequestPush
|
var form notify.RequestPush
|
||||||
var msg string
|
var msg string
|
||||||
|
@ -113,7 +113,7 @@ func pushHandler(cfg config.ConfYaml, q *queue.Queue) gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func configHandler(cfg config.ConfYaml) gin.HandlerFunc {
|
func configHandler(cfg *config.ConfYaml) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
c.YAML(http.StatusCreated, cfg)
|
c.YAML(http.StatusCreated, cfg)
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ func StatMiddleware() gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func autoTLSServer(cfg config.ConfYaml, q *queue.Queue) *http.Server {
|
func autoTLSServer(cfg *config.ConfYaml, q *queue.Queue) *http.Server {
|
||||||
m := autocert.Manager{
|
m := autocert.Manager{
|
||||||
Prompt: autocert.AcceptTOS,
|
Prompt: autocert.AcceptTOS,
|
||||||
HostPolicy: autocert.HostWhitelist(cfg.Core.AutoTLS.Host),
|
HostPolicy: autocert.HostWhitelist(cfg.Core.AutoTLS.Host),
|
||||||
|
@ -171,7 +171,7 @@ func autoTLSServer(cfg config.ConfYaml, q *queue.Queue) *http.Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func routerEngine(cfg config.ConfYaml, q *queue.Queue) *gin.Engine {
|
func routerEngine(cfg *config.ConfYaml, q *queue.Queue) *gin.Engine {
|
||||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||||
if cfg.Core.Mode == "debug" {
|
if cfg.Core.Mode == "debug" {
|
||||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||||
|
@ -228,7 +228,7 @@ func routerEngine(cfg config.ConfYaml, q *queue.Queue) *gin.Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
// markFailedNotification adds failure logs for all tokens in push notification
|
// markFailedNotification adds failure logs for all tokens in push notification
|
||||||
func markFailedNotification(cfg config.ConfYaml, notification *notify.PushNotification, reason string) []logx.LogPushEntry {
|
func markFailedNotification(cfg *config.ConfYaml, notification *notify.PushNotification, reason string) []logx.LogPushEntry {
|
||||||
logx.LogError.Error(reason)
|
logx.LogError.Error(reason)
|
||||||
logs := make([]logx.LogPushEntry, 0)
|
logs := make([]logx.LogPushEntry, 0)
|
||||||
for _, token := range notification.Tokens {
|
for _, token := range notification.Tokens {
|
||||||
|
@ -248,7 +248,7 @@ func markFailedNotification(cfg config.ConfYaml, notification *notify.PushNotifi
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleNotification add notification to queue list.
|
// HandleNotification add notification to queue list.
|
||||||
func handleNotification(ctx context.Context, cfg config.ConfYaml, req notify.RequestPush, q *queue.Queue) (int, []logx.LogPushEntry) {
|
func handleNotification(ctx context.Context, cfg *config.ConfYaml, req notify.RequestPush, q *queue.Queue) (int, []logx.LogPushEntry) {
|
||||||
var count int
|
var count int
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
newNotification := []*notify.PushNotification{}
|
newNotification := []*notify.PushNotification{}
|
||||||
|
@ -283,7 +283,7 @@ func handleNotification(ctx context.Context, cfg config.ConfYaml, req notify.Req
|
||||||
}
|
}
|
||||||
|
|
||||||
if core.IsLocalQueue(core.Queue(cfg.Queue.Engine)) && cfg.Core.Sync {
|
if core.IsLocalQueue(core.Queue(cfg.Queue.Engine)) && cfg.Core.Sync {
|
||||||
func(msg *notify.PushNotification, cfg config.ConfYaml) {
|
func(msg *notify.PushNotification, cfg *config.ConfYaml) {
|
||||||
q.QueueTask(func(ctx context.Context) error {
|
q.QueueTask(func(ctx context.Context) error {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
resp, err := notify.SendNotification(msg, cfg)
|
resp, err := notify.SendNotification(msg, cfg)
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// RunHTTPServer provide run http or https protocol.
|
// RunHTTPServer provide run http or https protocol.
|
||||||
func RunHTTPServer(ctx context.Context, cfg config.ConfYaml, q *queue.Queue, s ...*http.Server) (err error) {
|
func RunHTTPServer(ctx context.Context, cfg *config.ConfYaml, q *queue.Queue, s ...*http.Server) (err error) {
|
||||||
if !cfg.Core.Enabled {
|
if !cfg.Core.Enabled {
|
||||||
logx.LogAccess.Debug("httpd server is disabled.")
|
logx.LogAccess.Debug("httpd server is disabled.")
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// RunHTTPServer provide run http or https protocol.
|
// RunHTTPServer provide run http or https protocol.
|
||||||
func RunHTTPServer(ctx context.Context, cfg config.ConfYaml, q *queue.Queue, s ...*http.Server) (err error) {
|
func RunHTTPServer(ctx context.Context, cfg *config.ConfYaml, q *queue.Queue, s ...*http.Server) (err error) {
|
||||||
var server *http.Server
|
var server *http.Server
|
||||||
|
|
||||||
if !cfg.Core.Enabled {
|
if !cfg.Core.Enabled {
|
||||||
|
@ -79,7 +79,7 @@ func RunHTTPServer(ctx context.Context, cfg config.ConfYaml, q *queue.Queue, s .
|
||||||
return startServer(ctx, server, cfg)
|
return startServer(ctx, server, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func listenAndServe(ctx context.Context, s *http.Server, cfg config.ConfYaml) error {
|
func listenAndServe(ctx context.Context, s *http.Server, cfg *config.ConfYaml) error {
|
||||||
var g errgroup.Group
|
var g errgroup.Group
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
select {
|
select {
|
||||||
|
@ -99,7 +99,7 @@ func listenAndServe(ctx context.Context, s *http.Server, cfg config.ConfYaml) er
|
||||||
return g.Wait()
|
return g.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func listenAndServeTLS(ctx context.Context, s *http.Server, cfg config.ConfYaml) error {
|
func listenAndServeTLS(ctx context.Context, s *http.Server, cfg *config.ConfYaml) error {
|
||||||
var g errgroup.Group
|
var g errgroup.Group
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
select {
|
select {
|
||||||
|
@ -119,7 +119,7 @@ func listenAndServeTLS(ctx context.Context, s *http.Server, cfg config.ConfYaml)
|
||||||
return g.Wait()
|
return g.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func startServer(ctx context.Context, s *http.Server, cfg config.ConfYaml) error {
|
func startServer(ctx context.Context, s *http.Server, cfg *config.ConfYaml) error {
|
||||||
if s.TLSConfig == nil {
|
if s.TLSConfig == nil {
|
||||||
return listenAndServe(ctx, s, cfg)
|
return listenAndServe(ctx, s, cfg)
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ func TestMain(m *testing.M) {
|
||||||
m.Run()
|
m.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func initTest() config.ConfYaml {
|
func initTest() *config.ConfYaml {
|
||||||
cfg, _ := config.LoadConf()
|
cfg, _ := config.LoadConf()
|
||||||
cfg.Core.Mode = "test"
|
cfg.Core.Mode = "test"
|
||||||
return cfg
|
return cfg
|
||||||
|
|
|
@ -20,14 +20,14 @@ import (
|
||||||
|
|
||||||
// Server is used to implement gorush grpc server.
|
// Server is used to implement gorush grpc server.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
cfg config.ConfYaml
|
cfg *config.ConfYaml
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
// statusMap stores the serving status of the services this Server monitors.
|
// statusMap stores the serving status of the services this Server monitors.
|
||||||
statusMap map[string]proto.HealthCheckResponse_ServingStatus
|
statusMap map[string]proto.HealthCheckResponse_ServingStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer returns a new Server.
|
// NewServer returns a new Server.
|
||||||
func NewServer(cfg config.ConfYaml) *Server {
|
func NewServer(cfg *config.ConfYaml) *Server {
|
||||||
return &Server{
|
return &Server{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
statusMap: make(map[string]proto.HealthCheckResponse_ServingStatus),
|
statusMap: make(map[string]proto.HealthCheckResponse_ServingStatus),
|
||||||
|
@ -110,7 +110,7 @@ func (s *Server) Send(ctx context.Context, in *proto.NotificationRequest) (*prot
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunGRPCServer run gorush grpc server
|
// RunGRPCServer run gorush grpc server
|
||||||
func RunGRPCServer(ctx context.Context, cfg config.ConfYaml) error {
|
func RunGRPCServer(ctx context.Context, cfg *config.ConfYaml) error {
|
||||||
if !cfg.GRPC.Enabled {
|
if !cfg.GRPC.Enabled {
|
||||||
logx.LogAccess.Info("gRPC server is disabled.")
|
logx.LogAccess.Info("gRPC server is disabled.")
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
const gRPCAddr = "localhost:9000"
|
const gRPCAddr = "localhost:9000"
|
||||||
|
|
||||||
func initTest() config.ConfYaml {
|
func initTest() *config.ConfYaml {
|
||||||
cfg, _ := config.LoadConf()
|
cfg, _ := config.LoadConf()
|
||||||
cfg.Core.Mode = "test"
|
cfg.Core.Mode = "test"
|
||||||
return cfg
|
return cfg
|
||||||
|
|
|
@ -52,7 +52,7 @@ type HuaweiStatus struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitAppStatus for initialize app status
|
// InitAppStatus for initialize app status
|
||||||
func InitAppStatus(conf config.ConfYaml) error {
|
func InitAppStatus(conf *config.ConfYaml) error {
|
||||||
logx.LogAccess.Info("Init App Status Engine as ", conf.Stat.Engine)
|
logx.LogAccess.Info("Init App Status Engine as ", conf.Stat.Engine)
|
||||||
switch conf.Stat.Engine {
|
switch conf.Stat.Engine {
|
||||||
case "memory":
|
case "memory":
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// New func implements the storage interface for gorush (https://github.com/appleboy/gorush)
|
// New func implements the storage interface for gorush (https://github.com/appleboy/gorush)
|
||||||
func New(config config.ConfYaml) *Storage {
|
func New(config *config.ConfYaml) *Storage {
|
||||||
return &Storage{
|
return &Storage{
|
||||||
config: config,
|
config: config,
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ func New(config config.ConfYaml) *Storage {
|
||||||
|
|
||||||
// Storage is interface structure
|
// Storage is interface structure
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
config config.ConfYaml
|
config *config.ConfYaml
|
||||||
opts badger.Options
|
opts badger.Options
|
||||||
name string
|
name string
|
||||||
db *badger.DB
|
db *badger.DB
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// New func implements the storage interface for gorush (https://github.com/appleboy/gorush)
|
// New func implements the storage interface for gorush (https://github.com/appleboy/gorush)
|
||||||
func New(config config.ConfYaml) *Storage {
|
func New(config *config.ConfYaml) *Storage {
|
||||||
return &Storage{
|
return &Storage{
|
||||||
config: config,
|
config: config,
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ func New(config config.ConfYaml) *Storage {
|
||||||
|
|
||||||
// Storage is interface structure
|
// Storage is interface structure
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
config config.ConfYaml
|
config *config.ConfYaml
|
||||||
db *storm.DB
|
db *storm.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// New func implements the storage interface for gorush (https://github.com/appleboy/gorush)
|
// New func implements the storage interface for gorush (https://github.com/appleboy/gorush)
|
||||||
func New(config config.ConfYaml) *Storage {
|
func New(config *config.ConfYaml) *Storage {
|
||||||
return &Storage{
|
return &Storage{
|
||||||
config: config,
|
config: config,
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func New(config config.ConfYaml) *Storage {
|
||||||
|
|
||||||
// Storage is interface structure
|
// Storage is interface structure
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
config config.ConfYaml
|
config *config.ConfYaml
|
||||||
db *buntdb.DB
|
db *buntdb.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ func (s *Storage) getLevelDB(key string, count *int64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New func implements the storage interface for gorush (https://github.com/appleboy/gorush)
|
// New func implements the storage interface for gorush (https://github.com/appleboy/gorush)
|
||||||
func New(config config.ConfYaml) *Storage {
|
func New(config *config.ConfYaml) *Storage {
|
||||||
return &Storage{
|
return &Storage{
|
||||||
config: config,
|
config: config,
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func New(config config.ConfYaml) *Storage {
|
||||||
|
|
||||||
// Storage is interface structure
|
// Storage is interface structure
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
config config.ConfYaml
|
config *config.ConfYaml
|
||||||
db *leveldb.DB
|
db *leveldb.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// New func implements the storage interface for gorush (https://github.com/appleboy/gorush)
|
// New func implements the storage interface for gorush (https://github.com/appleboy/gorush)
|
||||||
func New(config config.ConfYaml) *Storage {
|
func New(config *config.ConfYaml) *Storage {
|
||||||
return &Storage{
|
return &Storage{
|
||||||
config: config,
|
config: config,
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ func (s *Storage) getInt64(key string, count *int64) {
|
||||||
|
|
||||||
// Storage is interface structure
|
// Storage is interface structure
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
config config.ConfYaml
|
config *config.ConfYaml
|
||||||
client *redis.Client
|
client *redis.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue