utils

package
v0.0.0-...-9eb7758 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bcrypt

type Bcrypt struct {
}

func NewBcrypt

func NewBcrypt() *Bcrypt

func (*Bcrypt) ComparePassword

func (b *Bcrypt) ComparePassword(hashedPassword, password string) error

func (*Bcrypt) HashPassword

func (b *Bcrypt) HashPassword(password string) (string, error)

type Code

type Code struct {
}

func NewCode

func NewCode() *Code

func (*Code) GenerateCsrfToken

func (c *Code) GenerateCsrfToken() string

func (*Code) GenerateDigitCode

func (c *Code) GenerateDigitCode(digit int) string

func (*Code) GenerateStateOauth

func (c *Code) GenerateStateOauth() (state string, expiration int64)

type CookieStore

type CookieStore struct {
	AccessTokenCookieName  string
	RefreshTokenCookieName string
	CsrfTokenCookieName    string
	OauthStateCookieName   string
	DefaultExpiration      time.Time
}

func NewCookieStore

func NewCookieStore() *CookieStore

func (*CookieStore) DestroyCookie

func (c *CookieStore) DestroyCookie(wr http.ResponseWriter, cookieName string)

func (*CookieStore) GetCookieDecrypted

func (c *CookieStore) GetCookieDecrypted(req *http.Request, cookieName string) (string, error)

func (*CookieStore) SetCookieAccessToken

func (c *CookieStore) SetCookieAccessToken(wr http.ResponseWriter, accessToken string)

func (*CookieStore) SetCookieCsrfToken

func (c *CookieStore) SetCookieCsrfToken(wr http.ResponseWriter, csrfToken string)

func (*CookieStore) SetCookieOAuth2State

func (c *CookieStore) SetCookieOAuth2State(wr http.ResponseWriter, state string)

func (*CookieStore) SetCookieRefreshToken

func (c *CookieStore) SetCookieRefreshToken(wr http.ResponseWriter, refreshToken string)

type Email

type Email struct {
	From        string   // Sender
	To          []string // Recipients
	Cc          []string // Copy to other recipients
	Subject     string   // Email subject
	Body        string   // HTML body template
	Queue       []Email  // Queue of emails to be sent
	Attachments []string // File attachments
}

func NewEmail

func NewEmail() *Email

func (*Email) Add

func (e *Email) Add(email Email) (err error)

func (*Email) Send

func (e *Email) Send() (err error)

func (*Email) Stop

func (e *Email) Stop()

func (*Email) Worker

func (e *Email) Worker()

type IBcrypt

type IBcrypt interface {
	HashPassword(password string) (string, error)
	ComparePassword(hashedPassword, password string) error
}

type ICode

type ICode interface {
	GenerateDigitCode(digit int) string
	GenerateStateOauth() (state string, expiration time.Time)
	GenerateCsrfToken() string
}

type ICookieStore

type ICookieStore interface {
	SetCookieAccessToken(wr http.ResponseWriter, accessToken string)
	SetCookieRefreshToken(wr http.ResponseWriter, refreshToken string)
	SetCookieCsrfToken(wr http.ResponseWriter, csrfToken string)
	SetCookieOAuth2State(wr http.ResponseWriter, state string)
	GetCookieDecrypted(req *http.Request, cookieName string) (string, error)
	DestroyCookie(wr http.ResponseWriter, cookieName string)
}

type IEmail

type IEmail interface {
	Add(email Email) (err error)
	Send() (err error)
	Worker()
	Stop()
}

type IJwt

type IJwt interface {
	GenerateToken(subject interface{}) (token string, err error)
	ValidateToken(token string) (subject interface{}, err error)
}

type Jwt

type Jwt struct {
	Secret                          string
	ExpirationTimeAccess            time.Duration
	ExpirationTimeRefresh           time.Duration
	ExpirationTimeResetPassword     time.Duration
	ExpirationTimeEmailVerification time.Duration
}

func NewJwt

func NewJwt(secret string, expirationAccess string, expirationRefresh string,
	expirationResetPassword string, expirationEmailVerification string) *Jwt

func (*Jwt) GenerateToken

func (j *Jwt) GenerateToken(userId string, expiration time.Duration) (token string, err error)

func (*Jwt) ValidateToken

func (j *Jwt) ValidateToken(token string) (userId string, err error)

type Oauth

type Oauth struct {
	Providers []OauthProvider
}

func NewOauth

func NewOauth() *Oauth

func (*Oauth) GetProvider

func (o *Oauth) GetProvider(provider string) (OauthProvider, error)

func (*Oauth) GetUserInformation

func (o *Oauth) GetUserInformation(provider string, userInformation map[string]interface{}) (OauthUserInformation, error)

type OauthProvider

type OauthProvider struct {
	Provider string
	Config   OauthProviderConfig
}

type OauthProviderConfig

type OauthProviderConfig struct {
	ClientId     string
	ClientSecret string
	RedirectUrl  string
	Scopes       []string
	AuthUrl      string
	TokenUrl     string
	UserInfoUrl  string
}

type OauthUserInformation

type OauthUserInformation struct {
	Id     string
	Name   string
	Email  string
	Avatar string
}

type ValidateError

type ValidateError struct {
	FailedField string
	Tag         string
	Value       string
}

func Validate

func Validate(i interface{}) (errors []*ValidateError)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL