Deploy Bots API #28
@@ -26,6 +26,8 @@ type RouterConfig struct {
|
|||||||
port int
|
port int
|
||||||
devClient *grpc.ClientConn
|
devClient *grpc.ClientConn
|
||||||
dataClient *grpc.ClientConn
|
dataClient *grpc.ClientConn
|
||||||
|
httpClient *http.Client
|
||||||
|
storageUrl string
|
||||||
context *cli.Context
|
context *cli.Context
|
||||||
shutdownTimeout time.Duration
|
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
|
// WithShutdownTimeout sets the graceful shutdown timeout
|
||||||
func WithShutdownTimeout(timeout time.Duration) Option {
|
func WithShutdownTimeout(timeout time.Duration) Option {
|
||||||
return func(cfg *RouterConfig) {
|
return func(cfg *RouterConfig) {
|
||||||
@@ -76,7 +92,7 @@ func setupRoutes(cfg *RouterConfig) (*gin.Engine, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Times handler
|
// Times handler
|
||||||
timesHandler, err := handlers.NewTimesHandler(HTTP_CLIENT, STORAGE_URL, handlerOptions...)
|
timesHandler, err := handlers.NewTimesHandler(cfg.httpClient, cfg.storageUrl, handlerOptions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package cmds
|
package cmds
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/public-api/pkg/api"
|
"git.itzana.me/strafesnet/public-api/pkg/api"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@@ -31,6 +33,12 @@ func NewApiCommand() *cli.Command {
|
|||||||
EnvVars: []string{"DATA_RPC_HOST"},
|
EnvVars: []string{"DATA_RPC_HOST"},
|
||||||
Value: "data-service:9000",
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Data service client
|
||||||
|
storage_url := ctx.String("storage-host")
|
||||||
|
|
||||||
return api.NewRouter(
|
return api.NewRouter(
|
||||||
api.WithContext(ctx),
|
api.WithContext(ctx),
|
||||||
api.WithPort(ctx.Int("port")),
|
api.WithPort(ctx.Int("port")),
|
||||||
api.WithDevClient(devConn),
|
api.WithDevClient(devConn),
|
||||||
api.WithDataClient(dataConn),
|
api.WithDataClient(dataConn),
|
||||||
|
api.WithHttpClient(&http.Client{}),
|
||||||
|
api.WithStorageUrl(storage_url),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user