64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package storage
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
_ "github.com/lib/pq"
|
|
"github.com/spf13/viper"
|
|
"strconv"
|
|
)
|
|
|
|
type PostgresqlStorage struct {
|
|
DbConnection *sql.DB
|
|
}
|
|
|
|
func NewPostgresqlStorage(cfg *viper.Viper) (PostgresqlStorage, error) {
|
|
var (
|
|
host = cfg.GetString("storage.db.psql.host")
|
|
port = cfg.GetString("storage.db.psql.port")
|
|
user = cfg.GetString("storage.db.psql.user")
|
|
password = cfg.GetString("storage.db.psql.password")
|
|
dbname = cfg.GetString("storage.db.psql.dbname")
|
|
)
|
|
portInt, _ := strconv.Atoi(port)
|
|
psqlconn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, portInt,
|
|
user, password, dbname)
|
|
db, err := sql.Open("postgres", psqlconn)
|
|
if err != nil {
|
|
fmt.Println("error", err)
|
|
return PostgresqlStorage{}, fmt.Errorf("connection to postgresql failed")
|
|
}
|
|
defer db.Close()
|
|
err = db.Ping()
|
|
if err != nil {
|
|
return PostgresqlStorage{}, fmt.Errorf("connection to postgresql database failed")
|
|
}
|
|
return PostgresqlStorage{
|
|
DbConnection: db,
|
|
}, nil
|
|
}
|
|
|
|
func (PostgresqlStorage) GetAccount(id string) (*Account, error) {
|
|
return nil, fmt.Errorf("")
|
|
}
|
|
|
|
func (PostgresqlStorage) LocalAuthentication(namespace string, username string, email string, phone_number string) (*Account, error) {
|
|
return nil, fmt.Errorf("")
|
|
}
|
|
|
|
func (PostgresqlStorage) GetAccounts(namespaces []string) ([]Account, error) {
|
|
return nil, fmt.Errorf("")
|
|
}
|
|
|
|
func (PostgresqlStorage) GetAccountsByIds(accountids []string) ([]Account, error) {
|
|
return nil, fmt.Errorf("")
|
|
}
|
|
|
|
func (PostgresqlStorage) CreateAccount(account Account) error {
|
|
return fmt.Errorf("")
|
|
}
|
|
|
|
func (PostgresqlStorage) UpdateAccount(account Account) error {
|
|
return fmt.Errorf("")
|
|
}
|