Documentation ¶
Overview ¶
Package grpcserver is a generic gRPC server manager Copyright 2018 Portworx
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package grpcserver is a generic gRPC server manager Copyright 2018 Portworx
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package grpcserver is a generic gRPC server manager Copyright 2018 Portworx
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Variables
- func AddMetadataToContext(ctx context.Context, k, v string) context.Context
- func Connect(address string, dialOptions []grpc.DialOption) (*grpc.ClientConn, error)
- func ConnectWithTimeout(address string, dialOptions []grpc.DialOption, timeout time.Duration) (*grpc.ClientConn, error)
- func GetMetadataValueFromKey(ctx context.Context, k string) string
- func GetMethodInformation(constPath, fullmethod string) (service, api string)
- func GetTlsDialOptions(caCertData []byte) ([]grpc.DialOption, error)
- type CredsInjector
- type GrpcServer
- type GrpcServerConfig
- type Server
Constants ¶
This section is empty.
Variables ¶
var (
DefaultConnectionTimeout = 1 * time.Minute
)
Functions ¶
func AddMetadataToContext ¶
func Connect ¶
func Connect(address string, dialOptions []grpc.DialOption) (*grpc.ClientConn, error)
Connect to address by grpc
func ConnectWithTimeout ¶
func ConnectWithTimeout(address string, dialOptions []grpc.DialOption, timeout time.Duration) (*grpc.ClientConn, error)
ConnectWithTimeout to address by grpc with timeout
func GetMethodInformation ¶
GetMethodInformation returns the service and API of a gRPC fullmethod string. For example, if the full method is:
/openstorage.api.OpenStorage<service>/<method>
Then, to extract the service and api we would call it as follows:
s, a := GetMethodInformation("openstorage.api.OpenStorage", info.FullMethod) where info.FullMethod comes from the gRPC interceptor
func GetTlsDialOptions ¶
func GetTlsDialOptions(caCertData []byte) ([]grpc.DialOption, error)
GetTlsDialOptions returns the appropriate gRPC dial options to connect to a gRPC server over TLS. If caCertData is nil then it will use the CA from the host.
Types ¶
type CredsInjector ¶
type CredsInjector struct {
// contains filtered or unexported fields
}
CredsInjector implements credentials.PerRPCCredentials interface
func NewCredsInjector ¶
func NewCredsInjector(generator func() (string, error), tlsEnabled bool) *CredsInjector
NewCredsInjector creates gRPC interceptor to inject Authorization token in requests
func (*CredsInjector) GetRequestMetadata ¶
GetRequestMetadata checks JWT token expiration time and invokes token generator function to get new token if that is needed
func (*CredsInjector) RequireTransportSecurity ¶
func (i *CredsInjector) RequireTransportSecurity() bool
func (*CredsInjector) ResetToken ¶
func (i *CredsInjector) ResetToken()
ResetToken makes CredsInjector to invoke token generation next time when GetRequestMetadata is invoked
type GrpcServer ¶
type GrpcServer struct {
// contains filtered or unexported fields
}
GrpcServer is a server manager for gRPC implementations
func New ¶
func New(config *GrpcServerConfig) (*GrpcServer, error)
New creates a gRPC server on the specified port and transport.
func (*GrpcServer) Address ¶
func (s *GrpcServer) Address() string
Address returns the address of the server which can be used by clients to connect.
func (*GrpcServer) IsRunning ¶
func (s *GrpcServer) IsRunning() bool
IsRunning returns true if the server is currently running
func (*GrpcServer) Start ¶
func (s *GrpcServer) Start(register func(grpcServer *grpc.Server)) error
Start is used to start the server. It will return an error if the server is already runnig.
func (*GrpcServer) StartWithServer ¶
func (s *GrpcServer) StartWithServer(server func() *grpc.Server) error
StartWithServer is used to start the server. It will return an error if the server is already runnig.
func (*GrpcServer) Stop ¶
func (s *GrpcServer) Stop()
Stop is used to stop the gRPC server. It can be called multiple times. It does nothing if the server has already been stopped.
type GrpcServerConfig ¶
type GrpcServerConfig struct { Name string Net string Address string Opts []grpc.ServerOption }
GrpcServerConfig provides the configuration to the the gRPC server created by NewGrpcServer()
type Server ¶
type Server interface { // Start the server. If called on a running server it will return an error. Start() error // Stop the server. If called on a stopped server it will have no effect Stop() // IsRunning tell the caller if the server is currently running IsRunning() bool // Address returns the address used by clients to connect to the server Address() string }
Server is an interface to a gRPC server which provides an implementation of an exported gRPC interface