91f70d2a4a
Added basic support for server sync. Re-added a few missing defers. Renamed TO-DO to TODO across the entire codebase. Renamed StaticForumStore to MemoryForumStore. The ForumStore is now built on a sync.Map with a view slice for generating /forums rather than a slice. Renamed many more functions and variables to satisfy the linter. increase_post_user_stats() and decrease_post_user_stats() are now methods on the User struct. We also fix a bug where they take the moderator's score rather than the target user's into account when recalculating their level after a post / topic is deleted. Transitioned the topic list to CSS Grid for Tempra Simple, with a float fallback. Cosmo and Cosmo Conflux are now hidden from the theme list. Fixed more data races. Added more debug data to the template compiler logs.
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
/*
|
|
*
|
|
* Gosora PostgreSQL Interface
|
|
* Under heavy development
|
|
* Copyright Azareal 2017 - 2018
|
|
*
|
|
*/
|
|
package main
|
|
|
|
import "fmt"
|
|
import "strings"
|
|
import "database/sql"
|
|
import _ "github.com/go-sql-driver/mysql"
|
|
|
|
// We don't need SSL to run an installer... Do we?
|
|
var dbSslmode = "disable"
|
|
|
|
func _setPgsqlAdapter() {
|
|
dbPort = "5432"
|
|
initDatabase = _initPgsql
|
|
}
|
|
|
|
func _initPgsql() (err error) {
|
|
_dbPassword := dbPassword
|
|
if _dbPassword != "" {
|
|
_dbPassword = " password=" + _pgEscapeBit(_dbPassword)
|
|
}
|
|
db, err = sql.Open("postgres", "host='"+_pgEscapeBit(dbHost)+"' port='"+_pgEscapeBit(dbPort)+"' user='"+_pgEscapeBit(dbUsername)+"' dbname='"+_pgEscapeBit(dbName)+"'"+_dbPassword+" sslmode='"+dbSslmode+"'")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Println("Successfully connected to the database")
|
|
|
|
// TODO: Create the database, if it doesn't exist
|
|
|
|
return nil
|
|
}
|
|
|
|
func _pgEscapeBit(bit string) string {
|
|
// TODO: Write a custom parser, so that backslashes work properly in the sql.Open string. Do something similar for the database driver, if possible?
|
|
return strings.Replace(bit, "'", "\\'", -1)
|
|
}
|