add conf.DirlistEnable and modify readme

This commit is contained in:
Hedy Li 2021-07-20 15:22:39 +08:00
parent 33b0be1065
commit 6c71b360ac
Signed by: hedy
GPG Key ID: B51B5A8D1B176372
3 changed files with 20 additions and 9 deletions

View File

@ -1,5 +1,13 @@
# spsrv
WIP!
A static spartan server with many features:
* folder redirects
* /~user directories
* directory listing
* CONF or TOML config file
* directory listing options
* user directory feature and userdir path
## todo
- [x] /folder to /folder/ redirects
@ -9,7 +17,9 @@ WIP!
- [x] refactor working dir part
- [x] config
- [ ] status meta
- [ ] user homedir
- [x] user homedir
- [x] hostname, port
- [x] public dir
- [ ] dirlist title
- [ ] userdir slug
- [ ] /echo /guestbook (configurable)

View File

@ -8,12 +8,12 @@ import (
)
type Config struct {
Port int
Hostname string
RootDir string
UserDirEnable bool
UserDir string
// UserSlug string
Port int
Hostname string
RootDir string
UserDirEnable bool
UserDir string
DirlistEnable bool
DirlistReverse bool
DirlistSort string
DirlistTitles bool
@ -23,6 +23,7 @@ var defaultConf = &Config{
Port: 300,
Hostname: "localhost",
RootDir: "/var/spartan/",
DirlistEnable: true,
DirlistReverse: false,
DirlistSort: "name",
DirlistTitles: true,

View File

@ -151,7 +151,7 @@ func serveFile(conn io.ReadWriteCloser, reqPath, path string, conf *Config) {
// not putting the /folder to /folder/ redirect here because folder can still
// be opened without errors
// Directory listing
if strings.HasSuffix(path, "index.gmi") {
if conf.DirlistEnable && strings.HasSuffix(path, "index.gmi") {
// fullPath := filepath.Join(fmt.Sprint(rootDir), path)
fullPath := path
if _, err := os.Stat(fullPath); os.IsNotExist(err) {