|
| 1 | +package common |
| 2 | + |
| 3 | +func cloneConfig(src *Config) *Config { |
| 4 | + if src == nil { |
| 5 | + return nil |
| 6 | + } |
| 7 | + |
| 8 | + // Create a new Config and copy all fields |
| 9 | + cloned := &Config{ |
| 10 | + Name: src.Name, |
| 11 | + Host: src.Host, |
| 12 | + Port: src.Port, |
| 13 | + Alert: cloneAlertConfig(src.Alert), |
| 14 | + Queue: cloneQueueConfig(src.Queue), |
| 15 | + } |
| 16 | + |
| 17 | + return cloned |
| 18 | +} |
| 19 | + |
| 20 | +// Helper function to deep clone the AlertConfig struct |
| 21 | +func cloneAlertConfig(src AlertConfig) AlertConfig { |
| 22 | + return AlertConfig{ |
| 23 | + DebugBody: src.DebugBody, |
| 24 | + Slack: cloneSlackConfig(src.Slack), |
| 25 | + Telegram: cloneTelegramConfig(src.Telegram), |
| 26 | + Email: cloneEmailConfig(src.Email), |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +// Helper function to deep clone the SlackConfig struct |
| 31 | +func cloneSlackConfig(src SlackConfig) SlackConfig { |
| 32 | + return SlackConfig{ |
| 33 | + Enable: src.Enable, |
| 34 | + Token: src.Token, |
| 35 | + ChannelID: src.ChannelID, |
| 36 | + TemplatePath: src.TemplatePath, |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +// Helper function to deep clone the TelegramConfig struct |
| 41 | +func cloneTelegramConfig(src TelegramConfig) TelegramConfig { |
| 42 | + return TelegramConfig{ |
| 43 | + Enable: src.Enable, |
| 44 | + BotToken: src.BotToken, |
| 45 | + ChatID: src.ChatID, |
| 46 | + TemplatePath: src.TemplatePath, |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +// Helper function to deep clone the EmailConfig struct |
| 51 | +func cloneEmailConfig(src EmailConfig) EmailConfig { |
| 52 | + return EmailConfig{ |
| 53 | + Enable: src.Enable, |
| 54 | + SMTPHost: src.SMTPHost, |
| 55 | + SMTPPort: src.SMTPPort, |
| 56 | + Username: src.Username, |
| 57 | + Password: src.Password, |
| 58 | + To: src.To, |
| 59 | + Subject: src.Subject, |
| 60 | + TemplatePath: src.TemplatePath, |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +// Helper function to deep clone the QueueConfig struct |
| 65 | +func cloneQueueConfig(src QueueConfig) QueueConfig { |
| 66 | + return QueueConfig{ |
| 67 | + Enable: src.Enable, |
| 68 | + SNS: cloneSNSConfig(src.SNS), |
| 69 | + SQS: cloneSQSConfig(src.SQS), |
| 70 | + PubSub: clonePubSubConfig(src.PubSub), |
| 71 | + AzBus: cloneAzBusConfig(src.AzBus), |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +// Helper function to deep clone the SNSConfig struct |
| 76 | +func cloneSNSConfig(src SNSConfig) SNSConfig { |
| 77 | + return SNSConfig{ |
| 78 | + Enable: src.Enable, |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +// Helper function to deep clone the SQSConfig struct |
| 83 | +func cloneSQSConfig(src SQSConfig) SQSConfig { |
| 84 | + return SQSConfig{ |
| 85 | + Enable: src.Enable, |
| 86 | + QueueURL: src.QueueURL, |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +// Helper function to deep clone the PubSubConfig struct |
| 91 | +func clonePubSubConfig(src PubSubConfig) PubSubConfig { |
| 92 | + return PubSubConfig{ |
| 93 | + Enable: src.Enable, |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +// Helper function to deep clone the AzBusConfig struct |
| 98 | +func cloneAzBusConfig(src AzBusConfig) AzBusConfig { |
| 99 | + return AzBusConfig{ |
| 100 | + Enable: src.Enable, |
| 101 | + } |
| 102 | +} |
0 commit comments