Minor changes + fix go module path

This commit is contained in:
kayos@tcp.direct 2021-12-31 07:22:03 -08:00
parent 12c5d97265
commit 348583a492
6 changed files with 17 additions and 18 deletions

View File

@ -11,7 +11,7 @@ import (
) )
var ( var (
db *sqlx.DB dbo *sqlx.DB
postgres *pgsql.EmbeddedPostgres postgres *pgsql.EmbeddedPostgres
) )
@ -30,7 +30,7 @@ type User struct {
func getUser(username string) (u *User, err error) { func getUser(username string) (u *User, err error) {
u = new(User) u = new(User)
if err = db.Get(u, "SELECT * FROM accounts WHERE username=$1", username); err != nil { if err = dbo.Get(u, "SELECT * FROM accounts WHERE username=$1", username); err != nil {
return nil, err return nil, err
} }
return u, nil return u, nil
@ -39,7 +39,7 @@ func getUser(username string) (u *User, err error) {
// UserExists queries our database for a user using the given username and returns true if it exists, false if it does not. // UserExists queries our database for a user using the given username and returns true if it exists, false if it does not.
func UserExists(username string) bool { func UserExists(username string) bool {
u := new(User) u := new(User)
if err := db.Get(u, "SELECT id FROM accounts WHERE username=$1", username); err != nil { if err := dbo.Get(u, "SELECT id FROM accounts WHERE username=$1", username); err != nil {
return false return false
} }
return true return true
@ -48,7 +48,7 @@ func UserExists(username string) bool {
// EmailTaken queries our database for a user using the given email address and returns true if the email is taken, false if it is not. // EmailTaken queries our database for a user using the given email address and returns true if the email is taken, false if it is not.
func EmailTaken(email string) bool { func EmailTaken(email string) bool {
u := new(User) u := new(User)
if err := db.Get(u, "SELECT id FROM accounts WHERE email=$1", email); err == nil { if err := dbo.Get(u, "SELECT id FROM accounts WHERE email=$1", email); err == nil {
return true return true
} }
return false return false
@ -107,7 +107,7 @@ func RegisterNewUser(username, password, ipaddr string, gender int, admin bool)
} else { } else {
u.Admin = 0 u.Admin = 0
} }
_, err = db.NamedExec(`INSERT INTO accounts (username, password, creation, last_login, last_ip, ban, admin, gender) _, err = dbo.NamedExec(`INSERT INTO accounts (username, password, creation, last_login, last_ip, ban, admin, gender)
VALUES (:username, :password, :creation, :last_login, :last_ip, 0, :admin, :gender);`, u) VALUES (:username, :password, :creation, :last_login, :last_ip, 0, :admin, :gender);`, u)
return err return err
} }

View File

@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"time" "time"
"git.tcp.direct/tcp.direct/bitcask-mirror" "git.tcp.direct/Mirrors/bitcask-mirror"
) )
// AuthLog is for implementing an authentication log. // AuthLog is for implementing an authentication log.

View File

@ -65,7 +65,7 @@ func argParse() {
for _, arg := range os.Args { for _, arg := range os.Args {
if arg == "--install" { if arg == "--install" {
println("installing...") println("installing...")
install(db) install(dbo)
} }
if arg == "--regtest" { if arg == "--regtest" {
registerTest() registerTest()
@ -92,14 +92,13 @@ func StartDatabases() {
} }
defer postgres.Stop() defer postgres.Stop()
db, err = sqlx.Connect("postgres", dbo, err = sqlx.Connect("postgres",
"host=localhost port=5432 user=postgres password=postgres dbname=postgres sslmode=disable") "host=localhost port=5432 user=postgres password=postgres dbname=postgres sslmode=disable")
} else { } else {
connstr := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable", config.SQLHost, config.SQLPort, config.SQLUsername, config.SQLPassword) connstr := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable", config.SQLHost, config.SQLPort, config.SQLUsername, config.SQLPassword)
db, err = sqlx.Connect("postgres", connstr) dbo, err = sqlx.Connect("postgres", connstr)
} }
if err != nil { if err != nil {
log.Error().Caller().Err(err).Msg("postgres_fail") log.Error().Caller().Err(err).Msg("postgres_fail")
return return

2
go.mod
View File

@ -3,7 +3,7 @@ module mapyweb
go 1.17 go 1.17
require ( require (
git.tcp.direct/tcp.direct/bitcask-mirror v0.0.0-20210901071030-fc9e41007af9 git.tcp.direct/Mirrors/bitcask-mirror v0.0.0-20210901071030-fc9e41007af9
github.com/badoux/checkmail v1.2.1 github.com/badoux/checkmail v1.2.1
github.com/fergusstrange/embedded-postgres v1.10.0 github.com/fergusstrange/embedded-postgres v1.10.0
github.com/gorilla/csrf v1.7.1 github.com/gorilla/csrf v1.7.1

4
go.sum
View File

@ -37,8 +37,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
git.tcp.direct/tcp.direct/bitcask-mirror v0.0.0-20210901071030-fc9e41007af9 h1:Zn19tX8s2if2edBHqlbMoHFMTmpmOHSAgrQRlh8k/Wo= git.tcp.direct/Mirrors/bitcask-mirror v0.0.0-20210901071030-fc9e41007af9 h1:Zn19tX8s2if2edBHqlbMoHFMTmpmOHSAgrQRlh8k/Wo=
git.tcp.direct/tcp.direct/bitcask-mirror v0.0.0-20210901071030-fc9e41007af9/go.mod h1:YOj+SWTh6eVhZNkMEcVdWpXUHahl5eVjifOci4nzLjU= git.tcp.direct/Mirrors/bitcask-mirror v0.0.0-20210901071030-fc9e41007af9/go.mod h1:YOj+SWTh6eVhZNkMEcVdWpXUHahl5eVjifOci4nzLjU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc= github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc=

View File

@ -6,20 +6,20 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/savsgio/atreugo/v11" "github.com/savsgio/atreugo/v11"
config "mapyweb/config" "mapyweb/config"
) )
func main() { func main() {
webconf := atreugo.Config{ webconf := atreugo.Config{
Addr: fmt.Sprintf("%s:%s", config.HTTPBindAddr, config.HTTPBindPort), Addr: fmt.Sprintf("%s:%s", config.HTTPBindAddr, config.HTTPBindPort),
TLSEnable: true, TLSEnable: true,
CertKey: config.SSLKey, CertKey: config.SSLKeyFile,
CertFile: config.SSLCert, CertFile: config.SSLCertFile,
Name: "MapyWeb", Name: "MapyWeb",
Debug: config.Debug, Debug: config.Debug,
Compress: true, Compress: true,
MaxConnsPerIP: 10,
MaxRequestsPerConn: 4,
} }
server := atreugo.New(webconf) server := atreugo.New(webconf)