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

View File

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

View File

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

View File

@ -1,8 +1,9 @@
package main
import (
"git.fjla.uk/owlboard/mq-client/helpers"
)
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
}