File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ require (
1414 github.com/palantir/stacktrace v0.0.0-20161112013806-78658fd2d177
1515 github.com/rs/zerolog v1.26.1
1616 github.com/swaggo/swag v1.8.2
17+ github.com/thedevsaddam/govalidator v1.9.10
1718 go.opentelemetry.io/otel v1.7.0
1819 go.opentelemetry.io/otel/trace v1.7.0
1920 gorm.io/driver/postgres v1.3.7
Original file line number Diff line number Diff line change @@ -207,6 +207,8 @@ github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2/go.mod h1:lKJPbtWzJ9J
207207github.com/swaggo/swag v1.8.1 /go.mod h1:ugemnJsPZm/kRwFUnzBlbHRd0JY9zE1M4F+uy2pAaPQ =
208208github.com/swaggo/swag v1.8.2 h1:D4aBiVS2a65zhyk3WFqOUz7Rz0sOaUcgeErcid5uGL4 =
209209github.com/swaggo/swag v1.8.2 /go.mod h1:jMLeXOOmYyjk8PvHTsXBdrubsNd9gUJTTCzL5iBnseg =
210+ github.com/thedevsaddam/govalidator v1.9.10 h1:m3dLRbSZ5Hts3VUWYe+vxLMG+FdyQuWOjzTeQRiMCvU =
211+ github.com/thedevsaddam/govalidator v1.9.10 /go.mod h1:Ilx8u7cg5g3LXbSS943cx5kczyNuUn7LH/cK5MYuE90 =
210212github.com/urfave/cli/v2 v2.3.0 /go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI =
211213github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw =
212214github.com/valyala/bytebufferpool v1.0.0 /go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc =
Original file line number Diff line number Diff line change 11package events
22
3+ import "github.com/google/uuid"
4+
35// EventTypeMessageAPISent is emitted when a new message is sent
46const EventTypeMessageAPISent = "message.api.sent"
57
68// MessageAPISent is the payload of the EventTypeMessageSent event
79type MessageAPISent struct {
8- From string `json:"from"`
9- To string `json:"to"`
10- Content string `json:"content"`
10+ ID uuid.UUID `json:"id"`
11+ From string `json:"from"`
12+ To string `json:"to"`
13+ Content string `json:"content"`
1114}
Original file line number Diff line number Diff line change 77
88 "github.com/NdoleStudio/http-sms-manager/pkg/requests"
99 "github.com/NdoleStudio/http-sms-manager/pkg/telemetry"
10+ "github.com/thedevsaddam/govalidator"
1011)
1112
1213// MessageHandlerValidator validates models used in handlers.MessageHandler
@@ -27,6 +28,33 @@ func NewMessageHandlerValidator(
2728}
2829
2930// ValidateMessageSend validates the requests.MessageSend request
30- func (v MessageHandlerValidator ) ValidateMessageSend (ctx context.Context , request requests.MessageSend ) url.Values {
31- return nil
31+ func (validator MessageHandlerValidator ) ValidateMessageSend (ctx context.Context , request requests.MessageSend ) url.Values {
32+ v := govalidator .New (govalidator.Options {
33+ Data : & request ,
34+ Rules : govalidator.MapData {
35+ "to" : []string {
36+ "required" ,
37+ "regex:^\\ +[1-9]\\ d{1,14}$" ,
38+ },
39+ "from" : []string {
40+ "required" ,
41+ "regex:^\\ +[1-9]\\ d{1,14}$" ,
42+ },
43+ "content" : []string {
44+ "required" ,
45+ "min:1" ,
46+ "max:500" ,
47+ },
48+ },
49+ Messages : map [string ][]string {
50+ "to" : {
51+ "regex: The 'to' field must be a valid E.164 phone number: https://en.wikipedia.org/wiki/E.164" ,
52+ },
53+ "from" : {
54+ "regex: The 'from' field must be a valid E.164 phone number: https://en.wikipedia.org/wiki/E.164" ,
55+ },
56+ },
57+ })
58+
59+ return v .Validate ()
3260}
You can’t perform that action at this time.
0 commit comments