Service
GoArcc provides all the basic functionalities before building any embedded service or microservice. It lets you focus only on the business logic of your application.
What is Service
Service is a micro-functionality or small module, or you can say it's a microservice, which will be plugged into your existing codebase. Service is independent and can be easily plugged in and plugged out.
Directory structure of a Service
service-name
- for ex- user-profileversion-number
for ex. v1external-svc
- contains exposed APIs logic implementation.internal-svc
- contains unexposed API's logic implementation (only internal call).models
- database models, operations using gormpb
- autogenerated files from .proto file
Creating a Service
Service schema is defined inside a proto file. Learn how to define a proto here.
Also, read about the proto defining guideline of GoArcc here
For example, you are creating a service that will perform user-related crud operations like creating, updating, or deleting a user.
Let’s create a file user.proto
. See the sample proto file.
#
Generate the code from prototip
Make sure you have installed all the required plugins into your GOPATH
commands will be present into generate.go
file.
OR
you can directly run go generate
for code generation.
#
Service implementation- initialize your constructor in
service.go
file. see the sample - implement the interfaces which is generated into
pb/.._grpc.go
file.
see the example implementation
#
Service Registration into GoArccYour Service is ready, you can register you service to gRPC
or rest
or graphQL
.
- see example to register your service as REST.
- see example to register your service as gRPC.
- see example to register your service as graphQL.
You can find your service running in the respective ports.
See an example CRUD service here