otpsvc

package module
v0.0.0-...-c923453 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2020 License: MIT Imports: 11 Imported by: 2

README

OTP Service

codecov Go Report Card Go Reference

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entity

type Entity struct {
	UUID        string
	PhoneNumber string
	PinCode     string
	ExpiresAt   time.Time
}

type ErrInvalidPinCode

type ErrInvalidPinCode struct {
	UUID    string
	PinCode string
}

func (ErrInvalidPinCode) Error

func (err ErrInvalidPinCode) Error() string

type ErrOTPNotFoundOrExpired

type ErrOTPNotFoundOrExpired struct {
	UUID string
}

func (ErrOTPNotFoundOrExpired) Error

func (err ErrOTPNotFoundOrExpired) Error() string

type Middleware

type Middleware func(Service) Service

type Option

type Option func(*service)

func WithExpiresIn

func WithExpiresIn(sec int) Option

func WithGoogleAutomaticSMSVerificationTemplate

func WithGoogleAutomaticSMSVerificationTemplate() Option

func WithMessageTemplate

func WithMessageTemplate(tpl *template.Template) Option

func WithPinCodeLength

func WithPinCodeLength(l int) Option

type Repository

type Repository interface {
	Create(ctx context.Context, entity Entity) (err error)
	Find(ctx context.Context, otpUUID string) (res *Entity, err error)
}

type SendOTPOption

type SendOTPOption func(data map[string]interface{})

func WithGoogleAutomaticSMSVerification

func WithGoogleAutomaticSMSVerification(hash string) SendOTPOption

type SendOTPRequest

type SendOTPRequest struct {
	PhoneNumber string
}

type SendOTPResponse

type SendOTPResponse struct {
	OTPUUID string
}

type Service

type Service interface {
	SendOTP(ctx context.Context, req SendOTPRequest, options ...SendOTPOption) (res *SendOTPResponse, err error)
	VerifyOTP(ctx context.Context, req VerifyOTPRequest) (res *VerifyOTPResponse, err error)
}

func New

func New(repo Repository, smsSvc smssvc.Service, options ...Option) Service

type VerifyOTPRequest

type VerifyOTPRequest struct {
	OTPUUID string
	PinCode string
}

type VerifyOTPResponse

type VerifyOTPResponse struct {
	PhoneNumber string
}

Jump to

Keyboard shortcuts

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