Skip to content

Commit 01dc804

Browse files
committed
refactor local development path, experiement with different logging
1 parent 924d5d0 commit 01dc804

29 files changed

+202
-267
lines changed

.env

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# API
2+
PORT=8080
3+
TOKEN_KEY=
4+
#DEV_MODE=true
5+
6+
# DB
7+
#DB_DISABLED=true
8+
DB_HOST=db
9+
DB_PORT=5432
10+
DB_USER=postgres
11+
DB_PASSWORD=
12+
DB_DATABASE=skillbased
13+
DB_DEFAULT=postgres
14+
15+
# FRONTEND
16+
AUTH0_SECRET=
17+
AUTH0_BASE_URL=
18+
AUTH0_ISSUER_BASE_URL=
19+
AUTH0_CLIENT_ID=
20+
AUTH0_CLIENT_SECRET=
21+
AUTH0_AUDIENCE=
22+
AUTH0_SCOPE=
23+
24+
SKILLBASED_API_HOST=http://localhost:8080
25+
SKILLBASED_API_VERSION=v1
26+
SKILLBASED_API=$SKILLBASED_API_HOST/$SKILLBASED_API_VERSION
27+
28+
# NGINX
29+
HOSTNAME=

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33

44
[skillbased](http://skillbased.xyz) is a service that is aimed to provide players of casual, "pick-up" type sports to quickly and easily create balanced teams for their activity, and save those teams to create elevated levels of competition.
55

6-
Deploy locally with: `docker-compose -f docker-compose.yml up --build`
6+
## Development
7+
8+
Rename the `.env` file to `.env.local`. The default values should allow the API and postgres to start, however to
9+
enable Auth0 on the frontend, you'll need to supply your own credentials to their corresponding environment variables
10+
11+
Build and run the API, frontend, and a postgres database locally with: `docker-compose -f docker-compose.local.yml up --build`
712

813
## Tech
914
### Stack

api/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ TOKEN_KEY=
55

66
# DB
77
#DB_DISABLED=true
8-
DB_HOST=
8+
DB_HOST=test
99
DB_PORT=
1010
DB_USER=
1111
DB_PASSWORD=

api/go.mod

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,32 @@ module github.com/adamdevigili/skillbased/api
33
go 1.17
44

55
require (
6-
github.com/auth0/go-jwt-middleware v1.0.1-0.20210719135851-6401fcf7191b
76
github.com/badoux/checkmail v1.2.1
87
github.com/dgrijalva/jwt-go v3.2.0+incompatible
9-
github.com/golang-jwt/jwt v3.2.2+incompatible
108
github.com/google/uuid v1.3.0
119
github.com/jinzhu/gorm v1.9.16
1210
github.com/joho/godotenv v1.4.0
1311
github.com/kelseyhightower/envconfig v1.4.0
1412
github.com/labstack/echo/v4 v4.6.1
1513
github.com/labstack/gommon v0.3.0
1614
github.com/lib/pq v1.10.3
17-
github.com/rs/xid v1.3.0
18-
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
1915
github.com/pioz/faker v1.7.2
16+
github.com/segmentio/ksuid v1.0.4
17+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
2018
)
2119

2220
require (
21+
github.com/davecgh/go-spew v1.1.1 // indirect
22+
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
2323
github.com/jinzhu/inflection v1.0.0 // indirect
2424
github.com/mattn/go-colorable v0.1.8 // indirect
2525
github.com/mattn/go-isatty v0.0.14 // indirect
26+
github.com/stretchr/testify v1.7.0 // indirect
2627
github.com/valyala/bytebufferpool v1.0.0 // indirect
2728
github.com/valyala/fasttemplate v1.2.1 // indirect
2829
golang.org/x/net v0.0.0-20210913180222-943fd674d43e // indirect
2930
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0 // indirect
3031
golang.org/x/text v0.3.7 // indirect
3132
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
33+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
3234
)

api/go.sum

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
22
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
3-
github.com/auth0/go-jwt-middleware v1.0.1-0.20210719135851-6401fcf7191b/go.mod h1:Tlhz43qRKMMQ4WAii9sfAuW8sPuAgQCB4yIjPgT8AH0=
43
github.com/badoux/checkmail v1.2.1 h1:TzwYx5pnsV6anJweMx2auXdekBwGr/yt1GgalIx9nBQ=
54
github.com/badoux/checkmail v1.2.1/go.mod h1:XroCOBU5zzZJcLvgwU15I+2xXyCdTWXyR9MGfRhBYy0=
6-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
75
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
7+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
88
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM=
99
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
1010
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
@@ -13,12 +13,10 @@ github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DP
1313
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
1414
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
1515
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
16-
github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
1716
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
1817
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
1918
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
2019
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
21-
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
2220
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
2321
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
2422
github.com/jinzhu/gorm v1.9.16 h1:+IyIjPEABKRpsu/F8OvDPy9fyQlgsg2luMV2ZIH5i5o=
@@ -50,15 +48,14 @@ github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/
5048
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
5149
github.com/pioz/faker v1.7.2 h1:fterUcYCbMJ4TgFN8DSqhlwkgbSn9DfsQM1cadbPPw0=
5250
github.com/pioz/faker v1.7.2/go.mod h1:xSpay5w/oz1a6+ww0M3vfpe40pSIykeUPeWEc3TvVlc=
53-
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
5451
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5552
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
56-
github.com/rs/xid v1.3.0 h1:6NjYksEUlhurdVehpc7S7dk6DAmcKv8V9gG0FsVN2U4=
57-
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
53+
github.com/segmentio/ksuid v1.0.4 h1:sBo2BdShXjmcugAMwjugoGUdUV0pcxY5mW4xKRn3v4c=
54+
github.com/segmentio/ksuid v1.0.4/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O73XgrPE=
5855
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
59-
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
6056
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
6157
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
58+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
6259
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
6360
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
6461
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
@@ -68,7 +65,6 @@ github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+
6865
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
6966
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
7067
golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
71-
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
7268
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
7369
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
7470
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
@@ -101,9 +97,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
10197
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
10298
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
10399
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
104-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
105100
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
106-
gopkg.in/square/go-jose.v2 v2.5.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
107-
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
108101
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
109102
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
103+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
104+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

api/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313

1414
type Config struct {
1515
Port int `default:"8080"`
16-
TokenKey string `default:"false"`
17-
DevMode bool `default:"false"`
16+
TokenKey string `envconfig:"TOKEN_KEY"`
17+
DevMode bool `envconfig:"DEV_MODE" default:"false"`
1818
}
1919

2020
func main() {
@@ -36,6 +36,11 @@ func main() {
3636
log.Fatal(err.Error())
3737
}
3838

39+
if config.DevMode {
40+
log.Info("starting server in development mode")
41+
dbConfig.DevMode = config.DevMode
42+
}
43+
3944
// Initialize DB and routes
4045
server.InitRoutes(e, db.InitDB(dbConfig))
4146

api/pkg/core/balancer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func calcPlayerPowerScoreForSport(player models.Player, sport models.Sport) floa
7070
var powerScore float32
7171

7272
for skill, weight := range sport.SkillWeights {
73-
powerScore += float32(player.Skills[sport.ID.String()][skill]) * weight
73+
powerScore += float32(player.Skills[sport.ID][skill]) * weight
7474
}
7575

7676
return powerScore

api/pkg/db/init.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func InitDB(dbConfig Config) *gorm.DB {
3939
dbConfig.Password,
4040
)
4141

42-
log.Info(dbConfig)
42+
log.Info(fmt.Sprintf("%+v", dbConfig))
4343

4444
// If we're using a development Postgres, disable TLS
4545
if dbConfig.DevMode {
@@ -100,6 +100,11 @@ func initPlayersTable(db *gorm.DB) {
100100
}
101101
}
102102

103+
func deleteAllSeedPlayers(db *gorm.DB) {
104+
log.Info("deleteing all seed players from existing DB")
105+
db.Where("is_seed = ?", "t").Delete(&models.Player{})
106+
}
107+
103108
func initSportsTable(db *gorm.DB) {
104109
log.Info("Populating sports database with initial values..")
105110

api/pkg/db/player.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"github.com/adamdevigili/skillbased/api/pkg/models"
77
"github.com/jinzhu/gorm"
8-
"github.com/labstack/gommon/log"
98
)
109

1110
func InsertPlayer(db *gorm.DB, player *models.Player) error {
@@ -48,8 +47,3 @@ func DeletePlayer(db *gorm.DB, id string) error {
4847
return nil
4948
}
5049
}
51-
52-
func deleteAllSeedPlayers(db *gorm.DB) {
53-
log.Info("deleteing all seed players from existing DB")
54-
db.Where("is_seed = ?", "t").Delete(&models.Player{})
55-
}

api/pkg/db/seed.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,44 @@ import (
55

66
"github.com/adamdevigili/skillbased/api/pkg/models"
77
"github.com/pioz/faker"
8-
"github.com/rs/xid"
8+
"github.com/segmentio/ksuid"
99
)
1010

1111
var (
1212
ultimateFrisbee = models.Sport{
1313
Base: models.Base{
1414
Name: "Ultimate Frisbee",
15-
ID: xid.New(),
15+
ID: ksuid.New().String(),
1616
},
1717
SkillWeights: models.SkillWeightMap{
1818
"handling": 0.9,
1919
"speed": 0.8,
2020
"stamina": 0.8,
2121
"height": 0.4,
2222
},
23+
MaxPlayersPerTeam: 15,
24+
MaxActivePlayersPerTeam: 7,
2325
}
2426

2527
football = models.Sport{
2628
Base: models.Base{
2729
Name: "Football",
28-
ID: xid.New(),
30+
ID: ksuid.New().String(),
2931
},
3032
SkillWeights: models.SkillWeightMap{
3133
"strength": 0.7,
3234
"speed": 0.8,
3335
"stamina": 0.8,
3436
"agility": 0.5,
3537
},
38+
MaxPlayersPerTeam: 50,
39+
MaxActivePlayersPerTeam: 11,
3640
}
3741

3842
basketball = models.Sport{
3943
Base: models.Base{
4044
Name: "Basketball",
41-
ID: xid.New(),
45+
ID: ksuid.New().String(),
4246
},
4347
SkillWeights: models.SkillWeightMap{
4448
"shooting": 0.9,
@@ -47,6 +51,8 @@ var (
4751
"height": 0.8,
4852
"passing": 0.5,
4953
},
54+
MaxPlayersPerTeam: 12,
55+
MaxActivePlayersPerTeam: 5,
5056
}
5157

5258
initialSports = []models.Sport{
@@ -69,7 +75,7 @@ func generateSeedPlayers() []*models.Player {
6975
LastName: ln,
7076
Base: models.Base{
7177
Name: fmt.Sprintf("%s %s", fn, ln),
72-
ID: xid.New(),
78+
ID: ksuid.New().String(),
7379
},
7480
PowerScores: make(map[string]int),
7581
IsSeed: true,

0 commit comments

Comments
 (0)