dispatch/storage/directory.go

70 lines
1.5 KiB
Go
Raw Normal View History

2016-01-04 18:26:32 +00:00
package storage
import (
"path/filepath"
2020-04-20 01:02:15 +00:00
homedir "github.com/mitchellh/go-homedir"
2016-01-04 18:26:32 +00:00
)
func DefaultDirectory() string {
home, _ := homedir.Dir()
return filepath.Join(home, ".dispatch")
}
2020-04-20 01:02:15 +00:00
type directory struct {
dataRoot string
configRoot string
}
func (d directory) DataRoot() string {
return d.dataRoot
}
2016-01-04 18:26:32 +00:00
2020-04-20 01:02:15 +00:00
func (d directory) ConfigRoot() string {
return d.configRoot
2016-01-04 18:26:32 +00:00
}
func (d directory) LetsEncrypt() string {
2020-04-20 01:02:15 +00:00
return filepath.Join(d.ConfigRoot(), "letsencrypt")
2016-01-04 18:26:32 +00:00
}
func (d directory) Users() string {
2020-04-20 01:02:15 +00:00
return filepath.Join(d.DataRoot(), "users")
2016-01-04 18:26:32 +00:00
}
func (d directory) User(username string) string {
return filepath.Join(d.Users(), username)
2016-01-04 18:26:32 +00:00
}
func (d directory) Log(username string) string {
return filepath.Join(d.User(username), "log")
2016-01-11 20:04:57 +00:00
}
func (d directory) Index(username string) string {
return filepath.Join(d.User(username), "index")
2016-01-11 20:04:57 +00:00
}
func (d directory) Certificate(username string) string {
return filepath.Join(d.User(username), "cert.pem")
2016-01-11 20:04:57 +00:00
}
func (d directory) Key(username string) string {
return filepath.Join(d.User(username), "key.pem")
2016-01-11 20:04:57 +00:00
}
2020-05-17 00:14:35 +00:00
func (d directory) Downloads(username string) string {
return filepath.Join(d.User(username), "downloads")
}
2020-05-17 01:55:46 +00:00
func (d directory) DownloadedFile(username string, file string) string {
return filepath.Join(d.Downloads(username), file)
}
2016-01-04 18:26:32 +00:00
func (d directory) Config() string {
2020-04-20 01:02:15 +00:00
return filepath.Join(d.ConfigRoot(), "config.toml")
2016-01-04 18:26:32 +00:00
}
func (d directory) Database() string {
2020-04-20 01:02:15 +00:00
return filepath.Join(d.DataRoot(), "dispatch.db")
2016-01-04 18:26:32 +00:00
}