1
0
Fork 0

Compare commits

...

5 Commits

6 changed files with 33 additions and 15 deletions

View File

@ -8,17 +8,18 @@ PREFIX:=/usr/local
VERSION=23.32.0
FLAGS=-buildmode=pie -modcacherw -mod=readonly -trimpath
LDFLAGS=-ldflags "-s -w -X main.version=${VERSION}" -tags osusergo,netgo
all: web/*.jade.go ${TARGET}
.PHONY: run install uninstall clean
.PHONY: ${TARGET}
${TARGET}:
go build -o bin/$@ ${LDFLAGS} cmd/$@/main.go
${TARGET}: web/*.jade.go
go build -o bin/$@ ${LDFLAGS} ${FLAGS} cmd/$@/main.go
web/*.jade.go: web/templates/*.jade
ifeq (,$(wildcard $(shell go env GOPATH)/bin/jade))
go install github.com/Joker/jade/cmd/jade@latest
endif
go generate web/web.go
run:
@ -33,3 +34,7 @@ uninstall:
rm ${DESTDIR}${PREFIX}/bin/${TARGET}
rm ${DESTDIR}/${SYSDDIR}/${TARGET}.service
clean:
rm -f web/*.jade.go
go clean

2
go.mod
View File

@ -2,4 +2,4 @@ module dwelling-files
go 1.16
require git.arav.su/Arav/httpr v0.3.1
require git.arav.su/Arav/httpr v0.3.2

4
go.sum
View File

@ -1,2 +1,2 @@
git.arav.su/Arav/httpr v0.3.1 h1:8ba90SJ4XYUWfIlC3V0Zuw3+CcOb9IYVkOZ/2mB9JO0=
git.arav.su/Arav/httpr v0.3.1/go.mod h1:z0SVYwe5dBReeVuFU9QH2PmBxICJwchxqY5OfZbeVzU=
git.arav.su/Arav/httpr v0.3.2 h1:a+ifu+9+FnQe6p/Kd4kgTDKAFN6zBOJjBTMjbAuHxVk=
git.arav.su/Arav/httpr v0.3.2/go.mod h1:z0SVYwe5dBReeVuFU9QH2PmBxICJwchxqY5OfZbeVzU=

View File

@ -9,7 +9,7 @@ import (
const FileDateFormat = "2006-01-02 15:04:05 MST"
type DirStats struct {
type DirStat struct {
Files int64
FilesSize string
Directories int64
@ -22,16 +22,16 @@ type DirEntry struct {
Size string
}
func ScanDirectory(path, urlBase string) (entries []DirEntry, stats DirStats, err error) {
var dirEntries []DirEntry = make([]DirEntry, 0)
var fileEntries []DirEntry = make([]DirEntry, 0)
var totalFilesSize int64 = 0
func ScanDirectory(path, urlBase string) (entries []DirEntry, stats DirStat, err error) {
dir, err := os.ReadDir(path)
if err != nil {
return
}
var dirEntries []DirEntry = make([]DirEntry, 0)
var fileEntries []DirEntry = make([]DirEntry, 0)
var totalFilesSize int64 = 0
for _, ent := range dir {
entry, _ := ent.Info()

13
pkg/files/files_test.go Normal file
View File

@ -0,0 +1,13 @@
package files
import "testing"
const path = "/mnt/data/music/Various"
const urlBase = "/srv/ftp/"
func BenchmarkScanDirectory(b *testing.B) {
for i := 0; i < b.N; i++ {
/*e, _, _ :=*/ ScanDirectory(path, urlBase)
// b.Log(e[len(e)-1], len(e))
}
}

View File

@ -5,7 +5,7 @@ block nav
h1 Files
block content
:go:func Index(title, mainSite, currentPath string, stats *files.DirStats, items *[]files.DirEntry, r *http.Request)
:go:func Index(title, mainSite, currentPath string, stats *files.DirStat, items *[]files.DirEntry, r *http.Request)
:go:import "dwelling-files/pkg/files"
:go:import "dwelling-files/pkg/utils"
section