boringproxy/auth.go
Anders Pitman 45f609b8ba Move executable into separate package
Enables us to move towards being able to import as a library.
2020-12-07 21:41:45 -07:00

34 lines
496 B
Go

package boringproxy
import (
"sync"
)
type Auth struct {
db *Database
pendingRequests map[string]*LoginRequest
mutex *sync.Mutex
}
type LoginRequest struct {
Email string
}
func NewAuth(db *Database) *Auth {
pendingRequests := make(map[string]*LoginRequest)
mutex := &sync.Mutex{}
return &Auth{db, pendingRequests, mutex}
}
func (a *Auth) Authorized(token string) bool {
_, exists := a.db.GetTokenData(token)
if exists {
return true
}
return false
}