-
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: update dependencies and add GORM models
This commit updates the dependencies in the go.mod file, including adding the indirect dependencies for the packages `github.com/jinzhu/inflection`, `github.com/jinzhu/now`, `github.com/mattn/go-sqlite3`, `gorm.io/driver/sqlite`, and `gorm.io/gorm`. It also adds new GORM models for the database tables `LogEntry`, `Listener`, `Machine`, and `Record`.
- Loading branch information
1 parent
e79a51f
commit 65a262b
Showing
7 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package models | ||
|
||
import ( | ||
"log/slog" | ||
"os" | ||
|
||
"gorm.io/driver/sqlite" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func init() { | ||
db, err := gorm.Open(sqlite.Open("db.sqlite3"), &gorm.Config{}) | ||
if err != nil { | ||
slog.Error("failed to open database", slog.String("error", err.Error())) | ||
os.Exit(1) | ||
} | ||
err = db.AutoMigrate(&LogEntry{}) | ||
if err != nil { | ||
slog.Error("failed to migrate database", slog.String("error", err.Error())) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package models | ||
|
||
import ( | ||
"gorm.io/gorm" | ||
) | ||
|
||
// LogLevel represents the log level of a log entry | ||
type LogLevel string | ||
|
||
const ( | ||
// LogLevelError represents an error log level | ||
LogLevelError LogLevel = "error" | ||
// LogLevelInfo represents an info log level | ||
LogLevelInfo LogLevel = "info" | ||
// LogLevelDebug represents a debug log level | ||
LogLevelDebug LogLevel = "debug" | ||
) | ||
|
||
// LogEntry represents a log entry in the database | ||
type LogEntry struct { | ||
gorm.Model | ||
Level LogLevel | ||
Message string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package models |