initial commit; working state

This commit is contained in:
Vikas
2024-06-02 10:33:54 +05:30
commit a124c1b0be
24 changed files with 1082 additions and 0 deletions

31
db/models.go Normal file
View File

@@ -0,0 +1,31 @@
package db
import (
"time"
)
type Paste struct {
ID string `json:"id"`
Text string `json:"-"`
EncryptedBytes []byte `json:"-"`
Key string `json:"-"`
CreatedAt time.Time `json:"createdAt"`
ExpiresAt time.Time `json:"expiresAt"`
}
func NewEncryptedPaste(text string, expiresAt time.Time) (*Paste, error) {
key := randomKey()
encryptedText, err := encrypt(text, key)
if err != nil {
return nil, err
}
return &Paste{
ID: randomKey(),
Text: text,
EncryptedBytes: encryptedText,
Key: key,
CreatedAt: time.Now(),
ExpiresAt: expiresAt,
}, nil
}