1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-15 16:56:08 -05:00
v2fly/app/restfulapi/service.go
Loyalsoldier dce8764fd7
Lint: fix lint (#1427)
* Lint: replace golint with revive
* Lint: fix lint
2021-11-27 17:16:41 +08:00

59 lines
1.1 KiB
Go

package restfulapi
import (
"context"
"net"
"sync"
core "github.com/v2fly/v2ray-core/v4"
"github.com/v2fly/v2ray-core/v4/features"
feature_stats "github.com/v2fly/v2ray-core/v4/features/stats"
)
//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
type restfulService struct {
listener net.Listener
config *Config
access sync.Mutex
stats feature_stats.Manager
ctx context.Context
}
func (rs *restfulService) Type() interface{} {
return (*struct{})(nil)
}
func (rs *restfulService) Start() error {
defer rs.access.Unlock()
rs.access.Lock()
return rs.start()
}
func (rs *restfulService) Close() error {
defer rs.access.Unlock()
rs.access.Lock()
if rs.listener != nil {
return rs.listener.Close()
}
return nil
}
func (rs *restfulService) init(config *Config, stats feature_stats.Manager) {
rs.stats = stats
rs.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
}