Minor changes + fix go module path
This commit is contained in:
parent
12c5d97265
commit
348583a492
10
db/auth.go
10
db/auth.go
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
db *sqlx.DB
|
||||
dbo *sqlx.DB
|
||||
postgres *pgsql.EmbeddedPostgres
|
||||
)
|
||||
|
||||
|
@ -30,7 +30,7 @@ type User struct {
|
|||
|
||||
func getUser(username string) (u *User, err error) {
|
||||
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 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.
|
||||
func UserExists(username string) bool {
|
||||
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 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.
|
||||
func EmailTaken(email string) bool {
|
||||
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 false
|
||||
|
@ -107,7 +107,7 @@ func RegisterNewUser(username, password, ipaddr string, gender int, admin bool)
|
|||
} else {
|
||||
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)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"git.tcp.direct/tcp.direct/bitcask-mirror"
|
||||
"git.tcp.direct/Mirrors/bitcask-mirror"
|
||||
)
|
||||
|
||||
// AuthLog is for implementing an authentication log.
|
||||
|
|
|
@ -65,7 +65,7 @@ func argParse() {
|
|||
for _, arg := range os.Args {
|
||||
if arg == "--install" {
|
||||
println("installing...")
|
||||
install(db)
|
||||
install(dbo)
|
||||
}
|
||||
if arg == "--regtest" {
|
||||
registerTest()
|
||||
|
@ -92,14 +92,13 @@ func StartDatabases() {
|
|||
}
|
||||
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")
|
||||
} else {
|
||||
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 {
|
||||
log.Error().Caller().Err(err).Msg("postgres_fail")
|
||||
return
|
||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module mapyweb
|
|||
go 1.17
|
||||
|
||||
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/fergusstrange/embedded-postgres v1.10.0
|
||||
github.com/gorilla/csrf v1.7.1
|
||||
|
|
4
go.sum
4
go.sum
|
@ -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.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=
|
||||
git.tcp.direct/tcp.direct/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 h1:Zn19tX8s2if2edBHqlbMoHFMTmpmOHSAgrQRlh8k/Wo=
|
||||
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/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc=
|
||||
|
|
|
@ -6,20 +6,20 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
"github.com/savsgio/atreugo/v11"
|
||||
|
||||
config "mapyweb/config"
|
||||
"mapyweb/config"
|
||||
)
|
||||
|
||||
func main() {
|
||||
webconf := atreugo.Config{
|
||||
Addr: fmt.Sprintf("%s:%s", config.HTTPBindAddr, config.HTTPBindPort),
|
||||
TLSEnable: true,
|
||||
CertKey: config.SSLKey,
|
||||
CertFile: config.SSLCert,
|
||||
CertKey: config.SSLKeyFile,
|
||||
CertFile: config.SSLCertFile,
|
||||
Name: "MapyWeb",
|
||||
Debug: config.Debug,
|
||||
Compress: true,
|
||||
|
||||
|
||||
MaxConnsPerIP: 10,
|
||||
MaxRequestsPerConn: 4,
|
||||
}
|
||||
|
||||
server := atreugo.New(webconf)
|
||||
|
|
Loading…
Reference in New Issue