rephrase service file

and move RPC structure back to gossa.go
This commit is contained in:
Pierre Dubouilh 2021-12-22 14:27:18 +01:00 committed by Pierre Dubouilh
parent d99d975f70
commit bf4be929f5
5 changed files with 25 additions and 23 deletions

View file

@ -3,7 +3,6 @@ package main
import ( import (
"archive/zip" "archive/zip"
"compress/gzip" "compress/gzip"
"context"
_ "embed" _ "embed"
"encoding/json" "encoding/json"
"errors" "errors"
@ -18,14 +17,17 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"os/signal"
"path/filepath" "path/filepath"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"time"
) )
type rpcCall struct {
Call string `json:"call"`
Args []string `json:"args"`
}
var rootPath = "" var rootPath = ""
var handler http.Handler var handler http.Handler
@ -244,14 +246,15 @@ func main() {
check(err) check(err)
server := &http.Server{Addr: *host + ":" + *port, Handler: handler} server := &http.Server{Addr: *host + ":" + *port, Handler: handler}
go func() { // clean shutdown - used only for coverage test
sigchan := make(chan os.Signal, 1) // go func() {
signal.Notify(sigchan, os.Interrupt) // sigchan := make(chan os.Signal, 1)
<-sigchan // signal.Notify(sigchan, os.Interrupt)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) // <-sigchan
defer cancel() // ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
server.Shutdown(ctx) // defer cancel()
}() // server.Shutdown(ctx)
// }()
if !*ro { if !*ro {
http.HandleFunc(*extraPath+"rpc", rpc) http.HandleFunc(*extraPath+"rpc", rpc)
@ -260,6 +263,7 @@ func main() {
http.HandleFunc(*extraPath+"zip", zipRPC) http.HandleFunc(*extraPath+"zip", zipRPC)
http.HandleFunc("/", doContent) http.HandleFunc("/", doContent)
handler = http.StripPrefix(*extraPath, http.FileServer(http.Dir(rootPath))) handler = http.StripPrefix(*extraPath, http.FileServer(http.Dir(rootPath)))
fmt.Printf("Gossa starting on directory %s\nListening on http://%s:%s%s\n", rootPath, *host, *port, *extraPath) fmt.Printf("Gossa starting on directory %s\nListening on http://%s:%s%s\n", rootPath, *host, *port, *extraPath)
if err = server.ListenAndServe(); err != http.ErrServerClosed { if err = server.ListenAndServe(); err != http.ErrServerClosed {
check(err) check(err)

View file

@ -41,11 +41,6 @@ type pageTemplate struct {
RowsFolders []rowTemplate RowsFolders []rowTemplate
} }
type rpcCall struct {
Call string `json:"call"`
Args []string `json:"args"`
}
var host = flag.String("h", "127.0.0.1", "host to listen to") var host = flag.String("h", "127.0.0.1", "host to listen to")
var port = flag.String("p", "8001", "port to listen to") var port = flag.String("p", "8001", "port to listen to")
var extraPath = flag.String("prefix", "/", "url prefix at which gossa can be reached, e.g. /gossa/ (slashes of importance)") var extraPath = flag.String("prefix", "/", "url prefix at which gossa can be reached, e.g. /gossa/ (slashes of importance)")

View file

@ -14,14 +14,13 @@ a [simple UI](https://github.com/pldubouilh/gossa-ui) comes as default, featurin
* 🔍 files/directories browser & handler * 🔍 files/directories browser & handler
* 📩 drag-and-drop uploader * 📩 drag-and-drop uploader
* 🥂 fast golang static server * 🥂 fast golang static server
* 💾 90s web UI that prints in ms * 💾 90s web UI that prints in milliseconds
* 📸 picture browser * 📸 video streaming & picture browser
* 📽️ video streaming * ✍️ simple note editor
* ✍️ simple text/note editor
* ⌨️ keyboard navigation * ⌨️ keyboard navigation
* 🚀 lightweight codebase and dependency free * 🚀 lightweight and dependency free codebase
* 🔒 >95% test coverage and reproducible builds * 🔒 >95% test coverage and reproducible builds
* 💑 easy/secure multi account setup, read-only mode * 💑 easy multi account setup, read-only mode
* ✨ PWA enabled * ✨ PWA enabled
### build ### build

View file

@ -11,7 +11,7 @@ use the `service` file provided here to use as a systemd service.
% systemctl --user start gossa % systemctl --user start gossa
# enable at boot time # enable at boot time
% systemctl --user start gossa % systemctl --user enable gossa
``` ```
## run with docker ## run with docker

View file

@ -1,9 +1,13 @@
[Unit] [Unit]
Description=Gossa service for mytestfolder Description=Gossa service for mytestfolder
Wants=network-online.target
After=network-online.target
# note: its better to use absolute paths here # note: its better to use absolute paths here
[Service] [Service]
ExecStart=gossa /home/joe/mytestfolder ExecStart=gossa /home/joe/mytestfolder
Restart=always
RestartSec=30
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target