gosora/common/site.go
Azareal be47066770 General:
Added better pagination to /forum/{id}
Fixed the ordering of the elements in the pagesets.
Added hooks to the task system.
Reduced the amount of boilerplate for RunVhook and RunVhookNoReturn.
Added RunVhookNeedHook to allow plugin developers to add custom content types to the report system.
Added BulkGetMap to the DefaultPollStore.
Renamed the MultiServer config setting to ServerCount and made it an integer.
Don't cache topic lists for empty groups.
Don't load replies for topics without any.

Tempra Simple:
Added chart and submenu CSS.
Improved the input and select CSS.
Fixed the pageset CSS.
Fixed the poll input CSS.

Tempra Conflux:
Fixed the quick reply button CSS.
Hid the avatar in the quick reply area.
Added the poll CSS.
Fixed the pageset CSS.

Shadow:
Fixed the time range selector CSS.
Fixed the poll input CSS.
2018-02-15 13:15:27 +00:00

120 lines
3.1 KiB
Go

package common
import (
"errors"
"strings"
)
// Site holds the basic settings which should be tweaked when setting up a site, we might move them to the settings table at some point
var Site = &site{Name: "Magical Fairy Land", Language: "english"}
// DbConfig holds the database configuration
var DbConfig = dbConfig{Host: "localhost"}
// Config holds the more technical settings
var Config config
// Dev holds build flags and other things which should only be modified during developers or to gather additional test data
var Dev devConfig
type site struct {
ShortName string
Name string
Email string
URL string
Host string
Port string
EnableSsl bool
EnableEmails bool
HasProxy bool
Language string
}
type dbConfig struct {
// Production database
Host string
Username string
Password string
Dbname string
Port string
// Test database. Split this into a separate variable?
TestHost string
TestUsername string
TestPassword string
TestDbname string
TestPort string
}
type config struct {
SslPrivkey string
SslFullchain string
MaxRequestSize int
CacheTopicUser int
UserCacheCapacity int
TopicCacheCapacity int
SMTPServer string
SMTPUsername string
SMTPPassword string
SMTPPort string
//SMTPEnableTLS bool
DefaultRoute string
DefaultGroup int
ActivationGroup int
StaffCSS string // ? - Move this into the settings table? Might be better to implement this as Group CSS
DefaultForum int // The forum posts go in by default, this used to be covered by the Uncategorised Forum, but we want to replace it with a more robust solution. Make this a setting?
MinifyTemplates bool
ServerCount int
Noavatar string // ? - Move this into the settings table?
ItemsPerPage int // ? - Move this into the settings table?
}
type devConfig struct {
DebugMode bool
SuperDebug bool
TemplateDebug bool
Profiling bool
TestDB bool
}
func ProcessConfig() error {
Config.Noavatar = strings.Replace(Config.Noavatar, "{site_url}", Site.URL, -1)
Site.Host = Site.URL
if Site.Port != "80" && Site.Port != "443" {
Site.URL = strings.TrimSuffix(Site.URL, "/")
Site.URL = strings.TrimSuffix(Site.URL, "\\")
Site.URL = strings.TrimSuffix(Site.URL, ":")
Site.URL = Site.URL + ":" + Site.Port
}
// We need this in here rather than verifyConfig as switchToTestDB() currently overwrites the values it verifies
if DbConfig.TestDbname == DbConfig.Dbname {
return errors.New("Your test database can't have the same name as your production database")
}
if Dev.TestDB {
SwitchToTestDB()
}
return nil
}
func VerifyConfig() error {
if !Forums.Exists(Config.DefaultForum) {
return errors.New("Invalid default forum")
}
if Config.ServerCount < 1 {
return errors.New("You can't have less than one server")
}
return nil
}
func SwitchToTestDB() {
DbConfig.Host = DbConfig.TestHost
DbConfig.Username = DbConfig.TestUsername
DbConfig.Password = DbConfig.TestPassword
DbConfig.Dbname = DbConfig.TestDbname
DbConfig.Port = DbConfig.TestPort
}