github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/service/service.go (about)

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package service
     4  
     5  import (
     6  	"../mediatype"
     7  	"../protocol"
     8  )
     9  
    10  // Service store needed data for a service to implement protocol.Service when embed to other struct that implements other methods!
    11  type Service struct {
    12  	uri string // Fill just if any http like type handler needed! Simple URI not variable included! API services can set like "/m?{{.ServiceID}}" but it is not efficient, find services by ID.
    13  
    14  	priority protocol.Priority // Use to queue requests by its priority
    15  	weight   protocol.Weight   // Use to queue requests by its weights in the same priority
    16  
    17  	// Authorization data to authorize incoming service
    18  	crud     protocol.CRUD // CRUD == Create, Read, Update, Delete
    19  	userType protocol.UserType
    20  
    21  	mediatype.MediaType
    22  }
    23  
    24  // func (s *Service) Init() {}
    25  
    26  func (s *Service) SetURIRoutePath(uri string) { s.uri = uri }
    27  func (s *Service) SetPriority(priority protocol.Priority, weight protocol.Weight) {
    28  	s.priority = priority
    29  	s.weight = weight
    30  }
    31  func (s *Service) SetAuthorization(crud protocol.CRUD, userType protocol.UserType) {
    32  	s.crud = crud
    33  	s.userType = userType
    34  }
    35  
    36  func (s *Service) URI() string                 { return s.uri }
    37  func (s *Service) Priority() protocol.Priority { return s.priority }
    38  func (s *Service) Weight() protocol.Weight     { return s.weight }
    39  func (s *Service) CRUDType() protocol.CRUD     { return s.crud }
    40  func (s *Service) UserType() protocol.UserType { return s.userType }
    41  
    42  /*
    43  *********** Handlers ***********
    44  not-implemented handlers of the service.
    45  */
    46  
    47  func (s *Service) ServeSRPC(st protocol.Stream) (err protocol.Error) {
    48  	err = &ErrServiceNotAcceptSRPC
    49  	return
    50  }
    51  func (s *Service) ServeSRPCDirect(conn protocol.Connection, request []byte) (response []byte, err protocol.Error) {
    52  	err = &ErrServiceNotAcceptSRPCDirect
    53  	return
    54  }
    55  func (s *Service) ServeHTTP(st protocol.Stream, httpReq protocol.HTTPRequest, httpRes protocol.HTTPResponse) (err protocol.Error) {
    56  	err = &ErrServiceNotAcceptHTTP
    57  	return
    58  }