Skip to content

Commit

Permalink
Move to env config
Browse files Browse the repository at this point in the history
  • Loading branch information
lil5 committed May 30, 2024
1 parent b9d0829 commit 9579bbc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang:latest

RUN apt install git

WORKDIR /app

ADD . .
RUN go build -o tigerbeetle_api .

ENTRYPOINT ./tigerbeetle_api
2 changes: 1 addition & 1 deletion config-example.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
port: 50051

tb_cluster_id: 0
tb_addresses: ["3033"]
tb_addresses: "3033"
tb_concurrency_max: 2
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
- 127.0.0.1:3033:3033
environment:
- TB_ADDRESSES=0.0.0.0:3033
command: start /data/0_0.tigerbeetle
command: start --addresses=0.0.0.0:3033 /data/0_0.tigerbeetle

volumes:
tigerbeetle:
17 changes: 9 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
)

type Config struct {
Port int `default:"50051" yml:"port" env:"PORT"`
Host string `default:"0.0.0.0" yml:"host" env:"HOST"`
TbClusterId int `default:"0" yml:"tb_cluster_id" env:"TB_CLUSTER_ID"`
TbAddresses []string `required:"true" yml:"tb_addresses" env:"TB_ADDRESSES"`
TbConcurrencyMax int `default:"2" yml:"tb_concurrency_max" env:"TB_CONCURRENCY_MAX"`
Port int `default:"50051" yaml:"port" env:"PORT"`
Host string `default:"0.0.0.0" yaml:"host" env:"HOST"`
TbClusterId int `default:"0" yaml:"tb_cluster_id" env:"TB_CLUSTER_ID"`
TbAddresses string `required:"true" yaml:"tb_addresses" env:"TB_ADDRESSES"`
TbConcurrencyMax int `default:"2" yaml:"tb_concurrency_max" env:"TB_CONCURRENCY_MAX"`
}

func main() {
Expand All @@ -38,15 +38,16 @@ func main() {
slog.Error("fatal error config file:", err)
os.Exit(1)
}
if len(config.TbAddresses) == 0 {
if config.TbAddresses == "" {
slog.Error("tb_addresses is empty")
os.Exit(1)
}
tbAddresses := strings.Split(config.TbAddresses, ",")

slog.Info("Connecting to tigerbeetle cluster", "addresses:", strings.Join(config.TbAddresses, ", "))
slog.Info("Connecting to tigerbeetle cluster", "addresses:", strings.Join(tbAddresses, ", "))

// Connect to tigerbeetle
tb, err := tigerbeetle_go.NewClient(types.ToUint128(uint64(config.TbClusterId)), config.TbAddresses, uint(config.TbConcurrencyMax))
tb, err := tigerbeetle_go.NewClient(types.ToUint128(uint64(config.TbClusterId)), tbAddresses, uint(config.TbConcurrencyMax))
if err != nil {
slog.Error("unable to connect to tigerbeetle:", err)
os.Exit(1)
Expand Down

0 comments on commit 9579bbc

Please sign in to comment.