2024-12-23 20:57:58 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"codeberg.org/vlbeaudoin/voki/v3"
|
|
|
|
"git.agecem.com/bottin/bottin/v10/pkg/bottin"
|
2024-12-30 15:00:42 -05:00
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
2024-12-23 20:57:58 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// Entry
|
|
|
|
func main() {
|
2024-12-30 17:30:37 -05:00
|
|
|
// Start commandline parsing then call `run`
|
|
|
|
Execute()
|
2024-12-23 20:57:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2024-12-30 17:30:37 -05:00
|
|
|
func() string {
|
|
|
|
if cfg.Bottin.TLS.Enabled {
|
|
|
|
return "https"
|
|
|
|
} else {
|
|
|
|
return "http"
|
|
|
|
}
|
|
|
|
}(),
|
2024-12-23 20:57:58 -05:00
|
|
|
)}
|
|
|
|
|
2024-12-30 15:00:42 -05:00
|
|
|
// connect to db
|
|
|
|
dbPool, err := pgxpool.New(ctx, "postgres://agendas:agendas@localhost:5432/agendas")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer dbPool.Close()
|
|
|
|
|
|
|
|
dbClient := DBClient{Pool: dbPool}
|
|
|
|
|
|
|
|
if err := RunServer(ctx, cfg, &bottinClient, &dbClient); err != nil && err != http.ErrServerClosed {
|
2024-12-23 20:57:58 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|