This library provides generic methods for decoding and publishing messages to Google Pub/Sub.
You can install the module directly from GitHub
go get -u github.com/fuzzylabs/go-pubsub@<version>
Where version can point to a commit hash or a branch, for example:
go get -u github.com/fuzzylabs/go-pubsub@9302e1d
or
go get -u github.com/fuzzylabs/go-pubsub@master
You can then import the library as follows:
import (
hubspot "github.com/fuzzylabs/go-pubsub"
)
package main
import (
pubsub "github.com/fuzzylabs/go-pubsub"
"net/http"
)
func Entrypoint(w http.ResponseWriter, r *http.Request) {
projectID := "test"
pubsubApi, err := pubsub.NewPubSubDecoder()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
message, err := pubsubApi.DecodeData(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
}
package main
import (
pubsub "github.com/fuzzylabs/go-pubsub"
"github.com/golang/protobuf/ptypes/empty"
)
func Entrypoint() {
projectID := "test"
pubsubApi, err := pubsub.NewPubSub(projectID)
if err != nil {
panic("")
}
// Replace with your message that satisfies `proto.Message` interface
message := &empty.Empty{}
pubsubApi.PublishMessage("test-topic", message)
}
moq
is used to generate mocks:
- Mocks for external interfaces to use within unit tests
- Mocks for
go-pubsub
API interfaces, for to make testing of applications that use the library easier
go generate
go vet
go test -coverprofile=coverage.out
go tool cover -html=coverage.out # To view test coverage