package main // #include import ( "C" "context" "encoding/json" "fmt" "cloud.google.com/go/pubsub" ) //export gpub func gpub(msg string) { ctx := context.Background() // Sets your Google Cloud Platform project ID. projectID := "fleet-furnace-197606" // Creates a client. client, err := pubsub.NewClient(ctx, projectID) if err != nil { fmt.Printf("Failed to create client: %v", err) } defer client.Close() // Sets the id for the new topic. topicID := "okTopic" // message := "{'_id':'665ceaade221eb5dc182501d','index':1,'guid':'7177c6c6-babb-4be5-822b-7984c5c3cd93','isActive':true}" println("msg:= ", msg) message := msg data, err := json.Marshal(message) if err != nil { fmt.Printf("Failed to marshal json") } fmt.Println(data) // Creates the new topic. topic := client.Topic(topicID) res := topic.Publish(ctx, &pubsub.Message{ Data: data, // Data: []byte("hello world"), }) msgID, err := res.Get(ctx) if err != nil { fmt.Println(err) } fmt.Printf("Msg %v created.\n", msgID) } func main() {}