Skip to content

Commit

Permalink
fix: use any instead of using interface{} for RecieverSelectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Manish Dangi committed Oct 15, 2024
1 parent f7aa6c0 commit 9774d00
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion core/notification/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Notification struct {
ValidDuration time.Duration `json:"valid_duration"`
Template string `json:"template"`
UniqueKey string `json:"unique_key"`
ReceiverSelectors []map[string]interface{} `json:"receiver_selectors"`
ReceiverSelectors []map[string]any `json:"receiver_selectors"`
CreatedAt time.Time `json:"created_at"`

// won't be stored in notification table, only to propagate this to notification_subscriber
Expand Down
2 changes: 1 addition & 1 deletion core/notification/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestNotification_Validate(t *testing.T) {
Labels: map[string]string{
"receiver_id": "2",
},
ReceiverSelectors: []map[string]interface{}{
ReceiverSelectors: []map[string]any{
{
"varkey1": "value1",
},
Expand Down
4 changes: 2 additions & 2 deletions core/notification/router_receiver_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *RouterReceiverService) PrepareMetaMessages(ctx context.Context, n Notif
return metaMessages, notificationLogs, nil
}

func (s *RouterReceiverService) handleConfigCase(ctx context.Context, selectors []map[string]interface{}) ([]receiver.Receiver, map[uint64]map[string]interface{}, error) {
func (s *RouterReceiverService) handleConfigCase(ctx context.Context, selectors []map[string]any) ([]receiver.Receiver, map[uint64]map[string]interface{}, error) {
var receiverIDs []uint64
userConfigs := make(map[uint64]map[string]interface{})

Expand Down Expand Up @@ -123,7 +123,7 @@ func (s *RouterReceiverService) handleConfigCase(ctx context.Context, selectors
return rcvs, userConfigs, nil
}

func (s *RouterReceiverService) handleIDOnlyCase(ctx context.Context, selectors []map[string]interface{}) ([]receiver.Receiver, error) {
func (s *RouterReceiverService) handleIDOnlyCase(ctx context.Context, selectors []map[string]any) ([]receiver.Receiver, error) {
convertedSelectors := make([]map[string]string, len(selectors))
for i, selector := range selectors {
convertedSelectors[i] = make(map[string]string)
Expand Down
2 changes: 1 addition & 1 deletion core/notification/router_receiver_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestRouterReceiverService_PrepareMetaMessage(t *testing.T) {
{
name: "should return error if number of receiver selector is more than threshold",
n: notification.Notification{
ReceiverSelectors: []map[string]interface{}{
ReceiverSelectors: []map[string]any{
{
"k1": "v1",
},
Expand Down
8 changes: 4 additions & 4 deletions internal/api/v1beta1/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

const notificationAPIScope = "notification_api"

func (s *GRPCServer) validatePostNotificationPayload(receiverSelectors []map[string]interface{}, labels map[string]string) error {
func (s *GRPCServer) validatePostNotificationPayload(receiverSelectors []map[string]any, labels map[string]string) error {
if len(receiverSelectors) == 0 && len(labels) == 0 {
return errors.ErrInvalid.WithMsgf("receivers or labels must be provided")
}
Expand All @@ -31,16 +31,16 @@ func (s *GRPCServer) validatePostNotificationPayload(receiverSelectors []map[str
return nil
}

func (s *GRPCServer) parseReceivers(pbSelectors []*structpb.Struct) ([]map[string]interface{}, error) {
var receiverSelectors []map[string]interface{}
func (s *GRPCServer) parseReceivers(pbSelectors []*structpb.Struct) ([]map[string]any, error) {
var receiverSelectors []map[string]any

for _, pbSelector := range pbSelectors {
selector := make(map[string]interface{})
for k, v := range pbSelector.AsMap() {
if k == "config" {
configMap, ok := v.(map[string]interface{})
if !ok {
return nil, errors.ErrInvalid.WithMsgf("invalid config format, expected map[string]interface{}")
return nil, errors.ErrInvalid.WithMsgf("invalid config format, expected map[string]any")
}
selector[k] = configMap
} else {
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v1beta1/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestGRPCServer_ListNotifications(t *testing.T) {
"data-key": "data-value",
},
Labels: map[string]string{},
ReceiverSelectors: []map[string]interface{}{},
ReceiverSelectors: []map[string]any{},
},
}

Expand Down
2 changes: 1 addition & 1 deletion internal/store/model/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (n *Notification) FromDomain(d notification.Notification) {
func (n *Notification) ToDomain() *notification.Notification {
receiverSelectors := n.ReceiverSelectors
if receiverSelectors == nil {
receiverSelectors = []map[string]interface{}{}
receiverSelectors = []map[string]any{}
}
return &notification.Notification{
ID: n.ID,
Expand Down
2 changes: 1 addition & 1 deletion internal/store/postgres/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (r *NotificationRepository) List(ctx context.Context, flt notification.Filt

// Always ensure ReceiverSelectors is initialized
if notificationDomain.ReceiverSelectors == nil {
notificationDomain.ReceiverSelectors = []map[string]interface{}{}
notificationDomain.ReceiverSelectors = []map[string]any{}
}

notificationsDomain = append(notificationsDomain, *notificationDomain)
Expand Down
12 changes: 6 additions & 6 deletions internal/store/postgres/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (s *NotificationRepositoryTestSuite) TestList() {
"label-key": "label-value",
},
Template: "",
ReceiverSelectors: []map[string]interface{}{
ReceiverSelectors: []map[string]any{
{
"team": "gotocompany-infra",
"severity": "WARNING",
Expand Down Expand Up @@ -256,7 +256,7 @@ func (s *NotificationRepositoryTestSuite) TestList() {
Template: "",
ValidDuration: 0,
UniqueKey: "",
ReceiverSelectors: []map[string]interface{}{},
ReceiverSelectors: []map[string]any{},
},
{
ID: "10911",
Expand All @@ -269,7 +269,7 @@ func (s *NotificationRepositoryTestSuite) TestList() {
ValidDuration: time.Duration(0),
Template: "expiry-alert",
UniqueKey: "",
ReceiverSelectors: []map[string]interface{}{},
ReceiverSelectors: []map[string]any{},
},
},
},
Expand All @@ -290,7 +290,7 @@ func (s *NotificationRepositoryTestSuite) TestList() {
ValidDuration: time.Duration(0),
Template: "expiry-alert",
UniqueKey: "",
ReceiverSelectors: []map[string]interface{}{},
ReceiverSelectors: []map[string]any{},
},
},
},
Expand All @@ -311,7 +311,7 @@ func (s *NotificationRepositoryTestSuite) TestList() {
},
Labels: map[string]string{"label-key": "label-value"},
Template: "",
ReceiverSelectors: []map[string]interface{}{}, // Initialize this
ReceiverSelectors: []map[string]any{},
UniqueKey: "",
ValidDuration: 0,
},
Expand All @@ -326,7 +326,7 @@ func (s *NotificationRepositoryTestSuite) TestList() {
"label-key": "label-value",
},
Template: "",
ReceiverSelectors: []map[string]interface{}{
ReceiverSelectors: []map[string]any{
{
"team": "gotocompany-infra",
"severity": "WARNING",
Expand Down
2 changes: 1 addition & 1 deletion pkg/pgc/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (a ListString) Value() (driver.Value, error) {
return json.Marshal(a)
}

type ListStringAnyMap []map[string]interface{}
type ListStringAnyMap []map[string]any

func (m *ListStringAnyMap) Scan(value interface{}) error {
if value == nil {
Expand Down

0 comments on commit 9774d00

Please sign in to comment.