Go Microservice Part IV - Service
By ski11up.com
In the previous blog post, Go MVC Part III - Model we have developed a Model of contact application including the DAO code which will retrieve the information from the data source which in our case is Contact struct.
Let’s start with developing Service in this post.
Service
Model contains domain objects as well the information retrieval mechanical from the database. Let’s assume our database is nothing but a go struct for the simplicity of the application.
Below is the straight forward code of contact Service.
contact_service.go
1
2
3
4
5
6
7
8
9
package services
import (
"go-lang/go-serv/domain" (1)
)
func GetContact(id int64) (*domain.Contact, error) { (2)
return domain.GetContact(id) (3)
}
| 1 | importing the domain package |
| 2 | service takes an int64 argument and returns the pointer of the domain model |
| 3 | returning the domain object, this will be used by the Controller to present to the View |
Next
Go to Go MVC Part V - Controller to get started with the Controller code.