Basic server app with WS connection.
Some checks failed
Linting and tests / Linting (push) Failing after 37s
Some checks failed
Linting and tests / Linting (push) Failing after 37s
This commit is contained in:
17
server/internal/services/core/options/migrations.go
Normal file
17
server/internal/services/core/options/migrations.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
//go:embed migrations
|
||||
var migrations embed.FS
|
||||
|
||||
func (o *options) registerMigrations() error {
|
||||
if err := o.db.RegisterMigrations("core/options", migrations); err != nil {
|
||||
return fmt.Errorf("register migrations: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE IF NOT EXISTS options (
|
||||
id UUID NOT NULL PRIMARY KEY,
|
||||
user_id UUID NOT NULL,
|
||||
key VARCHAR(1024) NOT NULL,
|
||||
value VARCHAR(8192)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS options_user_id_key_idx ON options(user_id, key);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE IF EXISTS options;
|
79
server/internal/services/core/options/options.go
Normal file
79
server/internal/services/core/options/options.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"bunker/server/internal/application"
|
||||
"bunker/server/internal/services/core"
|
||||
)
|
||||
|
||||
var (
|
||||
_ = core.Options(&options{})
|
||||
|
||||
errOptions = errors.New("options core service")
|
||||
)
|
||||
|
||||
type options struct {
|
||||
app *application.Application
|
||||
logger *slog.Logger
|
||||
db core.Database
|
||||
}
|
||||
|
||||
// Initialize initializes service.
|
||||
func Initialize(app *application.Application) error {
|
||||
opts := &options{
|
||||
app: app,
|
||||
}
|
||||
|
||||
if err := app.RegisterService(opts); err != nil {
|
||||
return fmt.Errorf("%w: %w", errOptions, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *options) Configure() error {
|
||||
if err := o.registerMigrations(); err != nil {
|
||||
return fmt.Errorf("configure: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *options) ConnectDependencies() error {
|
||||
databaseRaw := o.app.Service(core.ServiceNameDatabase)
|
||||
if databaseRaw == nil {
|
||||
return fmt.Errorf("connect dependencies: get database service: %w", application.ErrServiceNotFound)
|
||||
}
|
||||
|
||||
database, valid := databaseRaw.(core.Database)
|
||||
if !valid {
|
||||
return fmt.Errorf("connect dependencies: type assert database service: %w", core.ErrDatabaseIsInvalid)
|
||||
}
|
||||
|
||||
o.db = database
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *options) Initialize() error {
|
||||
o.logger = o.app.NewLogger("service", core.ServiceNameOptions)
|
||||
|
||||
o.logger.Info("Initializing...")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *options) Name() string {
|
||||
return core.ServiceNameOptions
|
||||
}
|
||||
|
||||
func (o *options) LaunchStartupTasks() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *options) Shutdown() error {
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user