mirror of
https://github.com/tenrok/event-scheduling.git
synced 2026-05-15 11:59:41 +03:00
feat: initial commit
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
DB_DSN=postgres://username:password@localhost/scheduling?sslmode=disable
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
.env
|
||||||
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"go.inferGopath": false
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
_ "github.com/lib/pq"
|
||||||
|
)
|
||||||
|
|
||||||
|
func initDBConnection() *sql.DB {
|
||||||
|
connStr := os.Getenv("DB_DSN")
|
||||||
|
db, err := sql.Open("postgres", connStr)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("couldn't connect to database", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return db
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
module github.com/dipeshdulal/event-scheduling
|
||||||
|
|
||||||
|
go 1.15
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/joho/godotenv v1.3.0
|
||||||
|
github.com/lib/pq v1.9.0
|
||||||
|
)
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||||
|
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||||
|
github.com/lib/pq v1.9.0 h1:L8nSXQQzAYByakOFMTwpjRoHsMJklur4Gi59b6VivR8=
|
||||||
|
github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Test structure
|
||||||
|
type Test struct {
|
||||||
|
ID uint
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
interrupt := make(chan os.Signal, 1)
|
||||||
|
|
||||||
|
if err := godotenv.Load(); err != nil {
|
||||||
|
log.Fatal("Error loading .env file ", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
db := initDBConnection()
|
||||||
|
|
||||||
|
rows, err := db.Query("SELECT id, name FROM public.test")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for rows.Next() {
|
||||||
|
var test Test
|
||||||
|
rows.Scan(&test.ID, &test.Name)
|
||||||
|
log.Printf("test: %v\n", test)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
signal.Notify(interrupt, os.Interrupt)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for range interrupt {
|
||||||
|
log.Print("Interrupt received closing...")
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
<-ctx.Done()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user