Add db to server

This commit is contained in:
Mustafa Gezen 2024-12-25 09:49:40 +01:00
parent c161e9f83e
commit e2749b36e5

View file

@ -2,10 +2,13 @@ package main
import (
"flag"
"fmt"
"github.com/rocky-linux/peridot/v2/base"
"github.com/jmoiron/sqlx"
"github.com/rocky-linux/peridot/v2/config"
"github.com/rocky-linux/peridot/v2/server"
_ "github.com/lib/pq"
)
var configPath = flag.String("config", "/etc/peridot/server.conf", "Path to the config file")
@ -19,8 +22,32 @@ func main() {
panic(err)
}
opts := []server.GRPCServerOption{server.WithPort(c.Server.Port)}
// If TLS is enabled, load the certs
if c.Server.TLS.Enabled {
opts = append(opts, server.WithTLS(c.Server.TLS.Certificate, c.Server.TLS.Key))
}
// Connect to db
db, err := sqlx.Connect(
"postgres",
fmt.Sprintf(
"host=%s port=%d user=%s password=%s dbname=%s sslmode=%s",
c.Server.Database.Host,
c.Server.Database.Port,
c.Server.Database.User,
c.Server.Database.Password,
c.Server.Database.Name,
c.Server.Database.SSLMode,
),
)
if err != nil {
panic(err)
}
// Start the server
s, err := server.NewServer(c, base.WithPort(c.Server.Port))
s, err := server.NewServer(c, server.FromSqlx(db), opts...)
if err != nil {
panic(err)
}