This commit is contained in:
Nama Kamu
2026-09-15 14:47:26 +07:00
parent 27283e041b
commit 8bafff0c98
9 changed files with 108 additions and 13 deletions
+14
View File
@@ -0,0 +1,14 @@
package config
import (
"fmt"
"github.com/joho/godotenv"
)
func LoadEnv() error {
err := godotenv.Load()
if err != nil {
return fmt.Errorf("error loading .env file: %w", err)
}
return nil
}
+18
View File
@@ -0,0 +1,18 @@
package database
import (
"context"
"fmt"
"os"
"github.com/jackc/pgx/v5"
)
func Connect() (*pgx.Conn, error) {
conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
if err != nil {
return nil, fmt.Errorf("Unable to connect to database: %v", err)
}
return conn, nil
}
+14
View File
@@ -0,0 +1,14 @@
package models
import (
"time"
)
// Snippet merepresentasikan satu baris data dari database PostgreSQL
type Snippet struct {
ID int64 `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
}