blob: 46bec842afcc59b5ff004464a7e5bcde3427518e [file] [log] [blame]
Don Newton379ae252019-04-01 12:17:06 -04001// 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
7package driver
8
9import (
10 "context"
11
12 "github.com/mongodb/mongo-go-driver/x/mongo/driver/topology"
13 "github.com/mongodb/mongo-go-driver/x/network/command"
14 "github.com/mongodb/mongo-go-driver/x/network/description"
15 "github.com/mongodb/mongo-go-driver/x/network/result"
16)
17
18// EndSessions handles the full cycle dispatch and execution of an endSessions command against the provided
19// topology.
20func EndSessions(
21 ctx context.Context,
22 cmd command.EndSessions,
23 topo *topology.Topology,
24 selector description.ServerSelector,
25) ([]result.EndSessions, []error) {
26
27 ss, err := topo.SelectServer(ctx, selector)
28 if err != nil {
29 return nil, []error{err}
30 }
31
32 desc := ss.Description()
33 conn, err := ss.Connection(ctx)
34 if err != nil {
35 return nil, []error{err}
36 }
37 defer conn.Close()
38
39 return cmd.RoundTrip(ctx, desc, conn)
40}