mirror of
https://github.com/pldubouilh/gossa
synced 2025-12-06 08:22:32 +01:00
split embedder
This commit is contained in:
parent
65a6087c60
commit
16b31a5047
3 changed files with 57 additions and 51 deletions
4
Makefile
4
Makefile
|
|
@ -53,10 +53,10 @@ watch-test:
|
||||||
ls gossa.go gossa_test.go gossa-ui/* | entr -rc make test
|
ls gossa.go gossa_test.go gossa-ui/* | entr -rc make test
|
||||||
|
|
||||||
build-all:
|
build-all:
|
||||||
${NOCGO} GOOS=linux GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-linux64
|
${NOCGO} GOOS=linux GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-linux-x64
|
||||||
${NOCGO} GOOS=linux GOARCH=arm go build ${FLAGS} -o build-all/gossa-linux-arm
|
${NOCGO} GOOS=linux GOARCH=arm go build ${FLAGS} -o build-all/gossa-linux-arm
|
||||||
${NOCGO} GOOS=linux GOARCH=arm64 go build ${FLAGS} -o build-all/gossa-linux-arm64
|
${NOCGO} GOOS=linux GOARCH=arm64 go build ${FLAGS} -o build-all/gossa-linux-arm64
|
||||||
${NOCGO} GOOS=darwin GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-mac64
|
${NOCGO} GOOS=darwin GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-mac-x64
|
||||||
${NOCGO} GOOS=darwin GOARCH=arm64 go build ${FLAGS} -o build-all/gossa-mac-arm64
|
${NOCGO} GOOS=darwin GOARCH=arm64 go build ${FLAGS} -o build-all/gossa-mac-arm64
|
||||||
${NOCGO} GOOS=windows GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-windows.exe
|
${NOCGO} GOOS=windows GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-windows.exe
|
||||||
|
|
||||||
|
|
|
||||||
49
gossa.go
49
gossa.go
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"context"
|
"context"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"encoding/base64"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
|
|
@ -27,50 +26,9 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var host = flag.String("h", "127.0.0.1", "host 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 symlinks = flag.Bool("symlinks", false, "follow symlinks \033[4mWARNING\033[0m: symlinks will by nature allow to escape the defined path (default: false)")
|
|
||||||
var verb = flag.Bool("verb", false, "verbosity")
|
|
||||||
var skipHidden = flag.Bool("k", true, "\nskip hidden files")
|
|
||||||
var ro = flag.Bool("ro", false, "read only mode (no upload, rename, move, etc...)")
|
|
||||||
var rootPath = ""
|
var rootPath = ""
|
||||||
|
|
||||||
var handler http.Handler
|
var handler http.Handler
|
||||||
|
|
||||||
//go:embed gossa-ui/ui.tmpl
|
|
||||||
var templateStr string
|
|
||||||
var templateParsed *template.Template
|
|
||||||
|
|
||||||
//go:embed gossa-ui/script.js
|
|
||||||
var scriptJs string
|
|
||||||
|
|
||||||
//go:embed gossa-ui/style.css
|
|
||||||
var styleCss string
|
|
||||||
|
|
||||||
//go:embed gossa-ui/favicon.svg
|
|
||||||
var faviconSvg []byte
|
|
||||||
|
|
||||||
type rowTemplate struct {
|
|
||||||
Name string
|
|
||||||
Href template.HTML
|
|
||||||
Size string
|
|
||||||
Ext string
|
|
||||||
}
|
|
||||||
|
|
||||||
type pageTemplate struct {
|
|
||||||
Title template.HTML
|
|
||||||
ExtraPath template.HTML
|
|
||||||
Ro bool
|
|
||||||
RowsFiles []rowTemplate
|
|
||||||
RowsFolders []rowTemplate
|
|
||||||
}
|
|
||||||
|
|
||||||
type rpcCall struct {
|
|
||||||
Call string `json:"call"`
|
|
||||||
Args []string `json:"args"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func check(e error) {
|
func check(e error) {
|
||||||
if e != nil {
|
if e != nil {
|
||||||
panic(e)
|
panic(e)
|
||||||
|
|
@ -284,13 +242,6 @@ func main() {
|
||||||
var err error
|
var err error
|
||||||
rootPath, err = filepath.Abs(rootPath)
|
rootPath, err = filepath.Abs(rootPath)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
templateStr = strings.Replace(templateStr, "css_will_be_here", styleCss, 1)
|
|
||||||
templateStr = strings.Replace(templateStr, "js_will_be_here", scriptJs, 1)
|
|
||||||
templateStr = strings.Replace(templateStr, "favicon_will_be_here", base64.StdEncoding.EncodeToString(faviconSvg), 2)
|
|
||||||
templateParsed, err = template.New("").Parse(templateStr)
|
|
||||||
check(err)
|
|
||||||
|
|
||||||
server := &http.Server{Addr: *host + ":" + *port, Handler: handler}
|
server := &http.Server{Addr: *host + ":" + *port, Handler: handler}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
|
|
||||||
55
gossa_embed.go
Executable file
55
gossa_embed.go
Executable file
|
|
@ -0,0 +1,55 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "embed"
|
||||||
|
"encoding/base64"
|
||||||
|
"flag"
|
||||||
|
"html/template"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed gossa-ui/script.js
|
||||||
|
var scriptJs string
|
||||||
|
|
||||||
|
//go:embed gossa-ui/style.css
|
||||||
|
var styleCss string
|
||||||
|
|
||||||
|
//go:embed gossa-ui/favicon.svg
|
||||||
|
var faviconSvg []byte
|
||||||
|
|
||||||
|
//go:embed gossa-ui/ui.tmpl
|
||||||
|
var templateStr string
|
||||||
|
|
||||||
|
// fill in template
|
||||||
|
var templateCss = strings.Replace(templateStr, "css_will_be_here", styleCss, 1)
|
||||||
|
var templateCssJs = strings.Replace(templateCss, "js_will_be_here", scriptJs, 1)
|
||||||
|
var templateCssJssIcon = strings.Replace(templateCssJs, "favicon_will_be_here", base64.StdEncoding.EncodeToString(faviconSvg), 2)
|
||||||
|
var templateParsed, _ = template.New("").Parse(templateCssJssIcon)
|
||||||
|
|
||||||
|
type rowTemplate struct {
|
||||||
|
Name string
|
||||||
|
Href template.HTML
|
||||||
|
Size string
|
||||||
|
Ext string
|
||||||
|
}
|
||||||
|
|
||||||
|
type pageTemplate struct {
|
||||||
|
Title template.HTML
|
||||||
|
ExtraPath template.HTML
|
||||||
|
Ro bool
|
||||||
|
RowsFiles []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 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 symlinks = flag.Bool("symlinks", false, "follow symlinks \033[4mWARNING\033[0m: symlinks will by nature allow to escape the defined path (default: false)")
|
||||||
|
var verb = flag.Bool("verb", false, "verbosity")
|
||||||
|
var skipHidden = flag.Bool("k", true, "\nskip hidden files")
|
||||||
|
var ro = flag.Bool("ro", false, "read only mode (no upload, rename, move, etc...)")
|
||||||
Loading…
Reference in a new issue