@@ -272,6 +272,23 @@ Additional Dependencies
272
272
* - x64 Support
273
273
- x64 support is required for CSFLE
274
274
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
+
275
292
.. _fle-create-a-master-key:
276
293
277
294
A. Create a Master Key
@@ -403,6 +420,34 @@ to a file with the **fully runnable code below**:
403
420
}
404
421
}
405
422
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
+
406
451
B. Create a Data Encryption Key
407
452
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
408
453
@@ -656,6 +701,13 @@ full `JSON Schema for the Medical Care Management System
656
701
View the **complete runnable** `helper code in C#
657
702
<https://github.com/mongodb-university/csfle-guides/blob/master/dotnet/CSFLE/JsonSchemaCreator.cs>`_.
658
703
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
+
659
711
D. Create the MongoDB Client
660
712
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
661
713
@@ -863,6 +915,50 @@ can provide configurable parameters including:
863
915
864
916
| **Default**: ``60``
865
917
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
+
866
962
867
963
.. note::
868
964
@@ -1019,6 +1115,58 @@ following **code snippet**:
1019
1115
1020
1116
Console.WriteLine($"Encrypted client query by the SSN (deterministically-encrypted) field:\n {result}\n");
1021
1117
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.
1022
1170
1023
1171
1024
1172
When 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:
1190
1338
**GitHub:** `C# CSFLE runnable example
1191
1339
<https://github.com/mongodb-university/csfle-guides/tree/master/dotnet>`_
1192
1340
1341
+ .. tab::
1342
+ :tabid: go
1343
+
1344
+ **GitHub:** `Go CSFLE runnable example
1345
+ <https://github.com/mongodb-university/csfle-guides/tree/master/gocse>`_
1346
+
1193
1347
Move to Production
1194
1348
~~~~~~~~~~~~~~~~~~
1195
1349
@@ -1238,3 +1392,9 @@ check out the reference docs in the server manual:
1238
1392
1239
1393
For additional information on MongoDB CSFLE API, see the
1240
1394
`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