mirror of
https://github.com/TwiN/gatus.git
synced 2025-01-03 12:39:39 +01:00
style(alerting): Add comments and rename character bytes constant
This commit is contained in:
parent
4b339bca37
commit
2fb807632c
@ -66,6 +66,7 @@ func (provider *AlertProvider) Send(endpoint *core.Endpoint, alert *alert.Alert,
|
|||||||
if config.ServerURL == "" {
|
if config.ServerURL == "" {
|
||||||
config.ServerURL = defaultHomeserverURL
|
config.ServerURL = defaultHomeserverURL
|
||||||
}
|
}
|
||||||
|
// The Matrix endpoint requires a unique transaction ID for each event sent
|
||||||
txnId := randStringBytes(24)
|
txnId := randStringBytes(24)
|
||||||
request, err := http.NewRequest(
|
request, err := http.NewRequest(
|
||||||
http.MethodPut,
|
http.MethodPut,
|
||||||
@ -173,14 +174,16 @@ func (provider *AlertProvider) getConfigForGroup(group string) MatrixProviderCon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
||||||
|
|
||||||
func randStringBytes(n int) string {
|
func randStringBytes(n int) string {
|
||||||
|
// All the compatible characters to use in a transaction ID
|
||||||
|
const availableCharacterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||||
|
|
||||||
b := make([]byte, n)
|
b := make([]byte, n)
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
for i := range b {
|
for i := range b {
|
||||||
b[i] = letterBytes[rand.Intn(len(letterBytes))]
|
b[i] = availableCharacterBytes[rand.Intn(len(availableCharacterBytes))]
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user