github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/protocol/service.go (about) 1 /* For license and copyright information please see the LEGAL file in the code repository */ 2 3 package protocol 4 5 // Services is the interface that must implement by any Application. 6 type Services interface { 7 // RegisterService use to register application services. 8 // Due to minimize performance impact, This method isn't safe to use concurrently and 9 // must register all service before use GetService methods. 10 RegisterService(s Service) 11 12 GetServiceByID(id MediaTypeID) (ser Service, err Error) 13 GetServiceByMediaType(mt string) (ser Service, err Error) 14 GetServiceByURI(uri string) (ser Service, err Error) 15 } 16 17 // Service is the interface that must implement by any struct to be a service. 18 // Set fields methods in this type must accept just once to prevent any mistake by change after set first. 19 type Service interface { 20 // Fill just if any http like type handler needed! Simple URI not variable included. 21 // API services can set like "/m?{{.ServiceID}}" but it is not efficient, instead find services by ID as integer. 22 URI() string // suggest use just URI.Path 23 24 Priority() Priority // Use to queue requests by its priority 25 Weight() Weight // Use to queue requests by its weights in the same priority 26 27 // Service authorization to authorize incoming service request 28 CRUDType() CRUD 29 UserType() UserType 30 31 // Handlers, Due to specific args and returns, we can't uncomment some of them 32 // 33 // Call service locally by import service package to other one 34 // Process(st Stream, req interface{}) (res interface{}, err Error) 35 // 36 // Call service remotely by preferred protocol. 37 // Do(req interface{}) (res interface{}, err Error) 38 39 SRPCHandler 40 HTTPHandler // Some other protocol like gRPC, SOAP, ... must implement inside HTTP, If they are use HTTP as a transfer protocol. 41 42 ServiceDetails 43 } 44 45 type ServiceDetails interface { 46 Request() []Field 47 Response() []Field 48 49 Details 50 MediaType 51 }