Browse Source

added service initialization

Shelikhoo 4 years ago
parent
commit
779a7c84ed
1 changed files with 21 additions and 0 deletions
  1. 21 0
      app/restful-api/service.go

+ 21 - 0
app/restful-api/service.go

@@ -3,6 +3,9 @@ package restful_api
 import (
 import (
 	"context"
 	"context"
 	"github.com/gin-gonic/gin"
 	"github.com/gin-gonic/gin"
+	core "github.com/v2fly/v2ray-core/v4"
+	"github.com/v2fly/v2ray-core/v4/features"
+	feature_stats "github.com/v2fly/v2ray-core/v4/features/stats"
 	"net"
 	"net"
 	"sync"
 	"sync"
 )
 )
@@ -16,6 +19,8 @@ type restfulService struct {
 	config   *Config
 	config   *Config
 	access   sync.Mutex
 	access   sync.Mutex
 
 
+	stats feature_stats.Manager
+
 	ctx context.Context
 	ctx context.Context
 }
 }
 
 
@@ -37,3 +42,19 @@ func (r *restfulService) Close() error {
 	}
 	}
 	return nil
 	return nil
 }
 }
+
+func (r *restfulService) init(config *Config, stats feature_stats.Manager) {
+	r.stats = stats
+	r.config = config
+}
+
+func newRestfulService(ctx context.Context, config *Config) (features.Feature, error) {
+	r := new(restfulService)
+	r.ctx = ctx
+	if err := core.RequireFeatures(ctx, func(stats feature_stats.Manager) {
+		r.init(config, stats)
+	}); err != nil {
+		return nil, err
+	}
+	return r, nil
+}