add thumbnails

This commit is contained in:
A.Unger
2021-03-04 14:08:44 +01:00
parent 3c770dd118
commit 96521d23a9
5 changed files with 50 additions and 18 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-thumbnails command.
func Execute() error {
cfg := config.New()
func Execute(cfg *config.Config) error {
app := &cli.App{
Name: "ocis-thumbnails",
Version: version.String,
@@ -108,3 +107,31 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error {
return nil
}
// SutureService allows for the thumbnails 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 thumbnails.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

@@ -1,5 +1,7 @@
package config
import "context"
// Log defines the available logging configuration.
type Log struct {
Level string
@@ -40,6 +42,8 @@ type Config struct {
Server Server
Tracing Tracing
Thumbnail Thumbnail
Context context.Context
}
// FileSystemStorage defines the available filesystem storage configuration.

View File

@@ -13,23 +13,20 @@ func RootWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "log-level",
Value: "info",
Usage: "Set logging level",
EnvVars: []string{"THUMBNAILS_LOG_LEVEL"},
EnvVars: []string{"THUMBNAILS_LOG_LEVEL", "OCIS_LOG_LEVEL"},
Destination: &cfg.Log.Level,
},
&cli.BoolFlag{
Name: "log-pretty",
Value: true,
Usage: "Enable pretty logging",
EnvVars: []string{"THUMBNAILS_LOG_PRETTY"},
EnvVars: []string{"THUMBNAILS_LOG_PRETTY", "OCIS_LOG_PRETTY"},
Destination: &cfg.Log.Pretty,
},
&cli.BoolFlag{
Name: "log-color",
Value: true,
Usage: "Enable colored logging",
EnvVars: []string{"THUMBNAILS_LOG_COLOR"},
EnvVars: []string{"THUMBNAILS_LOG_COLOR", "OCIS_LOG_COLOR"},
Destination: &cfg.Log.Color,
},
}