@@ -12,7 +12,7 @@ type BuildInfo struct {
1212 Version string `bson:"version"`
1313}
1414
15- func GetBuildInfo (ctx context.Context , client * mongo.Client ) (* BuildInfo , error ) {
15+ func GetBuildInfo (ctx context.Context , client * mongo.Client ) (BuildInfo , error ) {
1616 return runCommand [BuildInfo ](ctx , client , "buildInfo" )
1717}
1818
@@ -21,7 +21,7 @@ type ReplSetGetStatus struct {
2121 MyState int `bson:"myState"`
2222}
2323
24- func GetReplSetGetStatus (ctx context.Context , client * mongo.Client ) (* ReplSetGetStatus , error ) {
24+ func GetReplSetGetStatus (ctx context.Context , client * mongo.Client ) (ReplSetGetStatus , error ) {
2525 return runCommand [ReplSetGetStatus ](ctx , client , "replSetGetStatus" )
2626}
2727
@@ -38,7 +38,7 @@ type ServerStatus struct {
3838 OplogTruncation OplogTruncation `bson:"oplogTruncation"`
3939}
4040
41- func GetServerStatus (ctx context.Context , client * mongo.Client ) (* ServerStatus , error ) {
41+ func GetServerStatus (ctx context.Context , client * mongo.Client ) (ServerStatus , error ) {
4242 return runCommand [ServerStatus ](ctx , client , "serverStatus" )
4343}
4444
@@ -55,7 +55,7 @@ type Role struct {
5555 DB string `bson:"db"`
5656}
5757
58- func GetConnectionStatus (ctx context.Context , client * mongo.Client ) (* ConnectionStatus , error ) {
58+ func GetConnectionStatus (ctx context.Context , client * mongo.Client ) (ConnectionStatus , error ) {
5959 return runCommand [ConnectionStatus ](ctx , client , "connectionStatus" )
6060}
6161
@@ -64,21 +64,21 @@ type HelloResponse struct {
6464 Hosts []string `bson:"hosts,omitempty"`
6565}
6666
67- func GetHelloResponse (ctx context.Context , client * mongo.Client ) (* HelloResponse , error ) {
67+ func GetHelloResponse (ctx context.Context , client * mongo.Client ) (HelloResponse , error ) {
6868 return runCommand [HelloResponse ](ctx , client , "hello" )
6969}
7070
71- func runCommand [T any ](ctx context.Context , client * mongo.Client , command string ) (* T , error ) {
71+ func runCommand [T any ](ctx context.Context , client * mongo.Client , command string ) (T , error ) {
72+ var result T
7273 singleResult := client .Database ("admin" ).RunCommand (ctx , bson.D {
7374 bson.E {Key : command , Value : 1 },
7475 })
7576 if singleResult .Err () != nil {
76- return nil , fmt .Errorf ("'%s' failed: %v" , command , singleResult .Err ())
77+ return result , fmt .Errorf ("'%s' failed: %v" , command , singleResult .Err ())
7778 }
7879
79- var result T
8080 if err := singleResult .Decode (& result ); err != nil {
81- return nil , fmt .Errorf ("'%s' failed: %v" , command , err )
81+ return result , fmt .Errorf ("'%s' failed: %v" , command , err )
8282 }
83- return & result , nil
83+ return result , nil
8484}
0 commit comments