File tree Expand file tree Collapse file tree 5 files changed +72
-0
lines changed Expand file tree Collapse file tree 5 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import (
18
18
19
19
type CLI struct {
20
20
ServiceCommands
21
+ Service2Commands
21
22
22
23
PG struct {
23
24
pgmanager.DatabaseCommands
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+
6
+ // Packages
7
+ server "github.com/mutablelogic/go-server"
8
+ "github.com/mutablelogic/go-server/pkg/parser"
9
+ provider "github.com/mutablelogic/go-server/pkg/provider"
10
+ )
11
+
12
+ ///////////////////////////////////////////////////////////////////////////////
13
+ // TYPES
14
+
15
+ type Service2Commands struct {
16
+ // Run ServiceRunCommand `cmd:"" group:"SERVICE" help:"Run the service"`
17
+ Run2 Service2RunCommand `cmd:"" group:"SERVICE" help:"Run the service with plugins"`
18
+ }
19
+
20
+ type Service2RunCommand struct {
21
+ Plugins []string `help:"Plugin paths" env:"PLUGIN_PATH"`
22
+ Args []string `arg:"" help:"Configuration files"`
23
+ }
24
+
25
+ ///////////////////////////////////////////////////////////////////////////////
26
+ // PUBLIC METHODS
27
+
28
+ func (cmd * Service2RunCommand ) Run (app server.Cmd ) error {
29
+ // Create a provider by loading the plugins
30
+ provider , err := provider .NewWithPlugins (cmd .Plugins ... )
31
+ if err != nil {
32
+ return err
33
+ }
34
+
35
+ // Create a parser of the config files
36
+ parser , err := parser .New (provider .Plugins ()... )
37
+ if err != nil {
38
+ return err
39
+ }
40
+
41
+ // Parse the configuration files
42
+ for _ , path := range cmd .Args {
43
+ if err := parser .Parse (path ); err != nil {
44
+ return err
45
+ }
46
+ }
47
+
48
+ fmt .Println (provider , parser )
49
+
50
+ return nil
51
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "httpserver" : {
3
+ "main" : {
4
+ "port" : 8080 ,
5
+ "host" : " localhost"
6
+ }
7
+ }
8
+ }
Original file line number Diff line number Diff line change @@ -141,6 +141,15 @@ func (provider *provider) WriteConfig(w io.Writer) error {
141
141
////////////////////////////////////////////////////////////////////////////////
142
142
// PUBLIC METHODS
143
143
144
+ // Return all the plugins
145
+ func (provider * provider ) Plugins () []server.Plugin {
146
+ var result []server.Plugin
147
+ for _ , meta := range provider .protos {
148
+ result = append (result , meta .New ())
149
+ }
150
+ return result
151
+ }
152
+
144
153
// Return a task from a label
145
154
func (provider * provider ) Task (ctx context.Context , label string ) server.Task {
146
155
provider .Debugf (ctx , "Called Task for %q" , label )
Original file line number Diff line number Diff line change @@ -43,6 +43,9 @@ type Provider interface {
43
43
// Write out the plugin configuration to a writer
44
44
WriteConfig (io.Writer ) error
45
45
46
+ // Return the plugins registered with the provider
47
+ Plugins () []Plugin
48
+
46
49
// Load a plugin by name and label, and provide a resolver function
47
50
Load (string , string , PluginResolverFunc ) error
48
51
You can’t perform that action at this time.
0 commit comments