github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/client/grpc/message.go (about) 1 // Copyright 2020 Asim Aslam 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // Original source: github.com/micro/go-micro/v3/client/grpc/message.go 16 17 package grpc 18 19 import ( 20 "github.com/tickoalcantara12/micro/v3/service/client" 21 ) 22 23 type grpcEvent struct { 24 topic string 25 contentType string 26 payload interface{} 27 } 28 29 func newGRPCEvent(topic string, payload interface{}, contentType string, opts ...client.MessageOption) client.Message { 30 var options client.MessageOptions 31 for _, o := range opts { 32 o(&options) 33 } 34 35 if len(options.ContentType) > 0 { 36 contentType = options.ContentType 37 } 38 39 return &grpcEvent{ 40 payload: payload, 41 topic: topic, 42 contentType: contentType, 43 } 44 } 45 46 func (g *grpcEvent) ContentType() string { 47 return g.contentType 48 } 49 50 func (g *grpcEvent) Topic() string { 51 return g.topic 52 } 53 54 func (g *grpcEvent) Payload() interface{} { 55 return g.payload 56 }