mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-02-20 23:47:21 -05:00
added service initialization
This commit is contained in:
parent
ea1099d924
commit
779a7c84ed
@ -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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user