Initial commit

This commit is contained in:
Victor Lacasse-Beaudoin 2025-02-27 14:13:21 -05:00
commit 02947128bc
24 changed files with 1126 additions and 0 deletions

61
main.go Normal file
View file

@ -0,0 +1,61 @@
package main
import (
"context"
"fmt"
"net/http"
"codeberg.org/vlbeaudoin/voki/v3"
"git.agecem.com/bottin/bottin/v10/pkg/bottin"
"github.com/jackc/pgx/v5/pgxpool"
)
// Entry
func main() {
// Start commandline parsing then call `run`
Execute()
}
func run(ctx context.Context, cfg Config) error {
select {
case <-ctx.Done():
return ctx.Err()
default:
bottinClient := bottin.APIClient{Caller: voki.New(
http.DefaultClient,
cfg.Bottin.Host,
cfg.Bottin.Key,
cfg.Bottin.Port,
func() string {
if cfg.Bottin.TLS.Enabled {
return "https"
} else {
return "http"
}
}(),
)}
// connect to db
dbPool, err := pgxpool.New(ctx,
fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s",
cfg.DB.Username,
cfg.DB.Password,
cfg.DB.Host,
cfg.DB.Port,
cfg.DB.Database,
cfg.DB.SSLMode,
))
if err != nil {
return err
}
defer dbPool.Close()
dbClient := DBClient{Pool: dbPool}
if err := RunUIServer(ctx, cfg, &bottinClient, &dbClient); err != nil && err != http.ErrServerClosed {
return err
}
return nil
}
}