Draft: big refactor

This commit is contained in:
2025-09-16 16:03:27 +08:00
parent f527230f1e
commit c4f2b0af25
42 changed files with 684 additions and 215 deletions

View File

@@ -11,6 +11,5 @@ func InitDB(ctx context.Context, db *bun.DB) error {
return db.ResetModel(ctx,
(*models.User)(nil),
(*models.UserStatus)(nil),
(*models.Room)(nil),
)
}

View File

@@ -14,7 +14,7 @@ func ReadConfig(ctx context.Context) {
viper.AddConfigPath(".")
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
tracing.Logger.Ctx(ctx).
tracing.Logger.
Panic("failed to read config file",
zap.Error(err))
panic(err)

50
utils/udp.go Normal file
View File

@@ -0,0 +1,50 @@
package workflows
import (
"fmt"
"net"
"github.com/vmihailenco/msgpack/v5"
)
type UDPPayload struct {
MagicNumber int `msgpack:"magicNumber"`
Data string `msgpack:"data"`
}
const (
BUFFER_SIZE int = 1024
MAGIC_NUMBER int = 114514
)
func ListenUDP(port string) (string, error) {
addr, err := net.ResolveUDPAddr("udp", ":"+port)
if err != nil {
return nil, fmt.Errorf("failed to resolve address, %w", err)
}
conn, err := net.ListenUDP("udp", addr)
if err != nil {
return nil, fmt.Errorf("failed to listen on addr '%v', %w", addr, err)
}
defer conn.Close()
for {
buffer := make([]byte, BUFFER_SIZE)
n, clientAddr, err := conn.ReadFromUDP(buffer)
if err != nil {
continue
}
var payload UDPPayload
err = msgpack.Unmarshal(buffer[:n], &payload)
if err == nil && payload.MagicNumber == MAGIC_NUMBER {
return payload.Data
}
}
}
func SendPayload(endpoint, data string) error {
}