Documentation ¶
Overview ¶
Copyright 2024 Outernet Council Foundation
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 server provides a collection of server implementations for the Cosmic Connector application. It includes three main server types: GrpcServer, ChannelzServer, and PprofServer, all implementing the common Server interface.
Server Types:
- GrpcServer: Handles the main gRPC communication for the Federation service
- ChannelzServer: Provides gRPC channelz monitoring capabilities
- PprofServer: Exposes Go runtime profiling data via HTTP endpoints
Each server implementation provides consistent Start and Shutdown methods for lifecycle management. The servers can be used independently or together as part of a larger application.
Example usage:
import ( "context" "github.com/rs/zerolog" "aalyria.com/spacetime/apps/cosmicconnector/server" "aalyria.com/spacetime/apps/cosmicconnector/handler" ) func main() { logger := zerolog.New(os.Stdout) // Create a new gRPC server federationHandler := handler.NewFederationHandler() grpcServer := server.NewGrpcServer(8080, federationHandler, logger) // Start the server ctx := context.Background() if err := grpcServer.Start(ctx); err != nil { logger.Fatal().Err(err).Msg("Failed to start gRPC server") } // Graceful shutdown if err := grpcServer.Shutdown(ctx); err != nil { logger.Error().Err(err).Msg("Error during server shutdown") } }
The Server interface ensures consistent behavior across all server implementations:
type Server interface { Start(ctx context.Context) error Shutdown(ctx context.Context) error }
All server implementations use structured logging via zerolog and support graceful shutdown operations. They are designed to be concurrent-safe and suitable for production deployments.
Copyright 2024 Outernet Council Foundation ¶
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 2024 Outernet Council Foundation ¶
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 ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelzServer ¶
type ChannelzServer struct {
// contains filtered or unexported fields
}
ChannelzServer implements the Server interface for Channelz service.
func NewChannelzServer ¶
func NewChannelzServer(address string, logger zerolog.Logger) *ChannelzServer
NewChannelzServer creates a new ChannelzServer with the given address.
type GrpcServer ¶
type GrpcServer struct { pb.UnimplementedFederationServer // contains filtered or unexported fields }
GrpcServer implements the Server interface for gRPC services.
func NewGrpcServer ¶
func NewGrpcServer(port int, handler handler.FederationHandler, logger zerolog.Logger) *GrpcServer
NewGrpcServer creates a new GrpcServer with the given port, handler, and logger.
type PprofServer ¶
type PprofServer struct {
// contains filtered or unexported fields
}
PprofServer implements the Server interface for pprof HTTP endpoints.
func NewPprofServer ¶
func NewPprofServer(address string, logger zerolog.Logger) *PprofServer
NewPprofServer creates a new PprofServer with the given address and logger.