storage.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package kyoketsu
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. "git.aetherial.dev/aeth/kyoketsu/pkg/scan"
  7. "go.mongodb.org/mongo-driver/mongo"
  8. "go.mongodb.org/mongo-driver/mongo/options"
  9. )
  10. type TopologyDatabaseIO interface {
  11. AddHostToDb(*scan.TcpScanHost) error // Add a host to the hosts table
  12. UpdateHostEntry(string, *scan.TcpScanHost) error //Update a host entry, indexing by its ip address
  13. RemoveHostEntry(string) error
  14. }
  15. type MongoClient struct {
  16. conn *mongo.Client
  17. }
  18. func NewMongoClient(host string, port int) *MongoClient {
  19. ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
  20. defer cancel()
  21. client, err := mongo.Connect(ctx, options.Client().ApplyURI(fmt.Sprintf("mongodb://%s:%v", host, port)))
  22. defer func() {
  23. if err = client.Disconnect(ctx); err != nil {
  24. panic(err)
  25. }
  26. }()
  27. return &MongoClient{conn: client}
  28. }
  29. func (m *MongoClient) addDocument(id string, data interface{}) error {
  30. return nil
  31. }
  32. func (m *MongoClient) AddHostToDb(host *scan.TcpScanHost) error {
  33. return nil
  34. }
  35. func (m *MongoClient) UpdateHostEntry(id string, host *scan.TcpScanHost) error {
  36. return nil
  37. }
  38. func (m *MongoClient) RemoveHostEntry(id string) error {
  39. return nil
  40. }