service.go 623 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package restful_api
  2. import (
  3. "context"
  4. "github.com/gin-gonic/gin"
  5. "net"
  6. "sync"
  7. )
  8. //go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
  9. type restfulService struct {
  10. *gin.Engine
  11. listener net.Listener
  12. config *Config
  13. access sync.Mutex
  14. ctx context.Context
  15. }
  16. func (r *restfulService) Type() interface{} {
  17. return (*struct{})(nil)
  18. }
  19. func (r *restfulService) Start() error {
  20. defer r.access.Unlock()
  21. r.access.Lock()
  22. return r.start()
  23. }
  24. func (r *restfulService) Close() error {
  25. defer r.access.Unlock()
  26. r.access.Lock()
  27. if r.listener != nil {
  28. return r.listener.Close()
  29. }
  30. return nil
  31. }