Deploy Bots API #28

Merged
Quaternions merged 34 commits from staging into master 2026-02-28 02:33:43 +00:00
2 changed files with 30 additions and 1 deletions
Showing only changes of commit 33f55524a8 - Show all commits

View File

@@ -26,6 +26,8 @@ type RouterConfig struct {
port int
devClient *grpc.ClientConn
dataClient *grpc.ClientConn
httpClient *http.Client
storageUrl string
context *cli.Context
shutdownTimeout time.Duration
}
@@ -58,6 +60,20 @@ func WithDataClient(conn *grpc.ClientConn) Option {
}
}
// WithStorageUrl sets the storage url
func WithStorageUrl(storageUrl string) Option {
return func(cfg *RouterConfig) {
cfg.storageUrl = storageUrl
}
}
// WithStorageUrl sets the data gRPC client
func WithHttpClient(httpClient *http.Client) Option {
return func(cfg *RouterConfig) {
cfg.httpClient = httpClient
}
}
// WithShutdownTimeout sets the graceful shutdown timeout
func WithShutdownTimeout(timeout time.Duration) Option {
return func(cfg *RouterConfig) {
@@ -76,7 +92,7 @@ func setupRoutes(cfg *RouterConfig) (*gin.Engine, error) {
}
// Times handler
timesHandler, err := handlers.NewTimesHandler(HTTP_CLIENT, STORAGE_URL, handlerOptions...)
timesHandler, err := handlers.NewTimesHandler(cfg.httpClient, cfg.storageUrl, handlerOptions...)
if err != nil {
return nil, err
}

View File

@@ -1,6 +1,8 @@
package cmds
import (
"net/http"
"git.itzana.me/strafesnet/public-api/pkg/api"
"github.com/urfave/cli/v2"
"google.golang.org/grpc"
@@ -31,6 +33,12 @@ func NewApiCommand() *cli.Command {
EnvVars: []string{"DATA_RPC_HOST"},
Value: "data-service:9000",
},
&cli.StringFlag{
Name: "storage-host",
Usage: "Host of storage",
EnvVars: []string{"STORAGE_HOST"},
Value: "storage-service:9000",
},
},
}
}
@@ -48,10 +56,15 @@ func runAPI(ctx *cli.Context) error {
return err
}
// Data service client
storage_url := ctx.String("storage-host")
return api.NewRouter(
api.WithContext(ctx),
api.WithPort(ctx.Int("port")),
api.WithDevClient(devConn),
api.WithDataClient(dataConn),
api.WithHttpClient(&http.Client{}),
api.WithStorageUrl(storage_url),
)
}