Skip to main content

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-profile
    • version-number for ex. v1
      • external-svc - contains exposed APIs logic implementation.
      • internal-svc - contains unexposed API's logic implementation (only internal call).
      • models - database models, operations using gorm
      • pb - 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.

For internal and external services, the proto must be identical

Generate the code from proto#

tip

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#

Service Registration into GoArcc#

Your 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