agendas/main.go

66 lines
1 KiB
Go

package main
import (
"context"
"fmt"
"log"
"net/http"
"codeberg.org/vlbeaudoin/voki/v3"
"git.agecem.com/bottin/bottin/v10/pkg/bottin"
"golang.org/x/term"
)
// Entry
func init() {}
func main() {
cfg := Config{}
cfg.Bottin.Host = "api.bottin.agecem.com"
cfg.Bottin.Port = 443
cfg.Bottin.TLS.Enabled = true
ctx := context.TODO()
fmt.Println("bottin password (no echo): ")
password, err := term.ReadPassword(0)
if err != nil {
log.Fatal(err)
}
cfg.Bottin.Key = string(password)
if err := run(ctx, cfg); err != nil {
log.Fatal(err)
}
}
func run(ctx context.Context, cfg Config) error {
select {
case <-ctx.Done():
return ctx.Err()
default:
var protocol string
if cfg.Bottin.TLS.Enabled {
protocol = "https"
} else {
protocol = "http"
}
bottinClient := bottin.APIClient{Caller: voki.New(
http.DefaultClient,
cfg.Bottin.Host,
cfg.Bottin.Key,
cfg.Bottin.Port,
protocol,
)}
if err := RunServer(ctx, &bottinClient); err != nil && err != http.ErrServerClosed {
return err
}
return nil
}
}