add jwt middleware

This commit is contained in:
arnaucube
2019-06-15 10:12:21 +02:00
parent c38f7762f4
commit eec7019497
10 changed files with 178 additions and 58 deletions

View File

@@ -2,21 +2,21 @@ package models
import "gopkg.in/mgo.v2/bson"
/*
BuildingsList
MetalMine int64
CrystalMine int64
DeuteriumMine int64
EnergyMine int64
FusionReactor int64
RoboticsFactory int64
Shipyard int64
RessearchLab int64
*/
type Planet struct {
Id bson.ObjectId `json:"id" bson:"_id,omitempty"`
Size int64 // fields/slots
Name string
OwnerId bson.ObjectId
Buildings map[string]int64
/*
Buildings types (in the map, all in lowcase):
MetalMine int64
CrystalMine int64
DeuteriumMine int64
EnergyMine int64
FusionReactor int64
RoboticsFactory int64
Shipyard int64
RessearchLab int64
*/
}

View File

@@ -2,7 +2,6 @@ package models
import (
"errors"
"fmt"
"time"
"github.com/arnaucube/gogame/database"
@@ -107,8 +106,6 @@ func (u *User) GetResources() (*Resources, error) {
if err != nil {
return nil, err
}
// get u.LastUpdated
fmt.Println(u.LastUpdated)
// calculate Delta time = currentTime - u.LastUpdated
delta := time.Since(u.LastUpdated)
@@ -122,7 +119,6 @@ func (u *User) GetResources() (*Resources, error) {
// and calculate growth = ResourcePlant.Level for each planet
var metalGrowth, crystalGrowth, deuteriumGrowth, energyGrowth int64
for _, planet := range planets {
fmt.Println("planet", planet)
// TODO find correct formulas
metalGrowth = metalGrowth + ((1 + planet.Buildings["metalmine"]) * int64(delta))
crystalGrowth = crystalGrowth + ((1 + planet.Buildings["crystalmine"]) * int64(delta))

View File

@@ -1,12 +1,6 @@
package models
import (
"testing"
"github.com/arnaucube/gogame/database"
"github.com/stretchr/testify/assert"
)
/*
func TestCreateUser(t *testing.T) {
db, err := database.New("127.0.0.1:27017", "gogametests")
assert.Nil(t, err)
@@ -15,3 +9,4 @@ func TestCreateUser(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, user.Name, "user00")
}
*/