Skip to content

Instantly share code, notes, and snippets.

@jakobii
Last active October 31, 2019 20:55
Show Gist options
  • Select an option

  • Save jakobii/e5806e40fb32694e242c2a558abcfbf2 to your computer and use it in GitHub Desktop.

Select an option

Save jakobii/e5806e40fb32694e242c2a558abcfbf2 to your computer and use it in GitHub Desktop.

Revisions

  1. jakobii revised this gist Oct 31, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rethinkdb_golang_driver_tls_example.go
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ func Example() {
    Username: "admin",
    TLSConfig: &tls.Config{
    RootCAs: roots,
    InsecureSkipVerify: true, // if its a self signed cert, skip ndns name check.
    InsecureSkipVerify: true, // if its a self signed cert
    },
    })
    if err != nil {
  2. jakobii renamed this gist Oct 31, 2019. 1 changed file with 0 additions and 0 deletions.
  3. jakobii created this gist Oct 31, 2019.
    51 changes: 51 additions & 0 deletions golang_drive_rethinkdb_tls_example.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    package main

    import (
    "crypto/tls"
    "crypto/x509"
    "fmt"
    "io/ioutil"
    "log"
    "os"

    r "gopkg.in/rethinkdb/rethinkdb-go.v5"
    )

    func Example() {

    roots := x509.NewCertPool()
    cert, err := ioutil.ReadFile(os.Getenv(`PATH_TO_YOUR_CERT`)) // same cert passed to --driver-tls-cert
    roots.AppendCertsFromPEM(cert)

    session, err := r.Connect(r.ConnectOpts{
    Address: "YOUR_SERVERS_IP_ADDRESS:28015",
    Username: "admin",
    TLSConfig: &tls.Config{
    RootCAs: roots,
    InsecureSkipVerify: true, // if its a self signed cert, skip ndns name check.
    },
    })
    if err != nil {
    log.Fatalln(err)
    }

    res, err := r.Expr("Hello World").Run(session)
    if err != nil {
    log.Fatalln(err)
    }

    var response string
    err = res.One(&response)
    if err != nil {
    log.Fatalln(err)
    }

    fmt.Println(response)

    // Output:
    // Hello World
    }

    func main() {
    Example()
    }