package kyoketsu import ( "context" "fmt" "time" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" ) type TopologyDatabaseIO interface { /* This interface defines the Input and output methods that will be necessary for an appropriate implementation of the data storage that the distributed system will use. When I get around to implementing the client-to-client format of this, it could be anything. */ AddHostToDb(*Host) error // Add a host to the hosts table UpdateHostEntry(string, *Host) error //Update a host entry, indexing by its ip address RemoveHostEntry(string) error // Remove a host from the database } type MongoClient struct { conn *mongo.Client } func NewMongoClient(host string, port int) *MongoClient { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() client, err := mongo.Connect(ctx, options.Client().ApplyURI(fmt.Sprintf("mongodb://%s:%v", host, port))) defer func() { if err = client.Disconnect(ctx); err != nil { panic(err) } }() return &MongoClient{conn: client} } func (m *MongoClient) addDocument(id string, data interface{}) error { return nil } func (m *MongoClient) AddHostToDb(host *Host) error { return nil } func (m *MongoClient) UpdateHostEntry(id string, host *Host) error { return nil } func (m *MongoClient) RemoveHostEntry(id string) error { return nil }