Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging #60

Merged
merged 9 commits into from
Oct 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: logging
HilkopterBob committed Oct 8, 2024

Verified

This commit was signed with the committer’s verified signature.
matthewnessworthy Matthew Nessworthy
commit d93eb34f2669d33894cecbb36cb232e998e4b761
15 changes: 6 additions & 9 deletions db/db.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package db

import (
"fmt"
"packagelock/config"
"packagelock/logger"

"github.com/surrealdb/surrealdb.go"
)
@@ -17,41 +17,38 @@ func InitDB() error {

db, err := surrealdb.New("ws://" + dbAddress + ":" + dbPort + "/rpc")
if err != nil {
errorMessage := fmt.Sprintf(` Couldn't connect to DB! Got: '%s'.
logger.Logger.Errorf(` Couldn't connect to DB! Got: '%s'.
1. Check the config for a wrong Address/Port (Currently: %s:%s)
2. Check if the DB is reachable (eg. a Ping). Check the Firewalls if there.
3. Consult the PackageLock Doc's! 🚀
Golang Trace Logs:
`, err.Error(), dbAddress, dbPort)
fmt.Println(errorMessage)
panic(err)
}

if _, err = db.Signin(map[string]interface{}{
// TODO: get user&password from Conf
"user": dbUsername,
"pass": dbPasswd,
}); err != nil {
errorMessage := fmt.Sprintf(` Couldn't connect to DB! Got: '%s'.
logger.Logger.Errorf(` Couldn't connect to DB! Got: '%s'.
1. Check the config for a wrong DB-Username/Password (Currently: %s/<read the config!>)
3. Consult the PackageLock Doc's! 🚀
Golang Trace Logs:
`, err.Error(), dbUsername)
fmt.Println(errorMessage)
panic(err)
}

if _, err = db.Use("PackageLock", "db1.0"); err != nil {
// No error handling possible, as we need to use this db
panic(err)
logger.Logger.Panicf("Couldn't Use 'PackageLock' Namespace and 'db1.0' Database. Got: %s", err)
}

DB = db

logger.Logger.Infof("Successfully Connected to DB, at: %s:%s", dbAddress, dbPort)
return nil
}

// INFO: If you use this, fix it!
// INFO: And add logging/error handling
func Select(tablename string, SliceOfType interface{}) error {
transaction, err := DB.Select(tablename)
if err != nil {