Add missing GRPC data field (#412)

* feat(grpc): add support for data field in request body

* docs: update Readme with embedmd
This commit is contained in:
H 2019-05-21 08:10:32 +02:00 committed by Bo-Yi Wu
parent 33cddfa421
commit 201413967c
7 changed files with 183 additions and 1700 deletions

View File

@ -839,6 +839,7 @@ package main
import ( import (
"context" "context"
structpb "github.com/golang/protobuf/ptypes/struct"
"log" "log"
"github.com/appleboy/gorush/rpc/proto" "github.com/appleboy/gorush/rpc/proto"
@ -873,6 +874,16 @@ func main() {
LocKey: "Test loc key", LocKey: "Test loc key",
LocArgs: []string{"test", "test"}, LocArgs: []string{"test", "test"},
}, },
Data: &structpb.Struct{
Fields: map[string]*structpb.Value{
"key1": {
Kind: &structpb.Value_StringValue{StringValue: "welcome"},
},
"key2": {
Kind: &structpb.Value_NumberValue{NumberValue: 2},
},
},
},
}) })
if err != nil { if err != nil {
log.Fatalf("could not greet: %v", err) log.Fatalf("could not greet: %v", err)
@ -929,6 +940,7 @@ package main
import ( import (
"context" "context"
structpb "github.com/golang/protobuf/ptypes/struct"
"log" "log"
"github.com/appleboy/gorush/rpc/proto" "github.com/appleboy/gorush/rpc/proto"
@ -963,6 +975,16 @@ func main() {
LocKey: "Test loc key", LocKey: "Test loc key",
LocArgs: []string{"test", "test"}, LocArgs: []string{"test", "test"},
}, },
Data: &structpb.Struct{
Fields: map[string]*structpb.Value{
"key1": {
Kind: &structpb.Value_StringValue{StringValue: "welcome"},
},
"key2": {
Kind: &structpb.Value_NumberValue{NumberValue: 2},
},
},
},
}) })
if err != nil { if err != nil {
log.Fatalf("could not greet: %v", err) log.Fatalf("could not greet: %v", err)

2
go.mod
View File

@ -20,8 +20,8 @@ require (
github.com/emirpasic/gods v0.0.0-20170204130913-fc3e4a43ff31 // indirect github.com/emirpasic/gods v0.0.0-20170204130913-fc3e4a43ff31 // indirect
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 // indirect github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 // indirect
github.com/gin-gonic/gin v0.0.0-20170929084810-b8b68314faa0 github.com/gin-gonic/gin v0.0.0-20170929084810-b8b68314faa0
github.com/gogo/protobuf v1.1.1
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/protobuf v1.2.0
github.com/golang/snappy v0.0.0-20170215233205-553a64147049 // indirect github.com/golang/snappy v0.0.0-20170215233205-553a64147049 // indirect
github.com/hashicorp/hcl v0.0.0-20171017181929-23c074d0eceb // indirect github.com/hashicorp/hcl v0.0.0-20171017181929-23c074d0eceb // indirect
github.com/json-iterator/go v0.0.0-20170713110145-8b0360418449 // indirect github.com/json-iterator/go v0.0.0-20170713110145-8b0360418449 // indirect

2
go.sum
View File

@ -40,8 +40,6 @@ github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 h1:AzN37oI0cOS+cou
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
github.com/gin-gonic/gin v0.0.0-20170929084810-b8b68314faa0 h1:9NJhszAM+V+E0qESsPI3EGhCINyqzDWAwC0/dPEUexM= github.com/gin-gonic/gin v0.0.0-20170929084810-b8b68314faa0 h1:9NJhszAM+V+E0qESsPI3EGhCINyqzDWAwC0/dPEUexM=
github.com/gin-gonic/gin v0.0.0-20170929084810-b8b68314faa0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y= github.com/gin-gonic/gin v0.0.0-20170929084810-b8b68314faa0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y=
github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=

View File

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
structpb "github.com/golang/protobuf/ptypes/struct"
"log" "log"
"github.com/appleboy/gorush/rpc/proto" "github.com/appleboy/gorush/rpc/proto"
@ -36,6 +37,16 @@ func main() {
LocKey: "Test loc key", LocKey: "Test loc key",
LocArgs: []string{"test", "test"}, LocArgs: []string{"test", "test"},
}, },
Data: &structpb.Struct{
Fields: map[string]*structpb.Value{
"key1": {
Kind: &structpb.Value_StringValue{StringValue: "welcome"},
},
"key2": {
Kind: &structpb.Value_NumberValue{NumberValue: 2},
},
},
},
}) })
if err != nil { if err != nil {
log.Fatalf("could not greet: %v", err) log.Fatalf("could not greet: %v", err)

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
syntax = "proto3"; syntax = "proto3";
import "google/protobuf/struct.proto";
package proto; package proto;
@ -29,6 +30,7 @@ message NotificationRequest {
bool contentAvailable = 11; bool contentAvailable = 11;
string threadID = 12; string threadID = 12;
bool mutableContent = 13; bool mutableContent = 13;
google.protobuf.Struct data = 14;
} }
message NotificationReply { message NotificationReply {

View File

@ -82,6 +82,13 @@ func (s *Server) Send(ctx context.Context, in *proto.NotificationRequest) (*prot
} }
} }
if in.Data != nil {
notification.Data = map[string]interface{}{}
for k, v := range in.Data.Fields {
notification.Data[k] = v
}
}
go gorush.SendNotification(notification) go gorush.SendNotification(notification)
return &proto.NotificationReply{ return &proto.NotificationReply{