psql first commit
This commit is contained in:
parent
c96b6ed943
commit
15ab461a5e
|
@ -0,0 +1,8 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
</module>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -6,6 +6,7 @@ require (
|
||||||
github.com/google/uuid v1.3.0
|
github.com/google/uuid v1.3.0
|
||||||
github.com/gorilla/csrf v1.7.1
|
github.com/gorilla/csrf v1.7.1
|
||||||
github.com/gorilla/mux v1.8.0
|
github.com/gorilla/mux v1.8.0
|
||||||
|
github.com/lib/pq v1.3.0
|
||||||
github.com/mitchellh/mapstructure v1.5.0
|
github.com/mitchellh/mapstructure v1.5.0
|
||||||
github.com/ory/fosite v0.42.2
|
github.com/ory/fosite v0.42.2
|
||||||
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0
|
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0
|
||||||
|
|
|
@ -707,6 +707,7 @@ github.com/lib/pq v0.0.0-20180327071824-d34b9ff171c2/go.mod h1:5WUZQaWbwv1U+lTRe
|
||||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||||
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||||
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||||
|
github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU=
|
||||||
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||||
github.com/luna-duclos/instrumentedsql v0.0.0-20181127104832-b7d587d28109/go.mod h1:PWUIzhtavmOR965zfawVsHXbEuU1G29BPZ/CB3C7jXk=
|
github.com/luna-duclos/instrumentedsql v0.0.0-20181127104832-b7d587d28109/go.mod h1:PWUIzhtavmOR965zfawVsHXbEuU1G29BPZ/CB3C7jXk=
|
||||||
github.com/luna-duclos/instrumentedsql v1.1.2/go.mod h1:4LGbEqDnopzNAiyxPPDXhLspyunZxgPTMJBKtC6U0BQ=
|
github.com/luna-duclos/instrumentedsql v1.1.2/go.mod h1:4LGbEqDnopzNAiyxPPDXhLspyunZxgPTMJBKtC6U0BQ=
|
||||||
|
@ -790,6 +791,9 @@ github.com/nicksnyder/go-i18n v1.10.0/go.mod h1:HrK7VCrbOvQoUAQ7Vpy7i87N7JZZZ7R2
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
||||||
|
github.com/oleiade/reflections v1.0.0/go.mod h1:RbATFBbKYkVdqmSFtx13Bb/tVhR0lgOBXunWTZKeL4w=
|
||||||
|
github.com/oleiade/reflections v1.0.1 h1:D1XO3LVEYroYskEsoSiGItp9RUxG6jWnCVvrqH0HHQM=
|
||||||
|
github.com/oleiade/reflections v1.0.1/go.mod h1:rdFxbxq4QXVZWj0F+e9jqjDkc7dbp97vkRixKo2JR60=
|
||||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
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("")
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewPostgresqlStorage(t *testing.T) {
|
||||||
|
cfg := viper.New()
|
||||||
|
cfg.Set("storage.db.psql.host", "localhost")
|
||||||
|
cfg.Set("storage.db.psql.port", "5432")
|
||||||
|
cfg.Set("storage.db.psql.user", "postgres")
|
||||||
|
cfg.Set("storage.db.psql.password", "postgres")
|
||||||
|
cfg.Set("storage.db.psql.dbname", "mobilityaccounts")
|
||||||
|
|
||||||
|
storage, err := NewPostgresqlStorage(cfg)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("error creating new PostgreSQL storage: %v", err)
|
||||||
|
}
|
||||||
|
defer storage.DbConnection.Close()
|
||||||
|
}
|
|
@ -46,6 +46,9 @@ func NewDBStorage(cfg *viper.Viper) (DBStorage, error) {
|
||||||
case "mongodb":
|
case "mongodb":
|
||||||
s, err := NewMongoDBStorage(cfg)
|
s, err := NewMongoDBStorage(cfg)
|
||||||
return s, err
|
return s, err
|
||||||
|
case "psql":
|
||||||
|
s, err := NewPostgresqlStorage(cfg)
|
||||||
|
return s, err
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("storage type %v is not supported", storage_type)
|
return nil, fmt.Errorf("storage type %v is not supported", storage_type)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue