Registry - File
Integration
Code Source: https://github.com/gogf/examples/tree/main/registry/file
Description
This example demonstrates how to use File-based service registry with GoFrame
applications. It shows how to:
- Register services using file system
- Discover services from files
- Implement simple service discovery
- Build basic distributed systems
Structure
.
├── client/ # Client example
│ └── client.go # Client implementation with file-based discovery
├── server/ # Server example
│ └── server.go # Server implementation with file registration
├── go.mod # Go module file
└── go.sum # Go module checksums
Features
The example showcases the following features:
-
Service Registration
- File-based service registration
- Simple metadata storage
- Local file system integration
- Automatic file management
-
Service Discovery
- File-based service discovery
- Local service lookup
- Basic load balancing
- Simple failover support
-
Protocol Support
HTTP
services- Extensible for other protocols
Requirements
- Go 1.22 or higher
- Git
- GoFrame
- GoFrame File Registry
Prerequisites
No additional infrastructure required. The example uses the local file system for service registration and discovery.
Usage
-
Start the server:
cd server
go run server.go -
Run the client:
cd client
go run client.go
Implementation Details
The example demonstrates:
- File-based registry configuration
- Service registration process
- Service discovery mechanism
- Basic health check implementation
- Simple load balancing strategy
Notes
- Uses local file system
- Suitable for development and testing
- Simple to set up and use
- No external dependencies
- File-based persistence
- Basic service discovery
- Limited scalability
- Consider security in production
- Handle file permissions properly
- Implement proper error handling
- Monitor file system usage
- Clean up old registrations