github.com/optim-corp/cios-golang-sdk@v0.5.1/sdk/service/pubsub/README.md (about) 1 # Pub/Sub 2 3 ## Channel API 4 5 ### interface 6 7 ``` 8 GetChannels(ctx, cios.ApiGetChannelsRequest) (cios.MultipleChannel, *_nethttp.Response, error) 9 GetChannelsAll(ctx, cios.ApiGetChannelsRequest) ([]cios.Channel, *_nethttp.Response, error) 10 GetChannelsUnlimited(ctx, cios.ApiGetChannelsRequest) ([]cios.Channel, *_nethttp.Response, error) 11 GetChannel(ctx, string, *bool, *string) (cios.Channel, *_nethttp.Response, error) 12 GetChannelFirst(ctx, cios.ApiGetChannelsRequest) (cios.Channel, *_nethttp.Response, error) 13 GetChannelsMapByID(ctx, cios.ApiGetChannelsRequest) (map[string]cios.Channel, *_nethttp.Response, error) 14 GetChannelsMapByResourceOwnerID(ctx, cios.ApiGetChannelsRequest) (map[string][]cios.Channel, *_nethttp.Response, error) 15 DeleteChannel(ctx, string) (*_nethttp.Response, error) 16 GetOrCreateChannel(ctx, cios.ApiGetChannelsRequest, cios.ChannelProposal) (cios.Channel, *_nethttp.Response, error) 17 CreateChannel(ctx, cios.ChannelProposal) (cios.Channel, *_nethttp.Response, error) 18 UpdateChannel(ctx, string, cios.ChannelUpdateProposal) (cios.MultipleChannel, *_nethttp.Response, error) 19 ``` 20 21 ### Usage 22 23 #### Get a Channel 24 25 ```go 26 options := srvpubsub.MakeGetChannelsOpts 27 channel, httpResponse, err := client.PubSub().GetChannel(ctx, "channel_id", nil, nil) 28 ``` 29 30 #### Get Channels max limit 1000 31 32 ```go 33 options := srvpubsub.MakeGetChannelsOpts 34 channels, httpResponse, err := client.PubSub().GetChannels(ctx, options().Limit(500)) 35 ``` 36 37 #### Get Channels no limit 38 39 ```go 40 options := srvpubsub.MakeGetChannelsOpts 41 channels, httpResponse, err := client.PubSub().GetChannelsAll(ctx, options().Limit(500)) 42 ``` 43 44 #### Get Channels unlimited 45 46 ```go 47 options := srvpubsub.MakeGetChannelsOpts 48 channels, httpResponse, err := client.PubSub().GetChannelsUnlimited(ctx, options().Limit(500)) 49 ``` 50 51 52 #### Get a Channel that is first Channels API 53 54 ```go 55 options := srvpubsub.MakeGetChannelsOpts 56 channel, httpResponse, err := client.PubSub().GetChannelFirst(ctx, options().Label("sample=test")) 57 ``` 58 59 #### Get Channel Map by Channel ID 60 61 ```go 62 options := srvpubsub.MakeGetChannelsOpts 63 channelMap, httpResponse, err := client.PubSub().GetChannelsMapByID(ctx, options().Label("sample=test")) 64 ``` 65 66 #### Get Channel Map by ResourceOwner ID 67 68 ```go 69 options := srvpubsub.MakeGetChannelsOpts 70 channelMap, httpResponse, err := client.PubSub().GetChannelsMapByResourceOwnerID(ctx, options().Label("sample=test")) 71 ``` 72 73 #### Get or Create a Channel 74 75 ```go 76 options := srvpubsub.MakeGetChannelsOpts 77 channel, httpResponse, err := client.PubSub().GetOrCreateChannel(ctx, options().Limit(500), cios.ChannelProposal{}) 78 ``` 79 80 #### Create a Channel 81 82 ```go 83 channel, httpResponse, err := client.PubSub().CreateChannel(ctx, cios.ChannelProposal{}) 84 ``` 85 86 87 #### Update a Channel 88 89 ```go 90 _, httpResponse, err := client.PubSub().UpdateChannel(ctx, cios.ChannelUpdateProposal{}) 91 ``` 92 93 #### Delete a Channel 94 95 ```go 96 _, httpResponse, err := client.PubSub().UpdateChannel(ctx, cios.ChannelUpdateProposal{}) 97 ``` 98 99 ## Data Store API 100 101 ### interface 102 103 ``` 104 GetDataStoreChannels(ctx, cios.ApiGetDataStoreChannelsRequest) (cios.MultipleDataStoreChannel, *_nethttp.Response, error) 105 GetDataStoreChannel(ctx, string) (cios.DataStoreChannel, *_nethttp.Response, error) 106 GetObjects(ctx, string, cios.ApiGetDataStoreObjectsRequest) (cios.MultipleDataStoreObject, *_nethttp.Response, error) 107 GetObjectsAll(ctx, string, cios.ApiGetDataStoreObjectsRequest) ([]cios.DataStoreObject, *_nethttp.Response, error) 108 GetObjectsUnlimited(ctx, string, cios.ApiGetDataStoreObjectsRequest) ([]cios.DataStoreObject, *_nethttp.Response, error) 109 GetObject(ctx, string, string, *string) (interface{}, *_nethttp.Response, error) 110 GetObjectLatest(ctx, string, *string) (interface{}, *_nethttp.Response, error) 111 MapObjectLatest(ctx, string, *string, interface{}) (*_nethttp.Response, error) 112 GetMultiObjectLatest(ctx, []string) (cios.MultipleDataStoreDataLatest, *_nethttp.Response, error) 113 GetMultiObjectLatestByChannels(ctx, []cios.Channel) (cios.MultipleDataStoreDataLatest, *_nethttp.Response, error) 114 MapMultiObjectLatestPayload(ctx, []string, interface{}) ([]cios.PackerFormatJsonHeader, *_nethttp.Response, error) 115 MapMultiObjectLatestPayloadByChannels(ctx, []cios.Channel, interface{}) ([]cios.PackerFormatJsonHeader, *_nethttp.Response, error) 116 GetStream(ctx, string, sdkmodel.ApiGetStreamRequest) ([]string, error) 117 GetStreamAll(ctx, string, sdkmodel.ApiGetStreamRequest) ([]string, error) 118 GetStreamUnlimited(ctx, string, sdkmodel.ApiGetStreamRequest) ([]string, error) 119 MapStreamAll(ctx, string, sdkmodel.ApiGetStreamRequest, interface{}) error 120 MapStreamUnlimited(ctx, string, sdkmodel.ApiGetStreamRequest, interface{}) error 121 GetJsonStreamUnlimited(ctx, string, sdkmodel.ApiGetStreamRequest) ([]cios.PackerFormatJson, error) 122 GetStreamFirst(ctx, string, sdkmodel.ApiGetStreamRequest) (string, error) 123 MapStreamFirst(ctx, string, sdkmodel.ApiGetStreamRequest, interface{}) error 124 DeleteDataByChannel(ctx, string) (*_nethttp.Response, error) 125 DeleteObject(ctx, string, string) (*_nethttp.Response, error) 126 ``` 127 128 ### Usage 129 130 #### Get Channels on Data Store max limit 1000 131 132 ```go 133 options := srvpubsub.MakeGetDataStoreChannelsOpts() 134 channels, httpResponse, err := client.PubSub().GetDataStoreChannels(ctx, options().Limit(1000)) 135 ``` 136 137 #### Get a Channel on Data Store 138 139 ```go 140 channel, httpResponse, err := client.PubSub().GetDataStoreChannel(ctx, "channel_id") 141 ``` 142 143 #### Get a DataStore Object 144 145 ※ Fix in the future 146 ```go 147 packer_format := "payload_only" 148 object, httpResponse, err := client.PubSub().GetObject(ctx, "channel_id", "object_id", &packer_format) 149 ``` 150 151 #### Get latest DataStore Object 152 153 ※ Fix in the future 154 ```go 155 packer_format := "payload_only" 156 object, httpResponse, err := client.PubSub().GetObjectLatest(ctx, "channel_id", &packer_format) 157 ``` 158 159 #### Get latest DataStore Object on Channels 160 161 ```go 162 objects, httpResponse, err := client.PubSub().GetMultiObjectLatest(ctx, []string{"channel_id1", "channel_id2", "channel_id3"}) 163 ``` 164 165 #### Get latest DataStore Object by Channels 166 167 ```go 168 objects, httpResponse, err := client.PubSub().GetMultiObjectLatest(ctx, []cios.Channel{channel1, channel2, channel3}) 169 ``` 170 171 #### Get DataStore Objects max limit 1000 172 173 ```go 174 options := srvpubsub.MakeGetObjectsOpts 175 objects, httpResponse, err := client.PubSub().GetObjects(ctx, "channel_id", options()) 176 ``` 177 178 #### Get DataStore Objects no limit 179 180 ```go 181 options := srvpubsub.MakeGetObjectsOpts 182 objects, httpResponse, err := client.PubSub().GetObjectsAll(ctx, "channel_id", options()) 183 ``` 184 185 #### Get DataStore Objects unlimited 186 187 ```go 188 options := srvpubsub.MakeGetObjectsOpts 189 objects, httpResponse, err := client.PubSub().GetObjectsUnlimited(ctx, "channel_id", options()) 190 ``` 191 192 #### Parse latest for Object 193 194 ```go 195 packerFormat := "payload_only" 196 sample := struct{....}{} 197 httpResponse, err := client.PubSub().MapObjectLatest(ctx, "channel_id", &packerFormat, &sample) 198 ``` 199 200 #### Parse latest for Object on channels 201 202 ※ Fix in the future 203 204 ```go 205 packerFormat := "payload_only" 206 sample := struct{....}{} 207 httpResponse, err := client.PubSub().MapMultiObjectLatestPayload(ctx, []string{"channel_id", "channel_id"}, &sample) 208 ``` 209 210 #### Get DataStore Stream max limit 1000 211 212 ```go 213 options := srvpubsub.MakeGetStreamOpts 214 stream, err := client.PubSub().GetStream(ctx, "channel_id", options()) 215 ``` 216 217 #### Get DataStore Stream no limit 218 219 ```go 220 options := srvpubsub.MakeGetStreamOpts 221 stream, err := client.PubSub().GetStreamAll(ctx, "channel_id", options()) 222 ``` 223 224 #### Get DataStore Stream unlimited 225 226 ```go 227 options := srvpubsub.MakeGetStreamOpts 228 stream, err := client.PubSub().GetStreamUnimited(ctx, "channel_id", options()) 229 ``` 230 #### Get a DataStore Stream first 231 232 ```go 233 options := srvpubsub.MakeGetStreamOpts 234 data, err := client.PubSub().GetStreamFirst(ctx, "channel_id", options()) 235 ``` 236 237 #### Parse DataStore Stream no limit 238 239 ```go 240 data := []struct{...}{} 241 options := srvpubsub.MakeGetStreamOpts 242 err := client.PubSub().MapStreamAll(ctx, "channel_id", options(), &data) 243 ``` 244 245 #### Parse DataStore Stream unlimited 246 247 ```go 248 data := []struct{...}{} 249 options := srvpubsub.MakeGetStreamOpts 250 err := client.PubSub().MapStreamUnlimited(ctx, "channel_id", options(), &data) 251 ``` 252 253 #### Map a DataStore Stream first 254 255 ```go 256 options := srvpubsub.MakeGetStreamOpts 257 data := struct{}{} 258 err := client.PubSub().GetStreamFirst(ctx, "channel_id", options(), &data) 259 ``` 260 261 #### Delete DataStore Objects 262 263 ```go 264 httpResponse, err := client.PubSub().DeleteDataByChannel(ctx, "channel_id") 265 ``` 266 267 #### Delete a DataStore Object 268 269 ```go 270 httpResponse, err := client.PubSub().DeleteObject(ctx, "channel_id", "object_id") 271 ``` 272 273 ## Messaging API 274 275 ### interface 276 277 ``` 278 NewMessaging(string, enum.MessagingMode, enum.PackerFormat) *srvpubsub.CiosMessaging 279 PublishMessage(ciosctx.RequestCtx, string, interface{}, *string) (*_nethttp.Response, error) 280 PublishMessagePackerOnly(ciosctx.RequestCtx, string, interface{}) (*_nethttp.Response, error) 281 PublishMessageJSON(ciosctx.RequestCtx, string, cios.PackerFormatJson) (*_nethttp.Response, error) 282 ``` 283 284 ### Usage 285 286 #### Publish Message 287 288 ※ Fix in the future 289 290 ```go 291 packerFormat := "payload_only" 292 data := struct{}{} 293 httpResponse, err := client.PubSub().PublishMessage(ctx, "channel_id", data, &packetFormat) 294 ``` 295 296 297 #### Publish payload only format 298 299 ※ Fix in the future 300 ```go 301 data := struct{}{} 302 httpResponse, err := client.PubSub().PublishMessagePackerOnly(ctx, "channel_id", data) 303 ``` 304 305 #### Publish json format 306 307 ```go 308 data := struct{}{} 309 httpResponse, err := client.PubSub().PublishMessageJSON(ctx, "channel_id", data) 310 ``` 311 312 313 #### Create Messaging instance 314 315 ```go 316 ms := client.PubSub().NewMessaging("channel_id", enum.PubSub, enum.Json) 317 err := ms.Start(ctx) 318 ... 319 ms.Close() 320 ``` 321 322 #### About Messaging Instance 323 324 ※ Fix in the future 325 326 What doesn't exist interface yet. 327 328 * Send a Message 329 ``` 330 Send(message []byte) (err error) 331 SendStr(message string) error 332 SendAny(message interface{}) error 333 SendJson(message interface{}) error 334 Publish(message interface{}) error 335 ``` 336 ```go 337 err := ms.Send([]byte{}) 338 err := ms.SendStr("sample") 339 err := ms.SendJson(struct{}{}) 340 ``` 341 342 * Receive a Message 343 344 ``` 345 Receive() (body []byte, err error) 346 ReceiveStr() (string, error) 347 MapReceived(stct interface{}) 348 ``` 349 ```go 350 byts, err := ms.Receive() 351 str, err := ms.ReceiveStr() 352 data struct{} 353 err := ms.MapReceived(&data) 354 ```