Go Library
A Golang backend library for Cyprinus Location Subscription. It is used to subscribe to user's locations at project level or location of a single user.
roam-go supports subscription to the following location data:
  • Specific user
  • All users of a group
  • All users of project

Installation

You can install our Golang library as mentioned below.
1
go get -u github.com/roam-ai/roam-go/roam
Copied!

Methods

Subscribe to a single user

You can use the SDK to subscribe to single user's location and listen to it. You have pass the user id which our Mobile SDK's returns during creating a user.
1
userSubscription , err := roam.NewUserSubscription("apikey","userID")
Copied!

Example Usage

1
package main
2
3
import (
4
"fmt"
5
"github.com/roam-ai/roam-go/roam"
6
"time"
7
)
8
func main() {
9
// initialization
10
subscription , _ := roam.NewUserSubscription("apikey","userID")
11
12
// Declaring handler function
13
var handler roam.MessageHandler = func(userID string , payload []byte){
14
// logic
15
}
16
17
// start subscription
18
subscription.Subscribe(handler)
19
}
Copied!

Subscribe to a group:

You can also use the SDK to subscribe to a user group and listen to their location updates. You can get the group_id from our developer API for user grouping and use the group id when creating the client instance to listen to location at user group level.
1
groupSubscription , err := roam.NewGroupSubscription("apikey","groupID")
Copied!
1
package main
2
3
import (
4
"fmt"
5
"github.com/roam-ai/roam-go/roam"
6
"time"
7
)
8
func main() {
9
// initialization
10
subscription , _ := roam.NewGroupSubscription("apikey","groupID")
11
12
// Declaring handler function
13
var handler roam.MessageHandler = func(userID string , payload []byte){
14
// logic
15
}
16
17
// start subscription
18
subscription.Subscribe(handler)
19
}
Copied!

Unsubscribe

At any point, if you wish to unsubscribe from location updates, use the below code:
1
subscription.Unsubscribe()
Copied!

Handler Function

While calling Subscribe method on subscription, you will need to pass a handler func as parameter. Handler func should have userID of type string and payload of type []byte and will be invoked on every location update received.
1
var handler roam.MessageHandler = func(userID string , payload []byte){
2
// logic
3
}
4
5
subscription.Subscribe(handler)
Copied!

Example Usage

GitHub - roam-ai/roam-go: Go Pub/Sub Library; GoLang library to subscribe to realtime location updates from Roam.ai's location SDKs.
GitHub
roam-go
You can think this library as a wrapper around our REST API which needs your API key for authorization and it works as per project level. It is fairly simple to use:
  • Create an instance of subscription with your API key.
  • Define your custom callback function and pass it with Subscribe method, which will be executed on every location received from the server.
  • To stop receiving data, call Unsubscribe method. The below example usage code:
1
package main
2
3
import (
4
"fmt"
5
"github.com/roam-ai/roam-go/roam"
6
"time"
7
)
8
func main() {
9
// initialization
10
subscription , _ := roam.NewProjectSubscription("apikey")
11
12
var handler roam.MessageHandler = func(userID string , payload []byte){
13
fmt.Println(userID)
14
fmt.Println(string(payload))
15
}
16
17
subscription.Subscribe(handler)
18
}
Copied!

Need Help?

If you have any problems or issues over our SDK, feel free to create a github issue or submit a request on Cyprinus Help.
Last modified 4mo ago