- Fix 10 err113 violations: extract dynamic errors to package-level sentinels - Fix 12 errcheck violations: handle unchecked error returns in player, metadata, and config packages - Fix 4 revive stutter warnings: rename player.PlayerState to player.State, player.PlayerVolume to player.Volume, queue.QueueTrack to queue.Track, queue.QueueState to queue.State - Fix 2 staticcheck SA4001: simplify *&x to x in assets handler - Fix 5 unused constants: remove dead AudioFileType iota block in models - Fix gci/gofumpt/wsl formatting issues across multiple files - Add gofumpt module-path setting to .golangci.yml for correct import grouping - Fix player test: gate integration test behind YELLOWJACKET_INTEGRATION env var instead of only skipping in CI, and replace t.Errorf+t.Failed with t.Fatalf - Remove continue-on-error from golangci-lint CI step so linting is now required
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
// Package library manages the music library and its configuration.
|
|
package library
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
var errNotDirectory = errors.New("path is not a directory")
|
|
|
|
// Config holds Library config data.
|
|
type Config struct {
|
|
DirectoryPath Directory `form:"Directory" schema:"directory,required"`
|
|
}
|
|
|
|
// Directory represents a filesystem path to a music directory.
|
|
type Directory string
|
|
|
|
// NewConfig creates a validated library configuration.
|
|
func NewConfig(dir string) (*Config, error) {
|
|
config := &Config{
|
|
DirectoryPath: Directory(dir),
|
|
}
|
|
if err := config.Validate(); err != nil {
|
|
return nil, fmt.Errorf("validation error for new library config: %w", err)
|
|
}
|
|
|
|
return config, nil
|
|
}
|
|
|
|
// Validate checks that the configured directory exists.
|
|
func (c *Config) Validate() error {
|
|
if len(c.DirectoryPath) != 0 {
|
|
dirInfo, err := os.Stat(string(c.DirectoryPath))
|
|
if err != nil {
|
|
return fmt.Errorf("problem getting info on library dir (%s): %w", c.DirectoryPath, err)
|
|
}
|
|
|
|
if !dirInfo.IsDir() {
|
|
return fmt.Errorf("%s: %w", c.DirectoryPath, errNotDirectory)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|