Draft: feat login

This commit is contained in:
2025-09-05 03:59:25 +08:00
parent 6d7074198f
commit 3a9ffe7857
43 changed files with 1894 additions and 91 deletions

15
utils/initDB.go Normal file
View File

@@ -0,0 +1,15 @@
package utils
import (
"context"
"gitea.konchin.com/ytshih/inp2025/game/models"
"github.com/uptrace/bun"
)
func InitDB(ctx context.Context, db *bun.DB) error {
return db.ResetModel(ctx,
(*models.User)(nil),
(*models.UserStatus)(nil),
)
}

23
utils/readConfig.go Normal file
View File

@@ -0,0 +1,23 @@
package utils
import (
"context"
"gitea.konchin.com/ytshih/inp2025/game/tracing"
"github.com/spf13/viper"
"go.uber.org/zap"
)
func ReadConfig(ctx context.Context) {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
tracing.Logger.Ctx(ctx).
Panic("failed to read config file",
zap.Error(err))
panic(err)
}
}
}

14
utils/tick.go Normal file
View File

@@ -0,0 +1,14 @@
package utils
import (
"time"
"gitea.konchin.com/ytshih/inp2025/game/types"
tea "github.com/charmbracelet/bubbletea"
)
func Tick(d time.Duration) tea.Cmd {
return tea.Tick(d, func(t time.Time) tea.Msg {
return types.TickMsg(t)
})
}