separaded endpoints + cleaned page templates + added constants to time formatting
Some checks failed
Tests / Run Go Tests (push) Failing after 1m34s
Some checks failed
Tests / Run Go Tests (push) Failing after 1m34s
This commit is contained in:
@@ -14,7 +14,7 @@ type FileLog struct {
|
||||
var Logs map[string]FileLog = make(map[string]FileLog)
|
||||
|
||||
func NewAudit() (i *log.Logger, close func() error) {
|
||||
LOG_FILE := "logs/" + time.Now().Format("2006-01-02") + ".log"
|
||||
LOG_FILE := "logs/" + time.Now().Format(time.DateOnly) + ".log"
|
||||
logFile, err := os.OpenFile(LOG_FILE, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
|
||||
31
Backend/helper/paramParser/main.go
Normal file
31
Backend/helper/paramParser/main.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package paramParser
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ParamsParser struct {
|
||||
urlParams url.Values
|
||||
}
|
||||
|
||||
func New(_urlParams url.Values) ParamsParser {
|
||||
return ParamsParser{
|
||||
urlParams: _urlParams,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ParamsParser) ParseTimestamp(key string, format string, fallback time.Time) time.Time {
|
||||
paramTimestamp := p.urlParams.Get(key)
|
||||
if paramTimestamp == "" {
|
||||
return fallback
|
||||
}
|
||||
if timestamp, err := time.Parse(format, paramTimestamp); err == nil {
|
||||
return timestamp
|
||||
} else {
|
||||
slog.Warn("Error parsing HTTP Params to timestamp", slog.Any("key", key), slog.Any("error", err))
|
||||
return fallback
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
)
|
||||
|
||||
func TestGetMonday(t *testing.T) {
|
||||
isMonday, err := time.Parse("2006-01-02", "2025-07-14")
|
||||
notMonday, err := time.Parse("2006-01-02", "2025-07-16")
|
||||
isMonday, err := time.Parse(time.DateOnly, "2025-07-14")
|
||||
notMonday, err := time.Parse(time.DateOnly, "2025-07-16")
|
||||
if err != nil || isMonday.Equal(notMonday) {
|
||||
t.Errorf("U stupid? %e", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user