gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/grpc/admin/admin.go (about)

     1  /*
     2   *
     3   * Copyright 2021 gRPC authors.
     4   *
     5   * Licensed under the Apache License, Version 2.0 (the "License");
     6   * you may not use this file except in compliance with the License.
     7   * You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   */
    18  
    19  // Package admin provides a convenient method for registering a collection of
    20  // administration services to a gRPC server. The services registered are:
    21  //
    22  // - Channelz: https://github.com/grpc/proposal/blob/master/A14-channelz.md
    23  //
    24  // - CSDS: https://github.com/grpc/proposal/blob/master/A40-csds-support.md
    25  //
    26  // # Experimental
    27  //
    28  // Notice: All APIs in this package are experimental and may be removed in a
    29  // later release.
    30  package admin
    31  
    32  import (
    33  	grpc "gitee.com/ks-custle/core-gm/grpc"
    34  	channelzservice "gitee.com/ks-custle/core-gm/grpc/channelz/service"
    35  	internaladmin "gitee.com/ks-custle/core-gm/grpc/internal/admin"
    36  )
    37  
    38  func init() {
    39  	// Add a list of default services to admin here. Optional services, like
    40  	// CSDS, will be added by other packages.
    41  	internaladmin.AddService(func(registrar grpc.ServiceRegistrar) (func(), error) {
    42  		channelzservice.RegisterChannelzServiceToServer(registrar)
    43  		return nil, nil
    44  	})
    45  }
    46  
    47  // Register registers the set of admin services to the given server.
    48  //
    49  // The returned cleanup function should be called to clean up the resources
    50  // allocated for the service handlers after the server is stopped.
    51  //
    52  // Note that if `s` is not a *grpc.Server or a *xds.GRPCServer, CSDS will not be
    53  // registered because CSDS generated code is old and doesn't support interface
    54  // `grpc.ServiceRegistrar`.
    55  // https://github.com/envoyproxy/go-control-plane/issues/403
    56  func Register(s grpc.ServiceRegistrar) (cleanup func(), _ error) {
    57  	return internaladmin.Register(s)
    58  }