Permalink
Browse files

introduce MultiCommentService

  • Loading branch information...
1 parent 0cdec2a commit 4145e5e96cf9f80e477170296b49f57f250a352b @haya14busa committed Dec 12, 2016
Showing with 35 additions and 0 deletions.
  1. +35 −0 comment.go
View
@@ -0,0 +1,35 @@
+package reviewdog
+
+var _ BulkCommentService = &multiCommentService{}
+
+type multiCommentService struct {
+ services []CommentService
+}
+
+func (m *multiCommentService) Post(c *Comment) error {
+ for _, cs := range m.services {
+ if err := cs.Post(c); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+func (m *multiCommentService) Flash() error {
+ for _, cs := range m.services {
+ if bulk, ok := cs.(BulkCommentService); ok {
+ if err := bulk.Flash(); err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}
+
+// MultiCommentService creates a comment service that duplicates its post to
+// all the provided comment services.
+func MultiCommentService(services ...CommentService) CommentService {
+ s := make([]CommentService, len(services))
+ copy(s, services)
+ return &multiCommentService{services: s}
+}

0 comments on commit 4145e5e

Please sign in to comment.