refactor: séparer executable et library
This commit is contained in:
parent
b3706080cd
commit
2dcf0ec867
11 changed files with 70 additions and 71 deletions
50
cmd.go
50
cmd.go
|
@ -1,11 +1,15 @@
|
|||
package main
|
||||
package presences
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"codeberg.org/vlbeaudoin/voki/v3"
|
||||
"git.agecem.com/bottin/bottin/v11"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -49,3 +53,47 @@ var rootCmd = &cobra.Command{
|
|||
}
|
||||
},
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue