add proxy

This commit is contained in:
A.Unger
2021-03-04 13:56:49 +01:00
parent f7917bf760
commit e25f5b1c98
6 changed files with 42 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
package command
import (
"context"
"os"
"strings"
@@ -13,9 +14,7 @@ import (
)
// Execute is the entry point for the ocis-proxy command.
func Execute() error {
cfg := config.New()
func Execute(cfg *config.Config) error {
app := &cli.App{
Name: "ocis-proxy",
Version: version.String,
@@ -109,3 +108,31 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error {
return nil
}
// SutureService allows for the onlyoffice command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
ctx context.Context
cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service.
cfg *config.Config
}
// NewSutureService creates a new onlyoffice.SutureService
func NewSutureService(ctx context.Context, cfg *config.Config) SutureService {
sctx, cancel := context.WithCancel(ctx)
cfg.Context = sctx // propagate the context down to the go-micro services.
return SutureService{
ctx: sctx,
cancel: cancel,
cfg: cfg,
}
}
func (s SutureService) Serve() {
if err := Execute(s.cfg); err != nil {
return
}
}
func (s SutureService) Stop() {
s.cancel()
}

View File

@@ -45,7 +45,7 @@ func Server(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "server",
Usage: "Start integrated server",
Flags: flagset.ServerWithConfig(cfg),
Flags: append(flagset.ServerWithConfig(cfg), flagset.RootWithConfig(cfg)...),
Before: func(ctx *cli.Context) error {
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
@@ -176,8 +176,6 @@ func Server(cfg *config.Config) *cli.Command {
proxyHTTP.Context(ctx),
proxyHTTP.Config(cfg),
proxyHTTP.Metrics(metrics),
proxyHTTP.Flags(flagset.RootWithConfig(config.New())),
proxyHTTP.Flags(flagset.ServerWithConfig(config.New())),
proxyHTTP.Middlewares(loadMiddlewares(ctx, logger, cfg)),
)