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:
parent
ea1099d924
commit
779a7c84ed
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user