diff --git a/objects/objects.go b/objects/objects.go new file mode 100644 index 0000000..8fb1325 --- /dev/null +++ b/objects/objects.go @@ -0,0 +1,11 @@ +// Copyright (c) 2024 mStar +// +// Licensed under the EUPL, Version 1.2 +// +// You may not use this work except in compliance with the Licence. +// You should have received a copy of the Licence along with this work. If not, see: +// . +// See the Licence for the specific language governing permissions and limitations under the Licence. +// + +package objects diff --git a/objects/person.go b/objects/person.go new file mode 100644 index 0000000..305af92 --- /dev/null +++ b/objects/person.go @@ -0,0 +1,14 @@ +// Copyright (c) 2024 mStar +// +// Licensed under the EUPL, Version 1.2 +// +// You may not use this work except in compliance with the Licence. +// You should have received a copy of the Licence along with this work. If not, see: +// . +// See the Licence for the specific language governing permissions and limitations under the Licence. +// + +package objects + +type Person struct { +} diff --git a/storage/db_types.go b/storage/db_types.go new file mode 100644 index 0000000..5091c6d --- /dev/null +++ b/storage/db_types.go @@ -0,0 +1,59 @@ +// Copyright (c) 2024 mStar +// +// Licensed under the EUPL, Version 1.2 +// +// You may not use this work except in compliance with the Licence. +// You should have received a copy of the Licence along with this work. If not, see: +// . +// See the Licence for the specific language governing permissions and limitations under the Licence. +// + +package storage + +import ( + "crypto/rsa" + "net/mail" + "net/url" + + "gorm.io/gorm" +) + +type personDB struct { + gorm.Model // Includes primary key (uid) as well as various time info + + // Public data + + uid string + name string + instance url.URL + local bool + publicKey string + + // Private data, set if local == true + + mail *mail.Address + pwHash *string + inbox url.URL + privateKey *rsa.PrivateKey + following []url.URL + followers []url.URL +} + +type noteDB struct { + gorm.Model // Includes primary key (uid) as well as various time info + + // Public data + + uid string + content string + creator url.URL + instance url.URL + local bool + tags []string + repliesTo *url.URL + deliverTo []url.URL + + // Private data + + // None yet +} diff --git a/storage/storage.go b/storage/storage.go new file mode 100644 index 0000000..0c6d783 --- /dev/null +++ b/storage/storage.go @@ -0,0 +1,28 @@ +// Copyright (c) 2024 mStar +// +// Licensed under the EUPL, Version 1.2 +// +// You may not use this work except in compliance with the Licence. +// You should have received a copy of the Licence along with this work. If not, see: +// . +// See the Licence for the specific language governing permissions and limitations under the Licence. +// + +package storage + +import ( + "fmt" + + "gitlab.com/beckersam/linstrom/config" + "gorm.io/driver/postgres" + "gorm.io/gorm" +) + +func NewDb(cfg *config.Config) (*gorm.DB, error) { + db, err := gorm.Open(postgres.Open(cfg.General.DbPath)) + if err != nil { + return nil, fmt.Errorf("Failed to connect to db %s: %w", cfg.General.DbPath, err) + } + db.AutoMigrate(&personDB{}, ¬eDB{}) + return db, nil +}