mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-09-14 03:25:52 -05:00
database: Use specialized db connection struct
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
"wwfc/database"
|
||||
"wwfc/gpcm"
|
||||
"wwfc/logging"
|
||||
|
||||
@@ -102,7 +101,7 @@ func handleBanImpl(r *http.Request) (bool, string, int) {
|
||||
|
||||
logging.Notice("API:"+moderator, "Ban profile:", aurora.Cyan(req.ProfileID), "TOS:", aurora.Cyan(req.Tos), "Length:", aurora.Cyan(length), "Reason:", aurora.BrightCyan(req.Reason), "Reason (Hidden):", aurora.BrightCyan(req.ReasonHidden))
|
||||
|
||||
if !database.BanUser(pool, ctx, req.ProfileID, req.Tos, length, req.Reason, req.ReasonHidden, moderator) {
|
||||
if !db.BanUser(req.ProfileID, req.Tos, length, req.Reason, req.ReasonHidden, moderator) {
|
||||
return false, "Failed to ban user", http.StatusInternalServerError
|
||||
}
|
||||
|
||||
|
||||
20
api/main.go
20
api/main.go
@@ -1,16 +1,13 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"wwfc/common"
|
||||
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"wwfc/database"
|
||||
)
|
||||
|
||||
var (
|
||||
ctx = context.Background()
|
||||
pool *pgxpool.Pool
|
||||
db database.Connection
|
||||
|
||||
apiSecret string
|
||||
)
|
||||
|
||||
@@ -21,16 +18,7 @@ func StartServer(reload bool) {
|
||||
apiSecret = config.APISecret
|
||||
|
||||
// Start SQL
|
||||
dbString := fmt.Sprintf("postgres://%s:%s@%s/%s", config.Username, config.Password, config.DatabaseAddress, config.DatabaseName)
|
||||
dbConf, err := pgxpool.ParseConfig(dbString)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
pool, err = pgxpool.ConnectConfig(ctx, dbConf)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
db = database.Start(config)
|
||||
}
|
||||
|
||||
func Shutdown() {
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"wwfc/database"
|
||||
)
|
||||
|
||||
func HandleUnban(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -72,7 +71,7 @@ func handleUnbanImpl(r *http.Request) (bool, string, int) {
|
||||
return false, "pid missing or 0 in request", http.StatusBadRequest
|
||||
}
|
||||
|
||||
if !database.UnbanUser(pool, ctx, req.ProfileID) {
|
||||
if !db.UnbanUser(req.ProfileID) {
|
||||
return false, "Failed to unban user", http.StatusInternalServerError
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user