Services
NoteIMPORTANT!
The service file should be placed in directoryapp/services
Service is a relatively important component of an application. It holds all the main logic, determining the effectiveness and correctness of the application.
The service will be used by the Controller, Console (Command/Schedule/Queue) Or called from other Services.
The service will also help you call through external third-party used by the application.
So always think carefully and name the service files appropriately to suit your application. A small suggestion for naming and grouping services with the same purpose together. For example, there is a service auth_services.go
that will contain logic:
- SignIn(signIn *dto.SignIn) to login to system.
- SignUp(signUp *dto.SignUp) to register new account.
- SignOut(jwtToken string) to signout system.
- RefreshJWTToken(jwtToken, refreshToken string) to refresh JWT token.
Or another example of a forgotten password is forgot_password_services.go
and will contain logic:
- ForgotPassword(email string) to send email with a link have code to reset new password.
- UpdatePassword(code string, password string) to update new password from reset link was sent.
NoteTIP
You should not create each processing logic as a file or combine too much logic into one file because it will not bring too many semantic benefits. This will be difficult to find. Let’s create a service file with a bit more open semantics.
NoteIMPORTANT!
The Service is used in the following cases:
- Controller —> Service
- Service <—> Service
- Console —> Service