Browse Source

instance manager: create instance with API(fix)

Shelikhoo 4 years ago
parent
commit
c7c4effbd2
2 changed files with 18 additions and 0 deletions
  1. 16 0
      app/instman/instman.go
  2. 2 0
      main/distro/all/all.go

+ 16 - 0
app/instman/instman.go

@@ -3,6 +3,7 @@ package instman
 import (
 	"context"
 	core "github.com/v2fly/v2ray-core/v4"
+	"github.com/v2fly/v2ray-core/v4/common"
 	"github.com/v2fly/v2ray-core/v4/features/extension"
 )
 
@@ -66,3 +67,18 @@ func (i InstanceMgr) UntrackInstance(ctx context.Context, name string) error {
 	delete(i.instances, name)
 	return nil
 }
+
+func NewInstanceMgr(ctx context.Context, config *Config) (extension.InstanceManagement, error) {
+	return InstanceMgr{instances: map[string]*core.Instance{}}, nil
+}
+
+func init() {
+	common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
+		var f extension.InstanceManagement
+		var err error
+		if f, err = NewInstanceMgr(ctx, config.(*Config)); err != nil {
+			return nil, err
+		}
+		return f, nil
+	}))
+}

+ 2 - 0
main/distro/all/all.go

@@ -15,6 +15,7 @@ import (
 	_ "github.com/v2fly/v2ray-core/v4/app/stats/command"
 
 	// Developer preview services
+	_ "github.com/v2fly/v2ray-core/v4/app/instman/command"
 	_ "github.com/v2fly/v2ray-core/v4/app/observatory/command"
 
 	// Other optional features.
@@ -30,6 +31,7 @@ import (
 	_ "github.com/v2fly/v2ray-core/v4/transport/internet/tagged/taggedimpl"
 
 	// Developer preview features
+	_ "github.com/v2fly/v2ray-core/v4/app/instman"
 	_ "github.com/v2fly/v2ray-core/v4/app/observatory"
 
 	// Inbound and outbound proxies.