Files
ocis/services/proxy/pkg/command/root.go
T

59 lines
1.3 KiB
Go
Raw Normal View History

package command
import (
2021-03-04 13:56:49 +01:00
"context"
"os"
2022-05-04 14:49:59 +02:00
"github.com/owncloud/ocis/v2/ocis-pkg/clihelper"
ociscfg "github.com/owncloud/ocis/v2/ocis-pkg/config"
2022-06-20 16:49:06 +02:00
"github.com/owncloud/ocis/v2/services/proxy/pkg/config"
2021-03-11 15:50:01 +01:00
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)
2022-01-03 13:53:27 +01:00
// GetCommands provides all commands for this service
func GetCommands(cfg *config.Config) cli.Commands {
return []*cli.Command{
// start this service
Server(cfg),
// interaction with this service
// infos about this service
Health(cfg),
Version(cfg),
}
}
// Execute is the entry point for the ocis-proxy command.
2021-03-04 13:56:49 +01:00
func Execute(cfg *config.Config) error {
2022-01-03 13:53:27 +01:00
app := clihelper.DefaultApp(&cli.App{
Name: "proxy",
Usage: "proxy for oCIS",
2022-01-03 13:53:27 +01:00
Commands: GetCommands(cfg),
})
return app.Run(os.Args)
}
2021-03-04 14:03:06 +01:00
// SutureService allows for the proxy command to be embedded and supervised by a suture supervisor tree.
2021-03-04 13:56:49 +01:00
type SutureService struct {
2021-03-11 15:50:01 +01:00
cfg *config.Config
2021-03-04 13:56:49 +01:00
}
2021-03-04 14:03:06 +01:00
// NewSutureService creates a new proxy.SutureService
2021-03-11 15:50:01 +01:00
func NewSutureService(cfg *ociscfg.Config) suture.Service {
cfg.Proxy.Commons = cfg.Commons
2021-03-04 13:56:49 +01:00
return SutureService{
2021-03-11 15:50:01 +01:00
cfg: cfg.Proxy,
2021-03-04 13:56:49 +01:00
}
}
2021-03-11 15:50:01 +01:00
func (s SutureService) Serve(ctx context.Context) error {
s.cfg.Context = ctx
2021-03-04 13:56:49 +01:00
if err := Execute(s.cfg); err != nil {
2021-03-11 15:50:01 +01:00
return err
2021-03-04 13:56:49 +01:00
}
2021-03-11 15:50:01 +01:00
return nil
2021-03-04 13:56:49 +01:00
}