servicetmpl1

module
v0.0.0-...-ebc0203 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2020 License: MIT

README

A Self-Evolved Microservice Framework in Go

Other language:

中文

This is a major upgrade version of jfeng45/servicetmpl.

The followings are a series of articles to explain the different areas of the application design:

Getting Started

Installation and Setting Up

Don't need to finish all steps in this section up-front to get the code up running. The simplest way is to get the code from github and run it and come back to install the part when there is a real need. However, it will encounter an error when accesses the database. So, I'd recommend you install at least one database ( MySQL is better), then most of the code will work.

Download Code
go get github.com/jfeng45/servicetmpl1
Set Up MySQL

There are two database implementations, MySQL and CouchDB, but most functions are implemented in MySQL. You'd better install at least one of them.

Install MySQL
run SQL script in script folder to create database and table
Install CouchDB

The code works fine without it. CouchDB is created to show the feature of switching database by changing configuration.

Installation on Windows

Installation on Linux

Installation on Mac

CouchDB Example

Set up CouchDB
Access "Fauxton" through browser: http://localhost:5984/_utils/# (login with: admin/admin).
Create new database "service_config" in "Fauxton".
Add the following document to the database ( "_id" and "_rev" are generated by database, no need to change it):
{
  "_id": "80a9134c7dfa53f67f6be214e1000fa7",
  "_rev": "4-f45fb8bdd454a71e6ae88bdeea8a0b4c",
  "uid": 10,
  "username": "Tony",
  "department": "IT",
  "created": "2018-02-17T15:04:05-03:00"
}
Install Cache Service (Another Microservice)

Without it, calling another Microservice piece won't work, the rest of application works fine. Please follow instructions in reservegrpc to set up the service.

Start Application
Start MySQL Server
cd [MySQLroot]/bin
mysqld
Start CouchDB Server
It should already have been started
Start Cache Service

Please follow instructions in reservegrpc to start the server.

Run main
Run as a local application

In "main()" function of "main.go", there are two functions "testMySql()" and "testCouchDB()". "testMySql()" reads configurations from "configs/appConifgDev.yaml" and accesses MySQL. "testCouchDB()" reads from "configs/appConifgProd.yaml" and access CouchDB. There are multiple functions in "testMySql()", you can focus on testing one each time by commenting out others.

cd [rootOfProject]/cmd
go run main.go
Run as a gRPC Microservice application

Start gRPC Server

cd [rootOfProject]/cmd/grpcserver
go run grpcServerMain.go

Start gRPC Client

cd [rootOfProject]/cmd/grpcclient
go run grpcClientMain.go

License

MIT License

Directories

Path Synopsis
app
config
Package config reasd configurations from a YAML file and load them into a AppConfig type to save the configuration information for the application.
Package config reasd configurations from a YAML file and load them into a AppConfig type to save the configuration information for the application.
container
package container use dependency injection to create concrete type and wire the whole application together
package container use dependency injection to create concrete type and wire the whole application together
container/datastorefactory
Package datastorefactory using factory method pattern to create concrete database handler.
Package datastorefactory using factory method pattern to create concrete database handler.
container/usecasefactory
Package usecasefactory using factory method pattern to create concrete case case.
Package usecasefactory using factory method pattern to create concrete case case.
logger
Package logger represents a generic logging interface
Package logger represents a generic logging interface
Package applicationservice represents varies third part resource need to be accessed.
Package applicationservice represents varies third part resource need to be accessed.
cacheclient/generatedclient
Package generatedclient is created to save the generated client lib for gRPC call.
Package generatedclient is created to save the generated client lib for gRPC call.
dataservice
Package dataservice and it's sub-package represents data persistence service, mainly access database, but also including data persisted by other Micro-service.
Package dataservice and it's sub-package represents data persistence service, mainly access database, but also including data persisted by other Micro-service.
dataservice/userdata/couchdb
Package couchdb represents the CouchDB implementation of the user data persistence layer
Package couchdb represents the CouchDB implementation of the user data persistence layer
dataservice/userdata/sqldb
Package sql represents SQL database implementation of the user data persistence layer
Package sql represents SQL database implementation of the user data persistence layer
paymentclient
Package paymentclient is created to show the project structure, no real use.
Package paymentclient is created to show the project structure, no real use.
userclient
Package userclient is client library if you need to call the user Micro-service as a client.
Package userclient is client library if you need to call the user Micro-service as a client.
cmd
domain
usecase/listuser
Package registration represents the concrete implementation of ListUserUseCaseInterface interface
Package registration represents the concrete implementation of ListUserUseCaseInterface interface
usecase/registration
Package registrationTx represents the concrete implementation of RegistrationUseCaseInterface and RegistrationTxUseCaseInterface interface.
Package registrationTx represents the concrete implementation of RegistrationUseCaseInterface and RegistrationTxUseCaseInterface interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL