Skip to content

Instantly share code, notes, and snippets.

@microo8
Last active April 8, 2017 11:31
Show Gist options
  • Save microo8/53684deb27f06738073177968648b89c to your computer and use it in GitHub Desktop.
Save microo8/53684deb27f06738073177968648b89c to your computer and use it in GitHub Desktop.
helloservice
package helloservice
//HelloService is the Service with its public API
type HelloService struct {
HelloEndpoint chan *HelloReq //Endpoint on which the service listens
}
//NewHelloService returns a new Service
func NewHelloService() *HelloService {
return &HelloService{
HelloEndpoint1: make(chan *HelloReq),
}
}
//Run spins up an go routine in which the Service processes its requests
func (s *HelloService) Run() {
go func() {
for {
select {
case req := <-s.HelloEndpoint:
go s.ProcessHelloReq(req)
}
}
}()
}
//ProcessHelloReq processes request HelloReq and returns an response
func (s *HelloService) ProcessHelloReq(req *HelloReq) {
req.Resp <- &HelloResp{
Result: "Hello " + req.Query,
}
}
//HelloReq used to send request to the HelloEndpoint of Service
type HelloReq struct {
Query string
Resp chan *HelloResp
}
//HelloResp used as an response from the HelloEndpoint of Service
type HelloResp struct {
Result string
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment