formatting
This commit is contained in:
parent
34ac340cad
commit
4082be54e2
9 changed files with 53 additions and 46 deletions
|
@ -3,4 +3,13 @@ services:
|
|||
build: ./server/Dockerfile
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- "./storage/files:/mnt/storage/files"
|
||||
ole:
|
||||
build: ./scanners/ole/Dockerfile
|
||||
ports:
|
||||
- "5000:5000"
|
||||
volumes:
|
||||
- "./storage/files:/mnt/storage/files"
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
FROM python:3-alpine
|
||||
|
||||
# Set environment variables (these can be overridden in `docker-compose.yml` or `docker run`)
|
||||
ENV UPLOAD_FOLDER="/tmp/uploads"
|
||||
ENV FILE_DIRECTORY="/mnt/storage/files/"
|
||||
ENV HOST="127.0.0.1"
|
||||
ENV PORT="5000"
|
||||
ENV DEBUG="True"
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"log/slog"
|
||||
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/spf13/viper"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func ReadConfigFile(configFile string) {
|
||||
setDefaults()
|
||||
if configFile != "" {
|
||||
slog.Info("reading Config file", "file", configFile)
|
||||
viper.SetConfigFile(configFile)
|
||||
} else {
|
||||
viper.AddConfigPath(".")
|
||||
viper.AddConfigPath("/etc/scanfile/")
|
||||
viper.SetConfigName("config")
|
||||
viper.SetConfigType("toml")
|
||||
}
|
||||
viper.SetEnvPrefix("SF")
|
||||
setDefaults()
|
||||
if configFile != "" {
|
||||
slog.Info("reading Config file", "file", configFile)
|
||||
viper.SetConfigFile(configFile)
|
||||
} else {
|
||||
viper.AddConfigPath(".")
|
||||
viper.AddConfigPath("/etc/scanfile/")
|
||||
viper.SetConfigName("config")
|
||||
viper.SetConfigType("toml")
|
||||
}
|
||||
viper.SetEnvPrefix("SF")
|
||||
|
||||
viper.ReadInConfig()
|
||||
viper.AutomaticEnv()
|
||||
if viper.ConfigFileUsed() == "" {
|
||||
viper.WriteConfigAs("./config.toml")
|
||||
}
|
||||
slog.Info("done reading config", "file", viper.ConfigFileUsed())
|
||||
viper.ReadInConfig()
|
||||
viper.AutomaticEnv()
|
||||
if viper.ConfigFileUsed() == "" {
|
||||
viper.WriteConfigAs("./config.toml")
|
||||
}
|
||||
slog.Info("done reading config", "file", viper.ConfigFileUsed())
|
||||
}
|
||||
|
||||
func setDefaults() {
|
||||
// Web
|
||||
viper.SetDefault("web.port", 8080)
|
||||
viper.SetDefault("web.host", "127.0.0.1")
|
||||
viper.SetDefault("web.tls", false)
|
||||
viper.SetDefault("web.cert", "/etc/ssl/certs/ssl-cert-snakeoil.pem")
|
||||
viper.SetDefault("web.key", "/etc/ssl/key/ssl-cert-snakeoil.key")
|
||||
viper.SetDefault("web.loghttp", true)
|
||||
// Web
|
||||
viper.SetDefault("web.port", 8080)
|
||||
viper.SetDefault("web.host", "127.0.0.1")
|
||||
viper.SetDefault("web.tls", false)
|
||||
viper.SetDefault("web.cert", "/etc/ssl/certs/ssl-cert-snakeoil.pem")
|
||||
viper.SetDefault("web.key", "/etc/ssl/key/ssl-cert-snakeoil.key")
|
||||
viper.SetDefault("web.loghttp", true)
|
||||
}
|
||||
|
||||
func SaveConfig() error {
|
||||
return viper.WriteConfig()
|
||||
return viper.WriteConfig()
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ type User struct {
|
|||
}
|
||||
|
||||
func CreateUser(user User) error {
|
||||
log.Println(user)
|
||||
log.Println(user)
|
||||
_, err := db.NamedExec(`
|
||||
INSERT INTO users (
|
||||
username,
|
||||
|
|
|
@ -27,7 +27,6 @@ func Logging(next http.Handler) http.Handler {
|
|||
|
||||
next.ServeHTTP(wrapped, r)
|
||||
|
||||
slog.Info("webserver", "status", wrapped.statusCode, "method", r.Method, "path", r.URL.Path, "duration", time.Since(start))
|
||||
slog.Info("webserver", "status", wrapped.statusCode, "method", r.Method, "path", r.URL.Path, "duration", time.Since(start))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"git.jmbit.de/jmb/scanfile/server/web"
|
||||
"net/http"
|
||||
"git.jmbit.de/jmb/scanfile/server/web"
|
||||
)
|
||||
|
||||
func RegisterRoutes() *http.ServeMux {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", web.IndexWebHandler)
|
||||
mux.Handle("/assets/", http.FileServer(http.FS(web.Files)))
|
||||
mux.Handle("/assets/", http.FileServer(http.FS(web.Files)))
|
||||
return mux
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package server
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"time"
|
||||
"log/slog"
|
||||
|
||||
"git.jmbit.de/jmb/scanfile/server/internal/middlewares"
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@ package session
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"fmt"
|
||||
|
||||
"github.com/gorilla/securecookie"
|
||||
"github.com/gorilla/sessions"
|
||||
|
@ -31,7 +31,7 @@ func sessionStore() sessions.FilesystemStore {
|
|||
workdir, err := os.Getwd()
|
||||
if err != nil {
|
||||
slog.Error("Error determining working directory", "error", err)
|
||||
panic(err)
|
||||
panic(err)
|
||||
}
|
||||
sessionPath = path.Join(workdir, sessionPath)
|
||||
}
|
||||
|
|
|
@ -26,14 +26,13 @@ import (
|
|||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
|
||||
func main() {
|
||||
log.SetOutput(os.Stderr)
|
||||
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, nil)))
|
||||
config.ReadConfigFile("")
|
||||
if viper.GetBool("web.tls") {
|
||||
server.NewServer().ListenAndServeTLS(viper.GetString("web.cert"), viper.GetString("web.key"))
|
||||
} else {
|
||||
server.NewServer().ListenAndServe()
|
||||
}
|
||||
log.SetOutput(os.Stderr)
|
||||
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, nil)))
|
||||
config.ReadConfigFile("")
|
||||
if viper.GetBool("web.tls") {
|
||||
server.NewServer().ListenAndServeTLS(viper.GetString("web.cert"), viper.GetString("web.key"))
|
||||
} else {
|
||||
server.NewServer().ListenAndServe()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue