github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/server/serverpb/status.go (about)

     1  // Copyright 2020 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package serverpb
    12  
    13  import "github.com/cockroachdb/cockroach/pkg/util/errorutil"
    14  
    15  // OptionalStatusServer is a StatusServer that is only optionally present inside
    16  // the SQL subsystem. In practice, it is present on the system tenant, and not
    17  // present on "regular" tenants.
    18  type OptionalStatusServer struct {
    19  	w errorutil.TenantSQLDeprecatedWrapper // stores serverpb.StatusServer
    20  }
    21  
    22  // MakeOptionalStatusServer initializes and returns an OptionalStatusServer. The
    23  // provided server will be returned via OptionalErr() if and only if it is not
    24  // nil.
    25  func MakeOptionalStatusServer(s StatusServer) OptionalStatusServer {
    26  	return OptionalStatusServer{
    27  		// Return the status server from OptionalErr() only if one was provided.
    28  		// We don't have any calls to .Deprecated().
    29  		w: errorutil.MakeTenantSQLDeprecatedWrapper(s, s != nil /* exposed */),
    30  	}
    31  }
    32  
    33  // OptionalErr returns the wrapped StatusServer, if it is available. If it is
    34  // not, an error referring to the optionally supplied issues is returned.
    35  func (s *OptionalStatusServer) OptionalErr(issueNos ...int) (StatusServer, error) {
    36  	v, err := s.w.OptionalErr(issueNos...)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	return v.(StatusServer), nil
    41  }