Organisation of code

This commit is contained in:
Fred Boniface 2023-07-15 23:00:48 +01:00
parent a3867016d1
commit 0b134ee666
6 changed files with 23 additions and 16 deletions

5
src/database/access.go Normal file
View File

@ -0,0 +1,5 @@
package database
func PutMany(collection string, data []Service) bool {
return false
}

View File

@ -1,6 +1,8 @@
package main package database
import ( import (
"git.fjla.uk/owlboard/mq-client/helpers"
"context" "context"
"time" "time"
"fmt" "fmt"
@ -10,25 +12,19 @@ import (
// "go.mongodb.org/mongo-driver/mongo/readpref" // "go.mongodb.org/mongo-driver/mongo/readpref"
) )
type Service struct { // Provide the DB Connection to other functions
id string var MongoClient (*mongo.Client) = initDataAccess()
}
var client (*mongo.Client) = initDataAccess()
// Initialise the DB Connection
func initDataAccess() (*mongo.Client) { func initDataAccess() (*mongo.Client) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()
client, err := mongo.Connect(ctx, options.Client().ApplyURI(dbUri)) client, err := mongo.Connect(ctx, options.Client().ApplyURI(dbUri))
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
Log("Error connecting to database", 4) helpers.Log("Error connecting to database", 4)
} else { } else {
Log("Connected to Database", 1) helpers.Log("Connected to Database", 1)
} }
return client return client
} }
func PutMany(collection string, data []Service) bool {
return false
}

View File

@ -1,4 +1,4 @@
package main package helpers
import ( import (
"os" "os"
@ -8,7 +8,7 @@ import (
// Version Constants // Version Constants
const versionNum string = "2023.7.1" const versionNum string = "2023.7.1"
const versionSuffix string = "beta" const versionSuffix string = "beta"
const versionStr string = versionNum + "-" + versionSuffix const Version string = versionNum + "-" + versionSuffix
// Environment Variables // Environment Variables
var runtime string = getRuntime() var runtime string = getRuntime()

View File

@ -1,4 +1,4 @@
package main package helpers
import ( import (
"fmt" "fmt"

View File

@ -1,8 +1,9 @@
package main package main
import ( import (
"git.fjla.uk/owlboard/mq-client/helpers"
) )
func main() { func main() {
Out("Initialised OwlBoard MQ Client " + versionStr, 0) helpers.Out("Initialised OwlBoard MQ Client " + helpers.Version, 0)
} }

5
src/types/service.go Normal file
View File

@ -0,0 +1,5 @@
package types
type Service struct {
id string
}