1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

added service initialization

This commit is contained in:
Shelikhoo 2021-09-06 13:40:44 +01:00
parent ea1099d924
commit 779a7c84ed
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316

View File

@ -3,6 +3,9 @@ package restful_api
import (
"context"
"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"
"sync"
)
@ -16,6 +19,8 @@ type restfulService struct {
config *Config
access sync.Mutex
stats feature_stats.Manager
ctx context.Context
}
@ -37,3 +42,19 @@ func (r *restfulService) Close() error {
}
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
}