postgres

package
v0.0.0-...-82728be Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateToken

func GenerateToken(user_id int, timestamp string) (string, error)

Types

type CreateSessionCall

type CreateSessionCall struct {
	UserID int
}

type CreateSessionResponse

type CreateSessionResponse struct {
	Token string
	Error error
}

type ExtendSessionCall

type ExtendSessionCall struct {
	Token string
}

type ExtendSessionResponse

type ExtendSessionResponse struct {
	Error error
}

type GetSessionCall

type GetSessionCall struct {
	Token string
}

type GetSessionResponse

type GetSessionResponse struct {
	Session data.Session
	Error   error
}

type GetUserCall

type GetUserCall struct {
	Username string
	Password string
}

type GetUserResponse

type GetUserResponse struct {
	User  data.User
	Error error
}

type MockPostgres

type MockPostgres struct {
	GetUserCalls            []GetUserCall
	GetUserResponse         GetUserResponse
	UpdateLastLoginCalls    []UpdateLastLoginCall
	UpdateLastLoginResponse UpdateLastLoginResponse
	CreateSessionCalls      []CreateSessionCall
	CreateSessionResponse   CreateSessionResponse
	GetSessionCalls         []GetSessionCall
	GetSessionResponse      GetSessionResponse
	ExtendSessionCalls      []ExtendSessionCall
	ExtendSessionResponse   ExtendSessionResponse
}

func InitMock

func InitMock() MockPostgres

func (*MockPostgres) CreateSession

func (m *MockPostgres) CreateSession(user_id int) (string, error)

func (*MockPostgres) ExtendSession

func (m *MockPostgres) ExtendSession(token string) error

func (*MockPostgres) GetSession

func (m *MockPostgres) GetSession(token string) (data.Session, error)

func (*MockPostgres) GetUser

func (m *MockPostgres) GetUser(username string, password string) (data.User, error)

func (*MockPostgres) SetCreateSessionResponse

func (m *MockPostgres) SetCreateSessionResponse(response CreateSessionResponse)

func (*MockPostgres) SetExtendSessionResponse

func (m *MockPostgres) SetExtendSessionResponse(response ExtendSessionResponse)

func (*MockPostgres) SetGetSessionResponse

func (m *MockPostgres) SetGetSessionResponse(response GetSessionResponse)

func (*MockPostgres) SetGetUserResponse

func (m *MockPostgres) SetGetUserResponse(response GetUserResponse)

func (*MockPostgres) SetUpdateLastLoginResponse

func (m *MockPostgres) SetUpdateLastLoginResponse(
	response UpdateLastLoginResponse,
)

func (*MockPostgres) UpdateLastLogin

func (m *MockPostgres) UpdateLastLogin(username string) error

type Postgres

type Postgres struct {
	Clock      clock.Clock
	Connection *sql.DB
	Logger     *slog.Logger
}

func ConfigInit

func ConfigInit(config config.Postgres, clock clock.Clock, logger *slog.Logger) Postgres

func Init

func Init(host string, port int, username string, password string, dbname string, logger *slog.Logger, clock clock.Clock) Postgres

func (*Postgres) CreateSession

func (p *Postgres) CreateSession(user_id int) (string, error)

func (*Postgres) ExtendSession

func (p *Postgres) ExtendSession(token string) error

func (*Postgres) GetSession

func (p *Postgres) GetSession(token string) (data.Session, error)

func (*Postgres) GetUser

func (p *Postgres) GetUser(username string, password string) (data.User, error)

func (*Postgres) UpdateLastLogin

func (p *Postgres) UpdateLastLogin(username string) error

type Postgreser

type Postgreser interface {
	GetUser(username string, password string) (data.User, error)
	UpdateLastLogin(username string) error
	CreateSession(user_id int) (string, error)
	GetSession(token string) (data.Session, error)
	ExtendSession(token string) error
}

type UpdateLastLoginCall

type UpdateLastLoginCall struct {
	Username string
}

type UpdateLastLoginResponse

type UpdateLastLoginResponse struct {
	Error error
}

Jump to

Keyboard shortcuts

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