-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilities.go
More file actions
38 lines (33 loc) · 786 Bytes
/
utilities.go
File metadata and controls
38 lines (33 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package greenapi
import (
"fmt"
"net/url"
"strconv"
"strings"
)
func ValidateChatId(chatId ...string) error {
for _, chat := range chatId {
// Check for lid
_, err := strconv.Atoi(chat)
if err != nil {
// Not lid, using old check
if !strings.HasSuffix(chat, "@c.us") && !strings.HasSuffix(chat, "@g.us") {
return fmt.Errorf("chatId must end with \"@c.us\" or \"@g.us\"\ngot %s instead", chat)
}
}
}
return nil
}
func ValidateMessageLength(message string, limit int) error {
if len(message) > limit {
return fmt.Errorf("length of the message exceeds the limit of %v", limit)
}
return nil
}
func ValidateURL(link string) error {
_, err := url.ParseRequestURI(link)
if err != nil {
return fmt.Errorf("error parsing URL: %w", err)
}
return nil
}