...

Source file src/go.mongodb.org/mongo-driver/x/mongo/driver/topology/example_test.go

Documentation: go.mongodb.org/mongo-driver/x/mongo/driver/topology

     1  // Copyright (C) MongoDB, Inc. 2017-present.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"); you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
     6  
     7  package topology_test
     8  
     9  import (
    10  	"log"
    11  
    12  	"go.mongodb.org/mongo-driver/x/mongo/driver/topology"
    13  )
    14  
    15  func Example_clusterMonitoring() {
    16  	topo, err := topology.New(nil)
    17  	if err != nil {
    18  		log.Fatalf("could not create topology: %v", err)
    19  	}
    20  	err = topo.Connect()
    21  	if err != nil {
    22  		log.Fatalf("could not create topology: %v", err)
    23  	}
    24  
    25  	sub, err := topo.Subscribe()
    26  	if err != nil {
    27  		log.Fatalf("could not subscribe to topology: %v", err)
    28  	}
    29  
    30  	for desc := range sub.Updates {
    31  		log.Printf("%#v", desc)
    32  	}
    33  }
    34  

View as plain text