Documentation
¶
Index ¶
- Constants
- Variables
- func CheckPassword(password string, hashedPassword string) error
- func HashPassword(password string) (string, error)
- func IsSupportedCurrency(currency string) bool
- func RandomClusterID() string
- func RandomClusterName() string
- func RandomCurrency() string
- func RandomEmail() string
- func RandomInt(min, max int64) int64
- func RandomMoney() int64
- func RandomOwner() string
- func RandomString(n int) string
- type Config
- type Token
- type TokenMaker
Constants ¶
const ( USD = "USD" EUR = "EUR" CAD = "CAD" )
Constants for all supported currencies
Variables ¶
var ( ErrInvalidToken = fmt.Errorf("token is invalid") ErrExpiredToken = fmt.Errorf("token has expired") )
Different types of error returned by the VerifyToken function
Functions ¶
func CheckPassword ¶
CheckPassword checks if the provided password is correct or not
func HashPassword ¶
HashPassword returns the bcrypt hash of the password.
func IsSupportedCurrency ¶
IsSupportedCurrency returns true if the currency is supported
func RandomClusterID ¶
func RandomClusterID() string
func RandomString ¶
RandomString generates a random string of length n
Types ¶
type Config ¶
type Config struct { DBDriver string `mapstructure:"DB_DRIVER"` DBSource string `mapstructure:"DB_SOURCE"` ServerAddress string `mapstructure:"SERVER_ADDRESS"` TokenSymmetricKey string `mapstructure:"TOKEN_SYMMETRIC_KEY"` AccessTokenDuration time.Duration `mapstructure:"ACCESS_TOKEN_DURATION"` }
Config stores all configuration of the application. The values are read by viper from a config file or environment variable.
func LoadConfig ¶
LoadConfig reads configuration from file or environment variables.
type Token ¶
type Token struct { ID uuid.UUID `json:"id"` Username string `json:"username"` IssuedAt time.Time `json:"issued_at"` ExpiredAt time.Time `json:"expired_at"` }
Token contains the payload data of the token
type TokenMaker ¶
type TokenMaker struct {
// contains filtered or unexported fields
}
TokenMaker manages token creation and validation
func NewTokenMaker ¶
func NewTokenMaker(symmetricKey string) (*TokenMaker, error)
NewTokenMaker returns a new TokenMaker
func (*TokenMaker) CreateToken ¶
CreateToken creates a new token for a username with a fixed valid duration
func (*TokenMaker) VerifyToken ¶
func (tokenMaker *TokenMaker) VerifyToken(tokenString string) (*Token, error)
VerifyToken checks if the token is valid or not