# README
π₯Using the go-dandelion-cli
1.Install
go get github.com/team-dandelion/go-dandelion-cli@latest
go install github.com/team-dandelion/go-dandelion-cli@latest
2.Create project
In the local directory, create a project as prompted.
# Create project
go-dandelion-cli project -n example-project
- -n: project name
Project directory structureοΌ
β
βββ common // Used to store public structures
β
β
βββ logic-rpc
β βββ boot
β β βββ boot.go // Register initialization methods here
β βββ cmd
β β βββ api
β β β βββ server.go // Service startup entry point
β β βββ cobra.go // Cobra command registration
β βββ config // Service configuration folder
β β βββ configs_local.yaml // Local configuration file
β βββ global
β β βββ global.go // Global variables
β βββ internal
β β βββ dao // Database operations
β β βββ enum // Enums and constants
β β βββ logic // Business logic
β β βββ model // Data models
β β βββ service // Services
β β βββ api.go // Service interface
β βββ static
β β βββ rpc-server.txt // Service name
β βββ tools // Utility classes
β β
β βββ main.go // Entry file
β
β
βββ gateway-http
β βββ cmd
β β βββ api
β β β βββ server.go // Service startup entry point
β β βββ cobra.go // Cobra command registration
β βββ config // Service configuration folder
β β βββ configs_local.yaml // Local configuration file
β βββ internal
β β βββ middleware // Custom middleware
β β βββ route // Route management
β β β βββ route.go // Provides basic routes
β β βββ service // Services
β βββ static
β β βββ http-server.txt // Service name
β β
β βββ main.go // Entry file
3.Run service
3.1 Run rpc service
Enter the service directory
cd example-project/logic-rpc
Remove redundant configuration
In config/configs_local.yaml
, remove the mysql and redis configurations
Added test rpc methods
Add a Test Model to common/test_model.go
type (
TestParams struct{}
TestResp struct {
Data string
}
)
Add a Test rpc method to service/api.go
import (
"context"
"example-project/common"
)
type RpcApi struct {
}
func (ra *RpcApi) Test(ctx context.Context, req common.TestParams, resp *common.TestResp) (err error) {
resp.Data = "Hello, go-dandelion"
return nil
}
Start service
go build -o logic-rpc
#θΏθ‘
./logic-rpc server
3.2 Run http service
Enter the service directory
cd example-project/gateway-http
Add api interface
Add a TestFunc method to service/test_controller.go
import (
"example-project/common"
routing "github.com/gly-hub/fasthttp-routing"
"github.com/team-dandelion/go-dandelion/application"
"github.com/team-dandelion/go-dandelion/server/http"
)
type AuthController struct {
http.HttpController
}
func (a *AuthController) TestFunc(c *routing.Context) error {
return application.SRpcCall(c, "logic-rpc", "Test", new(common.TestParams), new(common.TestResp))
}
Registered routes in route/route.go
testController := new(service.AuthController)
baseRouter.Get("/test", testController.TestFunc)
Start service
go build -o gateway-http
#θΏθ‘
./gateway-http server
test
curl --location 'http://172.16.49.201:8080/api/test' --data ''
4.Customize the creation service
4.1 Go to the application directory
cd example-project
4.2 Build service
go-dandelion-cli server
output:
Type of service you want to create, enter a numberοΌ1-rpc 2-httpοΌ:1
RPC SERVICE NAME: example-server
Whether to initialize mysql?οΌy/nοΌ:y
Whether to initialize redis?οΌy/nοΌ:y
Whether to initialize the logger?οΌy/nοΌ:y
Whether to initialize the trace link?οΌy/nοΌ:y
# Packages
No description provided by the author