Skip to main content
Version: 2.8.x(Latest)

After successfully implementing our first microservice, developing the second one will be more straightforward as we're now familiar with the process.

Code Initialization


Execute the following command to create a service named word in the app directory.

$ gf init app/word -a
initializing...
initialization done!
you can now run "cd app/word && gf run main.go" to start your journey, enjoy!

Following the same process as before, remove the following files to start with a clean environment:

app/word/api/*
app/word/internal/controller/*
app/word/internal/cmd/cmd.go

Navigate to the microservice directory to begin development:

$ cd app/word

Generating Data Models


Creating Database Tables

Execute the following SQL statement in the word database to create the table for storing word data:

CREATE TABLE words (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
uid INT UNSIGNED NOT NULL,
word VARCHAR ( 255 ) NOT NULL,
definition TEXT,
example_sentence TEXT,
chinese_translation VARCHAR ( 255 ),
pronunciation VARCHAR ( 255 ),
created_at DATETIME,
updated_at DATETIME
);

Generating DAO Models

app/user/hack/config.yaml

gfcli:  
gen:
dao:
- link: "mysql:root:12345678@tcp(srv.com:3306)/word"
descriptionTag: true
$ gf gen dao
generated: D:\project\proxima\app\word\internal\dao\words.go
generated: D:\project\proxima\app\word\internal\dao\internal\words.go
generated: D:\project\proxima\app\word\internal\model\do\words.go
generated: D:\project\proxima\app\word\internal\model\entity\words.go
done!

Generating Protocol Buffer Entity Models

app/user/hack/config.yaml

gfcli:
gen:
dao:
- link: "mysql:root:12345678@tcp(srv.com:3306)/word"
descriptionTag: true

pbentity:
- link: "mysql:root:12345678@tcp(srv.com:3306)/word"
$ gf gen pbentity
generated: D:\project\proxima\app\word\manifest\protobuf\pbentity\words.proto
done!