github.com/amlun/go-oauth2-server@v1.0.1/web/service.go (about)

     1  package web
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/RichardKnop/go-oauth2-server/config"
     7  	"github.com/RichardKnop/go-oauth2-server/oauth"
     8  	"github.com/RichardKnop/go-oauth2-server/session"
     9  )
    10  
    11  // Service struct keeps variables for reuse
    12  type Service struct {
    13  	cnf            *config.Config
    14  	oauthService   oauth.ServiceInterface
    15  	sessionService session.ServiceInterface
    16  }
    17  
    18  // NewService returns a new Service instance
    19  func NewService(cnf *config.Config, oauthService oauth.ServiceInterface, sessionService session.ServiceInterface) *Service {
    20  	return &Service{
    21  		cnf:            cnf,
    22  		oauthService:   oauthService,
    23  		sessionService: sessionService,
    24  	}
    25  }
    26  
    27  // GetConfig returns config.Config instance
    28  func (s *Service) GetConfig() *config.Config {
    29  	return s.cnf
    30  }
    31  
    32  // GetOauthService returns oauth.Service instance
    33  func (s *Service) GetOauthService() oauth.ServiceInterface {
    34  	return s.oauthService
    35  }
    36  
    37  // GetSessionService returns session.Service instance
    38  func (s *Service) GetSessionService() session.ServiceInterface {
    39  	return s.sessionService
    40  }
    41  
    42  // Close stops any running services
    43  func (s *Service) Close() {}
    44  
    45  func (s *Service) setSessionService(r *http.Request, w http.ResponseWriter) {
    46  	s.sessionService.SetSessionService(r, w)
    47  }