Split out setupFilesystem to clean up the code
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
4a6ab368c6
commit
50f4709b4c
106
server.go
106
server.go
|
@ -22,7 +22,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var VERSION = "1.4.4"
|
var VERSION = "1.4.5"
|
||||||
|
|
||||||
func packageName(name string) string {
|
func packageName(name string) string {
|
||||||
if index := strings.Index(name, "_"); index != -1 {
|
if index := strings.Index(name, "_"); index != -1 {
|
||||||
|
@ -75,6 +75,60 @@ func main() {
|
||||||
log.WithError(err).Fatalln("unable to marshal config file, exiting...", err)
|
log.WithError(err).Fatalln("unable to marshal config file, exiting...", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := createDirs(conf); err != nil {
|
||||||
|
log.WithError(err).Fatalln("error creating directory structure, exiting")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := setupPgp(conf); err != nil {
|
||||||
|
log.WithError(err).Fatalln("error loading pgp key, exiting")
|
||||||
|
}
|
||||||
|
|
||||||
|
setupFilesystem()
|
||||||
|
|
||||||
|
log.Info("Indexing packages...")
|
||||||
|
|
||||||
|
for _, dist := range conf.Repo.DistroNames() {
|
||||||
|
if err := loadCache(dist); err != nil {
|
||||||
|
log.Info("Unable to load cached data for", dist, "- reindexing")
|
||||||
|
distro := &Distro{Name: dist, Architectures: make(map[string]map[string]*PackageFile)}
|
||||||
|
|
||||||
|
go scanInitialPackages(conf, distro)
|
||||||
|
|
||||||
|
distros[dist] = distro
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
|
httpFs := afero.NewHttpFs(fs)
|
||||||
|
|
||||||
|
mux.Handle("/", http.StripPrefix("/", http.FileServer(httpFs)))
|
||||||
|
mux.HandleFunc("/rescan", requireAuth(rescanHandler))
|
||||||
|
mux.HandleFunc("/upload", requireAuth(uploadHandler))
|
||||||
|
mux.HandleFunc("/delete", requireAuth(deleteHandler))
|
||||||
|
|
||||||
|
bind := fmt.Sprintf(":%d", conf.Http.Port)
|
||||||
|
|
||||||
|
if conf.Http.SSL {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"bind": bind,
|
||||||
|
"certFile": conf.Http.SSLCert,
|
||||||
|
"keyFile": conf.Http.SSLKey,
|
||||||
|
}).Info("Starting with SSL enabled")
|
||||||
|
|
||||||
|
err = http.ListenAndServeTLS(bind, conf.Http.SSLCert, conf.Http.SSLKey, mux)
|
||||||
|
} else {
|
||||||
|
log.WithField("bind", bind).Info("Starting without SSL enabled")
|
||||||
|
|
||||||
|
err = http.ListenAndServe(bind, mux)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Fatalln("Unable to start or keep running due to error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupFilesystem() {
|
||||||
osFs := afero.NewOsFs()
|
osFs := afero.NewOsFs()
|
||||||
|
|
||||||
switch conf.Fs.Driver {
|
switch conf.Fs.Driver {
|
||||||
|
@ -119,56 +173,6 @@ func main() {
|
||||||
|
|
||||||
tmpFs = afero.NewBasePathFs(osFs, baseTempDir)
|
tmpFs = afero.NewBasePathFs(osFs, baseTempDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := createDirs(conf); err != nil {
|
|
||||||
log.WithError(err).Fatalln("error creating directory structure, exiting")
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := setupPgp(conf); err != nil {
|
|
||||||
log.WithError(err).Fatalln("error loading pgp key, exiting")
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("Indexing packages...")
|
|
||||||
|
|
||||||
for _, dist := range conf.Repo.DistroNames() {
|
|
||||||
if err := loadCache(dist); err != nil {
|
|
||||||
log.Info("Unable to load cached data for", dist, "- reindexing")
|
|
||||||
distro := &Distro{Name: dist, Architectures: make(map[string]map[string]*PackageFile)}
|
|
||||||
|
|
||||||
go scanInitialPackages(conf, distro)
|
|
||||||
|
|
||||||
distros[dist] = distro
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
|
||||||
|
|
||||||
httpFs := afero.NewHttpFs(fs)
|
|
||||||
|
|
||||||
mux.Handle("/", http.StripPrefix("/", http.FileServer(httpFs)))
|
|
||||||
mux.HandleFunc("/rescan", requireAuth(rescanHandler))
|
|
||||||
mux.HandleFunc("/upload", requireAuth(uploadHandler))
|
|
||||||
mux.HandleFunc("/delete", requireAuth(deleteHandler))
|
|
||||||
|
|
||||||
bind := fmt.Sprintf(":%d", conf.Http.Port)
|
|
||||||
|
|
||||||
if conf.Http.SSL {
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"bind": bind,
|
|
||||||
"certFile": conf.Http.SSLCert,
|
|
||||||
"keyFile": conf.Http.SSLKey,
|
|
||||||
}).Info("Starting with SSL enabled")
|
|
||||||
|
|
||||||
err = http.ListenAndServeTLS(bind, conf.Http.SSLCert, conf.Http.SSLKey, mux)
|
|
||||||
} else {
|
|
||||||
log.WithField("bind", bind).Info("Starting without SSL enabled")
|
|
||||||
|
|
||||||
err = http.ListenAndServe(bind, mux)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Fatalln("Unable to start or keep running due to error")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func scanInitialPackages(config Conf, dist *Distro) {
|
func scanInitialPackages(config Conf, dist *Distro) {
|
||||||
|
|
Loading…
Reference in New Issue