mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-12-24 14:39:48 +00:00
Update config
This commit is contained in:
parent
2af37d4778
commit
4613e9cc7b
45
bloat.conf
45
bloat.conf
@ -1,9 +1,46 @@
|
||||
# Format:
|
||||
# - Lines starting with a '#' are ignored
|
||||
# - Key and Value are separated by a single '='
|
||||
# - Leading and trailing white spaces in Key and Value are ignored
|
||||
# - Quoting and multi-line values are not supported
|
||||
#
|
||||
# Changing values of client_name, client_scope or client_website will cause
|
||||
# previously generated access tokens to be invalid. Issue the
|
||||
# `rm database_path/*` command to clean the database afterwards.
|
||||
|
||||
# Address to listen to. Value can be of "HOSTNAME:PORT" or "IP:PORT" form. In
|
||||
# case of empty HOSTNAME or IP, "0.0.0.0:PORT" is used.
|
||||
# Example: ":8080", "127.0.0.1:8080", "mydomain:8080"
|
||||
listen_address=:8080
|
||||
|
||||
# Name of the client.
|
||||
client_name=web
|
||||
|
||||
# Mastodon scopes used by the client.
|
||||
# See https://docs.joinmastodon.org/api/oauth-scopes/
|
||||
client_scope=read write follow
|
||||
|
||||
# Full URL of the website. Users will be redirected to this URL after
|
||||
# authentication.
|
||||
# Example: "http://localhost:8080", "https://mydomain.com"
|
||||
client_website=http://localhost:8080
|
||||
static_directory=static
|
||||
templates_glob_pattern=templates/*
|
||||
#custom_css=custom.css
|
||||
#post_formats=PlainText:text/plain,HTML:text/html,Markdown:text/markdown,BBCode:text/bbcode
|
||||
|
||||
# Path of database directory. It's used to store session information.
|
||||
database_path=database
|
||||
|
||||
# Path of directory containing template files.
|
||||
templates_path=templates
|
||||
|
||||
# Path of directory containing static files (CSS and JS).
|
||||
static_directory=static
|
||||
|
||||
# Supported post formats. Value is a list of key:value pair separated by a ','.
|
||||
# Empty value will disable the format selection in frontend.
|
||||
post_formats=PlainText:text/plain,HTML:text/html,Markdown:text/markdown,BBCode:text/bbcode
|
||||
|
||||
# Log file. Will log to stdout if value is empty.
|
||||
log_file=
|
||||
|
||||
# Path to custom CSS. Value can be a file path relative to the static directory.
|
||||
# or a URL starting with either "http://" or "https://".
|
||||
# custom_css=custom.css
|
||||
|
@ -16,11 +16,11 @@ type config struct {
|
||||
ClientScope string
|
||||
ClientWebsite string
|
||||
StaticDirectory string
|
||||
TemplatesGlobPattern string
|
||||
TemplatesPath string
|
||||
DatabasePath string
|
||||
CustomCSS string
|
||||
PostFormats []model.PostFormat
|
||||
Logfile string
|
||||
LogFile string
|
||||
}
|
||||
|
||||
func (c *config) IsValid() bool {
|
||||
@ -29,35 +29,15 @@ func (c *config) IsValid() bool {
|
||||
len(c.ClientScope) < 1 ||
|
||||
len(c.ClientWebsite) < 1 ||
|
||||
len(c.StaticDirectory) < 1 ||
|
||||
len(c.TemplatesGlobPattern) < 1 ||
|
||||
len(c.TemplatesPath) < 1 ||
|
||||
len(c.DatabasePath) < 1 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func getDefaultConfig() *config {
|
||||
return &config{
|
||||
ListenAddress: ":8080",
|
||||
ClientName: "web",
|
||||
ClientScope: "read write follow",
|
||||
ClientWebsite: "http://localhost:8080",
|
||||
StaticDirectory: "static",
|
||||
TemplatesGlobPattern: "templates/*",
|
||||
DatabasePath: "database.db",
|
||||
CustomCSS: "",
|
||||
PostFormats: []model.PostFormat{
|
||||
model.PostFormat{"Plain Text", "text/plain"},
|
||||
model.PostFormat{"HTML", "text/html"},
|
||||
model.PostFormat{"Markdown", "text/markdown"},
|
||||
model.PostFormat{"BBCode", "text/bbcode"},
|
||||
},
|
||||
Logfile: "",
|
||||
}
|
||||
}
|
||||
|
||||
func Parse(r io.Reader) (c *config, err error) {
|
||||
c = getDefaultConfig()
|
||||
c = new(config)
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
@ -90,8 +70,8 @@ func Parse(r io.Reader) (c *config, err error) {
|
||||
c.ClientWebsite = val
|
||||
case "static_directory":
|
||||
c.StaticDirectory = val
|
||||
case "templates_glob_pattern":
|
||||
c.TemplatesGlobPattern = val
|
||||
case "templates_path":
|
||||
c.TemplatesPath = val
|
||||
case "database_path":
|
||||
c.DatabasePath = val
|
||||
case "custom_css":
|
||||
@ -115,8 +95,8 @@ func Parse(r io.Reader) (c *config, err error) {
|
||||
})
|
||||
}
|
||||
c.PostFormats = formats
|
||||
case "logfile":
|
||||
c.Logfile = val
|
||||
case "log_file":
|
||||
c.LogFile = val
|
||||
default:
|
||||
return nil, errors.New("invliad config key " + key)
|
||||
}
|
||||
|
20
main.go
20
main.go
@ -47,7 +47,8 @@ func main() {
|
||||
log.Fatal("invalid config")
|
||||
}
|
||||
|
||||
renderer, err := renderer.NewRenderer(config.TemplatesGlobPattern)
|
||||
templatesGlobPattern := filepath.Join(config.TemplatesPath, "*")
|
||||
renderer, err := renderer.NewRenderer(templatesGlobPattern)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -57,12 +58,14 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
sessionDB, err := kv.NewDatabse(filepath.Join(config.DatabasePath, "session"))
|
||||
sessionDBPath := filepath.Join(config.DatabasePath, "session")
|
||||
sessionDB, err := kv.NewDatabse(sessionDBPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
appDB, err := kv.NewDatabse(filepath.Join(config.DatabasePath, "app"))
|
||||
appDBPath := filepath.Join(config.DatabasePath, "app")
|
||||
appDB, err := kv.NewDatabse(appDBPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -77,10 +80,10 @@ func main() {
|
||||
}
|
||||
|
||||
var logger *log.Logger
|
||||
if len(config.Logfile) < 1 {
|
||||
if len(config.LogFile) < 1 {
|
||||
logger = log.New(os.Stdout, "", log.LstdFlags)
|
||||
} else {
|
||||
lf, err := os.Open(config.Logfile)
|
||||
lf, err := os.Open(config.LogFile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -88,13 +91,14 @@ func main() {
|
||||
logger = log.New(lf, "", log.LstdFlags)
|
||||
}
|
||||
|
||||
s := service.NewService(config.ClientName, config.ClientScope, config.ClientWebsite,
|
||||
customCSS, config.PostFormats, renderer, sessionRepo, appRepo)
|
||||
s := service.NewService(config.ClientName, config.ClientScope,
|
||||
config.ClientWebsite, customCSS, config.PostFormats, renderer,
|
||||
sessionRepo, appRepo)
|
||||
s = service.NewAuthService(sessionRepo, appRepo, s)
|
||||
s = service.NewLoggingService(logger, s)
|
||||
handler := service.NewHandler(s, config.StaticDirectory)
|
||||
|
||||
log.Println("listening on", config.ListenAddress)
|
||||
logger.Println("listening on", config.ListenAddress)
|
||||
err = http.ListenAndServe(config.ListenAddress, handler)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
Loading…
Reference in New Issue
Block a user