github.com/pachyderm/pachyderm@v1.13.4/src/client/version/api_server.go (about)

     1  package version
     2  
     3  import (
     4  	"fmt"
     5  
     6  	pb "github.com/pachyderm/pachyderm/src/client/version/versionpb"
     7  
     8  	"github.com/gogo/protobuf/types"
     9  	"golang.org/x/net/context"
    10  	"google.golang.org/grpc"
    11  )
    12  
    13  type apiServer struct {
    14  	version *pb.Version
    15  	options APIServerOptions
    16  }
    17  
    18  func newAPIServer(version *pb.Version, options APIServerOptions) *apiServer {
    19  	return &apiServer{version, options}
    20  }
    21  
    22  func (a *apiServer) GetVersion(ctx context.Context, request *types.Empty) (response *pb.Version, err error) {
    23  	return a.version, nil
    24  }
    25  
    26  // APIServerOptions are options when creating a new APIServer.
    27  type APIServerOptions struct {
    28  	DisableLogging bool
    29  }
    30  
    31  // NewAPIServer creates a new APIServer for the given Version.
    32  func NewAPIServer(version *pb.Version, options APIServerOptions) pb.APIServer {
    33  	return newAPIServer(version, options)
    34  }
    35  
    36  // GetServerVersion gets the server *Version given the *grpc.ClientConn.
    37  func GetServerVersion(clientConn *grpc.ClientConn) (*pb.Version, error) {
    38  	return pb.NewAPIClient(clientConn).GetVersion(
    39  		context.Background(),
    40  		&types.Empty{},
    41  	)
    42  }
    43  
    44  // String returns a string representation of the Version.
    45  func String(v *pb.Version) string {
    46  	return fmt.Sprintf("%d.%d.%d%s", v.Major, v.Minor, v.Micro, v.Additional)
    47  }