@@ -11,22 +11,22 @@ import (
1111var CheckTopicPermission = CheckPermission
1212
1313type Publisher struct {
14- Client * pubsub.Client
15- Topic * pubsub.Topic
16- Convert func (context.Context , []byte )([]byte , error )
14+ Client * pubsub.Client
15+ Topic * pubsub.Topic
16+ Convert func (context.Context , []byte ) ([]byte , error )
1717}
1818
19- func NewPublisher (ctx context.Context , client * pubsub.Client , topicId string , c * TopicConfig , options ... func (context.Context , []byte )([]byte , error )) * Publisher {
19+ func NewPublisher (ctx context.Context , client * pubsub.Client , topicId string , c * TopicConfig , options ... func (context.Context , []byte ) ([]byte , error )) * Publisher {
2020 topic := client .Topic (topicId )
2121 CheckTopicPermission (ctx , topic .IAM (), "pubsub.topics.publish" )
22- var convert func (context.Context , []byte )([]byte , error )
22+ var convert func (context.Context , []byte ) ([]byte , error )
2323 if len (options ) > 0 {
2424 convert = options [0 ]
2525 }
2626 return & Publisher {Client : client , Topic : ConfigureTopic (topic , c ), Convert : convert }
2727}
2828
29- func NewPublisherByConfig (ctx context.Context , c PublisherConfig , options ... func (context.Context , []byte )([]byte , error )) (* Publisher , error ) {
29+ func NewPublisherByConfig (ctx context.Context , c PublisherConfig , options ... func (context.Context , []byte ) ([]byte , error )) (* Publisher , error ) {
3030 if c .Retry .Retry1 <= 0 {
3131 client , err := NewPubSubClient (ctx , []byte (c .Client .Credentials ), c .Client .ProjectId )
3232 if err != nil {
@@ -60,25 +60,13 @@ func ConfigureTopic(topic *pubsub.Topic, c *TopicConfig) *pubsub.Topic {
6060 }
6161 return topic
6262}
63- func (p * Publisher ) Put (ctx context.Context , data []byte , attributes map [string ]string ) (string , error ) {
64- return p .Publish (ctx , data , attributes )
65- }
66- func (p * Publisher ) Send (ctx context.Context , data []byte , attributes map [string ]string ) (string , error ) {
67- return p .Publish (ctx , data , attributes )
68- }
69- func (p * Publisher ) Produce (ctx context.Context , data []byte , attributes map [string ]string ) (string , error ) {
70- return p .Publish (ctx , data , attributes )
71- }
72- func (p * Publisher ) Write (ctx context.Context , data []byte , attributes map [string ]string ) (string , error ) {
73- return p .Publish (ctx , data , attributes )
74- }
75- func (p * Publisher ) Publish (ctx context.Context , data []byte , attributes map [string ]string ) (string , error ) {
63+ func (p * Publisher ) Publish (ctx context.Context , data []byte , attributes map [string ]string ) error {
7664 var binary = data
7765 var err error
7866 if p .Convert != nil {
7967 binary , err = p .Convert (ctx , data )
8068 if err != nil {
81- return "" , err
69+ return err
8270 }
8371 }
8472 msg := & pubsub.Message {
@@ -89,7 +77,8 @@ func (p *Publisher) Publish(ctx context.Context, data []byte, attributes map[str
8977 }
9078
9179 publishResult := p .Topic .Publish (ctx , msg )
92- return publishResult .Get (ctx )
80+ _ , err = publishResult .Get (ctx )
81+ return err
9382}
9483
9584func CheckPermission (ctx0 context.Context , iam * iam.Handle , permission string ) {
0 commit comments