harbor run -t openthoughts/tasktrove-exp-rpt-stack-go-v4-stack-go-5331harbor download openthoughts/tasktrove-exp-rpt-stack-go-v4-stack-go-5331Implement a publish-subscribe (pub-sub) messaging system in Go. The implementation should fulfill the following functionality and adhere to the requirements outlined below:
Create a PubSub Structure:
PubSub that will handle subscriptions, publications, and the necessary channels for communication.Methods Required:
PubSub instance with the specified buffer size for channels.ch for the specified topics.PubSub, ensuring there are no lingering goroutines.Concurrency:
Testing:
pubsub_test.go, which confirm the functionality outlined above. The tests are structured to check various cases such as multiple subscriptions, unsubscriptions, and message deliveries.Placement:
/app/ directory, ensuring that the PubSub struct and its methods are all implemented correctly to satisfy the tests.Make sure to handle any errors or edge cases, such as trying to publish to a closed topic or subscription, and ensure that channels are properly closed to avoid memory leaks.
Important: declare your solution in package pubsub (the test file uses package pubsub, so the implementation must use the matching package name).