feat: initial commit
This commit is contained in:
26
internal/setup/quiz_handler.go
Normal file
26
internal/setup/quiz_handler.go
Normal file
@ -0,0 +1,26 @@
|
||||
package setup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"forge.cadoles.com/wpetit/kouiz/internal/config"
|
||||
"forge.cadoles.com/wpetit/kouiz/internal/http/handler/webui/quiz"
|
||||
"forge.cadoles.com/wpetit/kouiz/internal/store"
|
||||
"github.com/glebarez/sqlite"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func NewQuizHandlerFromConfig(ctx context.Context, conf *config.Config) (*quiz.Handler, error) {
|
||||
db, err := gorm.Open(sqlite.Open(string(conf.Store.DSN)), &gorm.Config{})
|
||||
if err != nil {
|
||||
log.Fatalf("[FATAL] %+v", errors.Wrap(err, "could not open store"))
|
||||
}
|
||||
|
||||
if conf.Store.Debug {
|
||||
db = db.Debug()
|
||||
}
|
||||
|
||||
return quiz.NewHandler(store.New(db)), nil
|
||||
}
|
Reference in New Issue
Block a user