Skip to content

vallahaye/protobson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

protobson

PkgGoDev GitHub go.mod Go version GoReportCard GitHub

BSON codecs for Google's protocol buffers.

This library provides add-ons to go.mongodb.org/mongo-driver for first-class protobuf support with similar API design, extensive testing and high reuse of already existing codecs. The following types are currently mapped:

Protobuf MongoDB
message Document
google.protobuf.Timestamp Date
google.protobuf.Duration 64-bit integer
google.protobuf.BoolValue Boolean
google.protobuf.BytesValue Binary
google.protobuf.DoubleValue Double
google.protobuf.FloatValue Double
google.protobuf.Int32Value 32-bit integer
google.protobuf.Int64Value 64-bit integer
google.protobuf.StringValue String
google.protobuf.UInt32Value 32-bit integer
google.protobuf.UInt64Value 64-bit integer
google.type.DateTime Date

This list will grow as we add support for most Well-Known Types as well as Google APIs Common Types.

Usage

$ go get go.vallahaye.net/protobson
// Set client options
clientOptions := options.Client().
  SetRegistry(protobson.DefaultRegistry).
  ApplyURI("mongodb://localhost:27017")

// Connect to MongoDB
client, err := mongo.Connect(context.TODO(), clientOptions)
if err != nil {
  log.Fatal(err)
}

// Check the connection
err = client.Ping(context.TODO(), nil)
if err != nil {
  log.Fatal(err)
}

fmt.Println("Connected to MongoDB!")