@@ -272,6 +272,23 @@ Additional Dependencies
272272 * - x64 Support
273273 - x64 support is required for CSFLE
274274
275+ .. tab::
276+ :tabid: go
277+
278+ .. list-table::
279+ :header-rows: 1
280+
281+ * - Dependency Name
282+ - Description
283+
284+ * - Go version 1.10 or later
285+ - A Go version of 1.10 or later is required. Go 1.11 or later is recommended for support
286+ `go module support <https://blog.golang.org/using-go-modules>__`.
287+
288+ * - `libmongocrypt <https://github.com/mongodb/libmongocrypt#libmongocrypt>`__ version 1.1.0 or later
289+ -
290+
291+
275292.. _fle-create-a-master-key:
276293
277294A. Create a Master Key
@@ -403,6 +420,34 @@ to a file with the **fully runnable code below**:
403420 }
404421 }
405422
423+ .. tab::
424+ :tabid: go
425+
426+ The following script generates a 96-byte locally-managed master key and
427+ saves it to a file called ``master-key.txt`` in the directory
428+ from which the program is executed.
429+
430+ .. code-block:: go
431+
432+ package main
433+
434+ import (
435+ "crypto/rand"
436+ "io/ioutil"
437+ "log"
438+ )
439+
440+ func main() {
441+ key := make([]byte, 96)
442+ if _, err := rand.Read(key); err != nil {
443+ log.Fatalf("Unable to create a random 96 byte data key: %v", err)
444+ }
445+ if err := ioutil.WriteFile("master-key.txt", key, 0644); err != nil {
446+ log.Fatalf("Unable to write key to file: %v", err)
447+ }
448+ }
449+
450+
406451B. Create a Data Encryption Key
407452~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
408453
@@ -656,6 +701,13 @@ full `JSON Schema for the Medical Care Management System
656701 View the **complete runnable** `helper code in C#
657702 <https://github.com/mongodb-university/csfle-guides/blob/master/dotnet/CSFLE/JsonSchemaCreator.cs>`_.
658703
704+ .. tab::
705+ :tabid: go
706+
707+ View the **complete runnable** `helper code in Go
708+ <https://github.com/mongodb-university/csfle-guides/blob/master/schema/json_schema.go>`_.
709+
710+
659711D. Create the MongoDB Client
660712~~~~~~~~~~~~~~~~~~~~~~~~~~~~
661713
@@ -863,6 +915,50 @@ can provide configurable parameters including:
863915
864916 | **Default**: ``60``
865917
918+ .. tab::
919+ :tabid: go
920+
921+ .. list-table::
922+ :header-rows: 1
923+ :stub-columns: 1
924+
925+ * - Name
926+ - Description
927+
928+
929+ * - port
930+ - | Listening port.
931+ | Specify this value as follows:
932+
933+ .. example::
934+
935+ .. code-block:: go
936+
937+ extraOptions := map[string]interface{}{
938+ "mongocryptdSpawnArgs": []string{
939+ "--port=30000",
940+ },
941+ }
942+
943+ | **Default**: ``27020``
944+
945+ * - idleShutdownTimeoutSecs
946+ - | Number of idle seconds in which the ``mongocryptd`` process should wait before exiting.
947+ | Specify this value as follows:
948+
949+ .. example::
950+
951+ .. code-block:: go
952+
953+ extraOptions := map[string]interface{}{
954+ "mongocryptdSpawnArgs": []string{
955+ "--idleShutdownTimeoutSecs=75",
956+ },
957+ }
958+
959+ | **Default**: ``60``
960+
961+
866962
867963.. note::
868964
@@ -1019,6 +1115,58 @@ following **code snippet**:
10191115
10201116 Console.WriteLine($"Encrypted client query by the SSN (deterministically-encrypted) field:\n {result}\n");
10211117
1118+ .. tab::
1119+ :tabid: go
1120+
1121+ .. code-block:: go
1122+
1123+ package patient
1124+
1125+ type medicalRecord struct {
1126+ Weight int `bson:"weight"`
1127+ BloodPressure string `bson:"bloodPressure"`
1128+ }
1129+
1130+ type insurance struct {
1131+ Provider string `bson:"provider"`
1132+ PolicyNumber int `bson:"policyNumber"`
1133+ }
1134+
1135+ type Patient struct {
1136+ Name string `bson:"name"`
1137+ SSN int `bson:"ssn"`
1138+ BloodType string `bson:"bloodType"`
1139+ medicalRecords []medicalRecord `bson:"medicalRecords"`
1140+ insurance insurance `bson:"insurance"`
1141+ }
1142+
1143+ func GetExamplePatient() Patient {
1144+
1145+ return Patient{
1146+ Name: "Jon Doe",
1147+ SSN: 241014209,
1148+ BloodType: "AB+",
1149+ medicalRecords: []medicalRecord{{
1150+ Weight: 180,
1151+ BloodPressure: "120/80",
1152+ }},
1153+ insurance: insurance{
1154+ Provider: "MaestCare",
1155+ PolicyNumber: 123142,
1156+ },
1157+ }
1158+ }
1159+
1160+ doc := GetExamplePatient()
1161+ collection := client.Database(dbName).Collection(collName)
1162+ if _, err := collection.InsertOne(context.TODO(), doc); err != nil {
1163+ return fmt.Errorf("InsertOne error: %v", err)
1164+ }
1165+
1166+ .. note::
1167+
1168+ Rather than creating a raw BSON document, you can pass a struct with ``bson`` tags directly
1169+ to the driver for encoding.
10221170
10231171
10241172When a CSFLE-enabled client inserts a new patient record into the Medical Care
@@ -1190,6 +1338,12 @@ To view and download a runnable example of CSFLE, select your driver below:
11901338 **GitHub:** `C# CSFLE runnable example
11911339 <https://github.com/mongodb-university/csfle-guides/tree/master/dotnet>`_
11921340
1341+ .. tab::
1342+ :tabid: go
1343+
1344+ **GitHub:** `Go CSFLE runnable example
1345+ <https://github.com/mongodb-university/csfle-guides/tree/master/gocse>`_
1346+
11931347Move to Production
11941348~~~~~~~~~~~~~~~~~~
11951349
@@ -1238,3 +1392,9 @@ check out the reference docs in the server manual:
12381392
12391393 For additional information on MongoDB CSFLE API, see the
12401394 `official C# driver documentation <https://mongodb.github.io/mongo-csharp-driver/2.11/reference/driver/crud/client_side_encryption/>`__.
1395+
1396+ .. tab::
1397+ :tabid: go
1398+
1399+ For additional information on the MongoDB CSFLE API, see the
1400+ `official Go driver documentation <https://pkg.go.dev/go.mongodb.org/
[email protected] /mongo#hdr-Client_Side_Encryption>`__
0 commit comments