broke out user and tranx into seperate files

This commit is contained in:
Derek McQuay 2016-08-22 15:17:13 -07:00
parent 4f7b61cb86
commit cb1f5f0464
2 changed files with 62 additions and 0 deletions

7
tranx.go Normal file
View File

@ -0,0 +1,7 @@
package chipmunk
type tranx struct {
Cost float32 `json:"cost"`
Store string `json:"store"`
Info string `json:"Info"`
}

55
user.go Normal file
View File

@ -0,0 +1,55 @@
package chipmunk
import "fmt"
var authEmails []string = []string{"derekmcquay@gmail.com", "colleenmmcquay@gmail.com", "dmmllnl@gmail.com"}
type user struct {
Info userInfo `json:"info"`
admin bool `json:"admin"`
txs []tranx `json:"Txs"`
}
type userInfo struct {
Sub string `json:"sub"`
Name string `json:"name"`
GivenName string `json:"given_name"`
FamilyName string `json:"family_name"`
Profile string `json:"profile"`
Picture string `json:"picture"`
Email string `json:"email"`
EmailVerified bool `json:"email_verified"`
}
func (u *user) addTranx(t tranx) {
u.txs = append(u.txs, t)
}
func authorizedEmail(e string) bool {
b := false
for _, i := range authEmails {
if i == e {
b = true
}
}
return b
}
func getUser(e string) (*user, error) {
for _, i := range users {
if e == i.Info.Email {
return &i, nil
}
}
return &user{}, fmt.Errorf("could not find user")
}
func addUser(u userInfo) {
users = append(
users,
user{
Info: u,
admin: true,
},
)
}