diff options
| author | Shulhan <ms@kilabit.info> | 2025-07-25 02:30:37 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-07-29 00:31:23 +0700 |
| commit | 0537c5e094c7b6e5ff376ccdf0dba80adf5c4342 (patch) | |
| tree | b8c2c3621c1e76c5182acdc2f09291b796792a9e /worker.go | |
| parent | 3d4c7b48674cd553ce8f670933af9b609992ae77 (diff) | |
| download | lilin-0537c5e094c7b6e5ff376ccdf0dba80adf5c4342.tar.xz | |
all: refactoring Service to create with ServiceOptions
Instead of defining the options in the Service, create it in the
ServiceOptions and pass it to NewService function.
In this way, we can check it, initialize it, and set default value.
The Address option now use URL with scheme, so we can derive the
service type based on the scheme, for example "http://" for HTTP based
service, "tcp://xxx" for TCP based service, and so on.
Diffstat (limited to 'worker.go')
| -rw-r--r-- | worker.go | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -32,6 +32,10 @@ func newWorker(configDir string) (wrk *worker, err error) { return wrk, nil } +type serviceConfigs struct { + Options map[string]ServiceOptions `ini:"service"` +} + // loadServiceDir Load all the service configurations. func (wrk *worker) loadServiceDir(configDir string) (err error) { var serviceDir = filepath.Join(configDir, `service.d`) @@ -42,6 +46,7 @@ func (wrk *worker) loadServiceDir(configDir string) (err error) { return err } + var svcConfigs serviceConfigs var de os.DirEntry for _, de = range listde { if de.IsDir() { @@ -64,13 +69,19 @@ func (wrk *worker) loadServiceDir(configDir string) (err error) { return err } - err = ini.Unmarshal(rawcfg, wrk) + err = ini.Unmarshal(rawcfg, &svcConfigs) if err != nil { return err } } - for name, service := range wrk.Services { - service.Name = name + var svc *Service + for name, svcOpts := range svcConfigs.Options { + svcOpts.Name = name + svc, err = NewService(svcOpts) + if err != nil { + return err + } + wrk.Services[name] = svc } return nil } |
