Skip to content

cdlan/ms-template-go

Repository files navigation

ms template

Template x go microservices

Badges

Latest Release

Deploy instruction

The microservice will be packaged in a docker image, to deploy use the provided configs in the deployments folder

Develop Requirements

  • install go

Make sure to install the version indicated in the go.mod file

  • Docker for building

Instructions - README

Setup repo

  • Edit go.mod with the name (like git.cdlan.net/<group>/<reponame>) of your project (and update all import statements)
  • Edit serviceName in server.go with the name of the service
  • Edit app.image in docker-compose.yaml
  • (optional) Uncomment all rows from .gitlab-ci.yml to enable pipelines
  • Register project in sonarqube

Quick Start

  1. Edit .proto files in api folder
  2. Run this command to generate go code from the protos
make grpc
  1. In grpc create a file for each service that you defined and implement the service servers and add a NewXYZServer() that return a pointer to the server
  2. In server.go register the newly created servers

Docs

We use mkdocs for documentation

  1. Update the content of mkdocs.yml for title and url
  2. Place md files inside the docs folder eventually in subfolders
  3. Run this command to build the container locally and serve it
make docs

Tests

We use testify for tests. Each package should have this two test suite defined:

type IntegrationTestSuite struct {
	suite.Suite
}

type UnitTestSuite struct {
	suite.Suite
}

func TestIntegrationTestSuite(t *testing.T) {
	suite.Run(t, new(IntegrationTestSuite))
}

func TestUnitTestSuite(t *testing.T) {
	suite.Run(t, new(UnitTestSuite))
}
  • UnitTestSuite should contains all tests that can be run on code alone (no db, no ext services connections) these can always be run inside the CI pipeline
  • IntegrationTestSuite contains all tests that should be run with some dependencies (db/ext-services/...)

To add a new test inside a suite:

func (suite *IntegrationTestSuite) TestCustomerGroupDAO_RmNonExistentResFromCustomerGroup() {

	res := model.CustomerGroupResource{
		CustomerGroupId: 99,
		Resource:        "test",
		AccessType:      "read",
	}

	dao := CustomerGroupDAO{}
	ctx := context.Background()

	// rm res
	err := dao.RemoveResourceAccess(ctx, res)
	assert.NotNil(suite.T(), err)
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors