WIP: major/v2 #1

Draft
vlbeaudoin wants to merge 5 commits from major/v2 into main
11 changed files with 70 additions and 71 deletions
Showing only changes of commit 2dcf0ec867 - Show all commits

View file

@ -4,15 +4,16 @@ LABEL author="vlbeaudoin"
WORKDIR /go/src/app WORKDIR /go/src/app
COPY LICENSE cmd.go config.go db.go entity.go flag.go go.mod go.sum handler.go main.go server.go ./ COPY LICENSE cmd.go config.go db.go entity.go flag.go go.mod go.sum handler.go server.go ./
ADD cmd/ cmd/
ADD queries/ queries/ ADD queries/ queries/
ADD ui/ ui/ ADD ui/ ui/
RUN CGO_ENABLED=0 go build \ RUN CGO_ENABLED=0 go build \
-a \ -a \
-o presences \ -o presences \
./ ./cmd/presences/
# Alpine # Alpine

View file

@ -17,7 +17,7 @@ help: ## Show this help
.PHONY: go-install .PHONY: go-install
go-install: ## Use `go install` to build and link the executable go-install: ## Use `go install` to build and link the executable
go install -a go install -a ./cmd/presences/
.PHONY: docker-build .PHONY: docker-build
docker-build: ## Build container image docker-build: ## Build container image

50
cmd.go
View file

@ -1,11 +1,15 @@
package main package presences
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
"net/http"
"codeberg.org/vlbeaudoin/voki/v3"
"git.agecem.com/bottin/bottin/v11"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/spf13/cobra" "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
}
}

11
cmd/presences/main.go Normal file
View file

@ -0,0 +1,11 @@
package main
import (
"git.agecem.com/bottin/presences"
)
// Entry
func main() {
// Start commandline parsing then call `run`
presences.Execute()
}

View file

@ -1,4 +1,4 @@
package main package presences
import ( import (
"fmt" "fmt"

2
db.go
View file

@ -1,4 +1,4 @@
package main package presences
import ( import (
"context" "context"

View file

@ -1,4 +1,4 @@
package main package presences
import "time" import "time"

View file

@ -1,4 +1,4 @@
package main package presences
import ( import (
"github.com/spf13/pflag" "github.com/spf13/pflag"

View file

@ -1,4 +1,4 @@
package main package presences
import ( import (
"context" "context"

61
main.go
View file

@ -1,61 +0,0 @@
package main
import (
"context"
"fmt"
"net/http"
"codeberg.org/vlbeaudoin/voki/v3"
"git.agecem.com/bottin/bottin/v11"
"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
}
}

View file

@ -1,4 +1,4 @@
package main package presences
import ( import (
"context" "context"