diff --git a/app.go b/server/app.go similarity index 85% rename from app.go rename to server/app.go index 23dc1003d..565850eae 100644 --- a/app.go +++ b/server/app.go @@ -1,4 +1,4 @@ -package main +package server import ( "net/http" @@ -14,32 +14,32 @@ import ( "github.com/go-chi/cors" ) -type App struct { +type Server struct { Importer *scanner.Importer router *chi.Mux } -func NewApp(importer *scanner.Importer) *App { - a := &App{Importer: importer} +func New(importer *scanner.Importer) *Server { + a := &Server{Importer: importer} initMimeTypes() a.initRoutes() a.initImporter() return a } -func (a *App) MountRouter(path string, subRouter http.Handler) { +func (a *Server) MountRouter(path string, subRouter http.Handler) { a.router.Group(func(r chi.Router) { r.Use(middleware.Logger) r.Mount(path, subRouter) }) } -func (a *App) Run(addr string) { +func (a *Server) Run(addr string) { log.Info("Started CloudSonic server", "address", addr) log.Error(http.ListenAndServe(addr, a.router)) } -func (a *App) initRoutes() { +func (a *Server) initRoutes() { r := chi.NewRouter() r.Use(cors.Default().Handler) @@ -60,11 +60,11 @@ func (a *App) initRoutes() { a.router = r } -func (a *App) initImporter() { +func (a *Server) initImporter() { go a.startPeriodicScans() } -func (a *App) startPeriodicScans() { +func (a *Server) startPeriodicScans() { for { select { case <-time.After(5 * time.Second): diff --git a/mime_types.go b/server/mime_types.go similarity index 98% rename from mime_types.go rename to server/mime_types.go index cac62c64c..f6c9a063f 100644 --- a/mime_types.go +++ b/server/mime_types.go @@ -1,4 +1,4 @@ -package main +package server import "mime" diff --git a/wire_gen.go b/wire_gen.go index 98af43bce..d0b0e9f67 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -13,12 +13,13 @@ import ( "github.com/cloudsonic/sonic-server/persistence" "github.com/cloudsonic/sonic-server/persistence/db_sql" "github.com/cloudsonic/sonic-server/scanner" + "github.com/cloudsonic/sonic-server/server" "github.com/google/wire" ) // Injectors from wire_injectors.go: -func CreateApp(musicFolder string) *App { +func CreateApp(musicFolder string) *server.Server { provider := createPersistenceProvider() checkSumRepository := provider.CheckSumRepository itunesScanner := scanner.NewItunesScanner(checkSumRepository) @@ -29,8 +30,8 @@ func CreateApp(musicFolder string) *App { playlistRepository := provider.PlaylistRepository propertyRepository := provider.PropertyRepository importer := scanner.NewImporter(musicFolder, itunesScanner, mediaFileRepository, albumRepository, artistRepository, artistIndexRepository, playlistRepository, propertyRepository) - app := NewApp(importer) - return app + serverServer := server.New(importer) + return serverServer } func CreateSubsonicAPIRouter() *api.Router { diff --git a/wire_injectors.go b/wire_injectors.go index 04127ecf5..a1b8e6df2 100644 --- a/wire_injectors.go +++ b/wire_injectors.go @@ -9,6 +9,7 @@ import ( "github.com/cloudsonic/sonic-server/itunesbridge" "github.com/cloudsonic/sonic-server/persistence/db_sql" "github.com/cloudsonic/sonic-server/scanner" + "github.com/cloudsonic/sonic-server/server" "github.com/google/wire" ) @@ -35,9 +36,9 @@ var allProviders = wire.NewSet( createPersistenceProvider, ) -func CreateApp(musicFolder string) *App { +func CreateApp(musicFolder string) *server.Server { panic(wire.Build( - NewApp, + server.New, allProviders, )) }