@@ -76,7 +76,7 @@ func (c *Castle) Filter(ctx context.Context, req *Request) (RecommendedAction, e
76
76
Email : req .User .Email ,
77
77
Username : req .User .Name ,
78
78
}
79
- r := & castleFilterAPIRequest {
79
+ r := & FilterRequest {
80
80
Type : req .Event .EventType ,
81
81
Name : req .Event .Name ,
82
82
Status : req .Event .EventStatus ,
@@ -86,7 +86,7 @@ func (c *Castle) Filter(ctx context.Context, req *Request) (RecommendedAction, e
86
86
Properties : req .Properties ,
87
87
CreatedAt : time .Now (),
88
88
}
89
- return c . sendCall (ctx , r , FilterEndpoint )
89
+ return sendCall (ctx , c , r , FilterEndpoint )
90
90
}
91
91
92
92
// Risk sends a risk request to castle.io
@@ -98,7 +98,7 @@ func (c *Castle) Risk(ctx context.Context, req *Request) (RecommendedAction, err
98
98
if req .Context == nil {
99
99
return RecommendedActionNone , errors .New ("request.Context cannot be nil" )
100
100
}
101
- r := & castleRiskAPIRequest {
101
+ r := & RiskRequest {
102
102
Type : req .Event .EventType ,
103
103
Name : req .Event .Name ,
104
104
Status : req .Event .EventStatus ,
@@ -108,10 +108,10 @@ func (c *Castle) Risk(ctx context.Context, req *Request) (RecommendedAction, err
108
108
Properties : req .Properties ,
109
109
CreatedAt : time .Now (),
110
110
}
111
- return c . sendCall (ctx , r , RiskEndpoint )
111
+ return sendCall (ctx , c , r , RiskEndpoint )
112
112
}
113
113
114
- func ( c * Castle ) sendCall (ctx context.Context , r castleAPIRequest , url string ) (_ RecommendedAction , err error ) {
114
+ func sendCall [ Req castleAPIRequest ] (ctx context.Context , c * Castle , r Req , url string ) (_ RecommendedAction , err error ) {
115
115
defer func () {
116
116
if ! c .metricsEnabled {
117
117
return
@@ -126,12 +126,7 @@ func (c *Castle) sendCall(ctx context.Context, r castleAPIRequest, url string) (
126
126
127
127
b := new (bytes.Buffer )
128
128
129
- switch request := r .(type ) {
130
- case * castleRiskAPIRequest :
131
- err = json .NewEncoder (b ).Encode (request )
132
- case * castleFilterAPIRequest :
133
- err = json .NewEncoder (b ).Encode (request )
134
- }
129
+ err = json .NewEncoder (b ).Encode (r )
135
130
if err != nil {
136
131
return RecommendedActionNone , err
137
132
}
0 commit comments