Categorygithub.com/team-dandelion/go-dandelion-cli
modulepackage
0.0.0-20250116030520-7b52d0936f37
Repository: https://github.com/team-dandelion/go-dandelion-cli.git
Documentation: pkg.go.dev

# 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