move config file loading out of gemlog package

This commit is contained in:
Travis Shears 2025-10-05 16:42:26 +02:00
parent 6b8ba76018
commit dc635db758
6 changed files with 46 additions and 75 deletions

View file

@ -1,9 +1,6 @@
package gemlog
import (
"crypto/rand"
"encoding/hex"
"fmt"
"time"
)
@ -16,6 +13,7 @@ type GemlogEntry struct {
Gemtxt string `json:"gemtxt"`
}
// GemlogListEntry is for showing a list of gemlog entries without the main Gemtxt
type GemlogListEntry struct {
Title string `json:"title"`
Slug string `json:"slug"`
@ -23,25 +21,3 @@ type GemlogListEntry struct {
ID string `json:"id"`
Rev string `json:"rev"`
}
// NewUUID generates a new UUID v4 using crypto/rand
func NewUUID() (string, error) {
uuid := make([]byte, 16)
_, err := rand.Read(uuid)
if err != nil {
return "", fmt.Errorf("failed to generate UUID: %w", err)
}
// Set version (4) and variant bits according to RFC 4122
uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4
uuid[8] = (uuid[8] & 0x3f) | 0x80 // Variant bits
// Format as standard UUID string: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
return fmt.Sprintf("%s-%s-%s-%s-%s",
hex.EncodeToString(uuid[0:4]),
hex.EncodeToString(uuid[4:6]),
hex.EncodeToString(uuid[6:8]),
hex.EncodeToString(uuid[8:10]),
hex.EncodeToString(uuid[10:16]),
), nil
}