init
This commit is contained in:
commit
2586161abd
49 changed files with 4171 additions and 0 deletions
49
web/app/app.go
Normal file
49
web/app/app.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"git.sleepycat.moe/sam/mercury/config"
|
||||
"git.sleepycat.moe/sam/mercury/internal/database/sql"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
Router chi.Router
|
||||
|
||||
Config config.Config
|
||||
Database *sql.Base
|
||||
}
|
||||
|
||||
func NewApp(cfg config.Config, db *sql.Base) *App {
|
||||
app := &App{
|
||||
Router: chi.NewRouter(),
|
||||
Config: cfg,
|
||||
Database: db,
|
||||
}
|
||||
|
||||
app.Router.Use(app.Logger)
|
||||
app.Router.Use(middleware.Recoverer)
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
func (a *App) Account(q ...sql.Querier) *sql.AccountStore {
|
||||
if len(q) == 0 || q[0] == nil {
|
||||
return sql.NewAccountStore(a.Database.PoolQuerier())
|
||||
}
|
||||
return sql.NewAccountStore(q[0])
|
||||
}
|
||||
|
||||
func (a *App) Blog(q ...sql.Querier) *sql.BlogStore {
|
||||
if len(q) == 0 || q[0] == nil {
|
||||
return sql.NewBlogStore(a.Database.PoolQuerier())
|
||||
}
|
||||
return sql.NewBlogStore(q[0])
|
||||
}
|
||||
|
||||
func (a *App) Post(q ...sql.Querier) *sql.PostStore {
|
||||
if len(q) == 0 || q[0] == nil {
|
||||
return sql.NewPostStore(a.Database.PoolQuerier())
|
||||
}
|
||||
return sql.NewPostStore(q[0])
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue