Tuesday, May 13, 2025
HomeGolang`gonectr` for the Gone framework - Group

`gonectr` for the Gone framework – Group


Command-line device for Gone framework, simplifying mission creation, module administration, and code era

Introduction

gonectr is the official command-line device for the Gone framework, designed to streamline the event means of Gone initiatives. It supplies a collection of handy instructions to assist builders rapidly create initiatives, handle modules, generate code, and construct functions. Whether or not you’re new to Gone or an skilled developer, gonectr can considerably enhance your growth effectivity.

Set up

Methodology 1: Utilizing go set up (Really helpful)

Run the next command to put in gonectr:


go set up github.com/gone-io/gonectr@newest

After set up, gonectr might be positioned within the $GOPATH/bin listing. Ensure this listing is added to your system’s $PATH atmosphere variable for international entry to the gonectr command.

Tip: If you happen to’re not sure concerning the location of $GOPATH, you may test it by operating go env GOPATH.

Methodology 2: Direct Binary Obtain

You too can go to the gonectr/releases web page to obtain the newest model binary in your working system, then:

  1. Extract the downloaded file

  2. Copy the extracted gonectr executable to a listing in your system PATH

  3. Make sure the file has execution permissions (on Linux/macOS, you might have to run chmod +x gonectr)

Function Overview

gonectr supplies the next core options:

  • Mission Creation: Rapidly scaffold Gone mission structure from templates

  • Module Set up: Combine Gone modules and robotically generate loading code

  • Code Technology: Routinely generate mandatory Gone framework integration code

  • Mock Technology: Create Mock implementations for interfaces, facilitating unit testing

  • Construct and Run: Simplify mission constructing and operating processes

Detailed Utilization Information

1. create Command: Create Gone Initiatives from Templates

The create command helps you rapidly create Gone initiatives based mostly on preset or customized templates.

View Assist:


gonectr create -h

Fundamental Utilization: Create Mission


gonectr create demo-project

This may create a primary Gone mission named demo-project within the present listing.

Create Mission with Particular Template


gonectr create demo-project -t template-name

Record All Accessible Templates


gonectr create -ls

This command lists all built-in mission templates with their transient descriptions.

Create Mission with Module Title


gonectr create demo-project -t template-name -m github.com/gone-io/my-module

That is notably helpful when creating initiatives that might be revealed as public packages.

Create Mission from Distant Git Repository Template


gonectr create demo-project -t https://github.com/gone-io/template-v2-web-mysql

You may straight use any Git repository that follows the Gone template specification as a mission template.

2. set up Command: Set up Gone Modules and Generate module.load.go

The set up command integrates Gone modules into your mission and robotically generates the required loading code.

Gone Module Greatest Follow: We advocate every Gone module to offer a number of gone.LoadFunc features, comparable to:

func Load(gone.Loader) error {

// Load associated Goners

return nil

}

View Assist:


gonectr set up -h

Fundamental Utilization: Set up Module


gonectr set up demo-module

This provides demo-module to your mission and generates the corresponding loading code.

Specify LoadFunc


# Specify LoadA and LoadB features for producing loading code

gonectr set up module LoadA,LoadB

Actual Instance


gonectr set up github.com/gone-io/goner/nacos RegistryLoad

This installs the nacos module and makes use of its RegistryLoad perform for initialization.

Uninstall/Modify Module

When executing gonectr set up module command:

  • If the module is just not put in, it is going to be put in

  • If already put in, an interactive choice checklist might be displayed the place you may uncheck undesirable LoadFunc to take away them from module.load.go

gone-io Official Modules, Supporting Brief Names


gonectr set up goner/nacos

Observe: For unofficial modules, it's essential use the entire Golang module identify.

3. generate Command: Generate *.gone.go Recordsdata for Gone Initiatives

The generate command scans mission directories and robotically generates integration code information wanted by the Gone framework.

Performance

This command will:

  1. Scan all packages in specified directories

  2. Create init.gone.go file for packages containing Goner or LoadFunc, producing computerized loading code:


func init() {

gone.

Hundreds(Load). // Load LoadFunc

Load(&MyGoner{}) // Load Goner

// ... Load extra Goners

}

Observe: If a bundle defines LoadFunc, it's going to solely load LoadFunc and never straight load Goners, indicating that the person has chosen to manually handle Goners.

  1. Create import.gone.go file in the primary bundle listing to import all found Goner packages:

bundle major

import (

_ "take a look at"

_ "take a look at/modules/a"

_ "take a look at/modules/b"

)

Vital: Don't manually modify *.gone.go information, as they are going to be robotically overwritten by gonectr.

Specify Scan Listing


# Can specify a number of directories concurrently

gonectr generate -s ./take a look at -s ./test2

Specify Essential Operate Listing


gonectr generate -m cmd/server

Superior Utilization: Generate import.gone.go for Non-main Package deal


gonectr generate -m for_import --main-package-name for_import

Superior Utilization: Assist A number of Gone Situations

When utilizing a number of Gone situations in the identical program, you should utilize --preparer-code and --preparer-package parameters:


# Goners in gone1 listing use instance-1 occasion

gonectr generate -s gone1 --preparer-code 'g.App("instance-1")' --preparer-package 'github.com/gone-io/goner/g'

# Goners in gone2 listing use instance-2 occasion

gonectr generate -s gone2 --preparer-code 'g.App("instance-2")' --preparer-package 'github.com/gone-io/goner/g'

Use with go generate

Create a generate.go file within the mission root listing and add the next code:


//go:generate gonectr generate -m main-package-dir

Then execute go generate ./... to robotically run the gonectr command.

4. mock Command: Generate Mock Code

The mock command generates Mock implementations for interfaces and registers them as Goners, facilitating integration into the Gone framework for testing.

Conditions: This function will depend on the uber mockgen device, please set up it first:

go set up go.uber.org/mock/mockgen@newest

View Assist:


gonectr mock -h

Fundamental Utilization


# Generate Mock implementation for UserService interface in service bundle

gonectr mock -package service -interfaces UserService

Extra Choices


# Generate Mock implementations for a number of interfaces and specify output listing

gonectr mock -package service -interfaces "UserService,OrderService" -output ./mocks

5. construct Command: Construct Gone Initiatives

The construct command is an enhanced wrapper round the usual go construct, particularly designed for Gone initiatives.

Options

View Assist:


gonectr construct -h

Fundamental Utilization


# Construct Gone mission in present listing

gonectr construct

# Specify output filename

gonectr construct -o myapp

# Use different go construct parameters

gonectr construct -v -ldflags="-s -w"

6. run Command: Run Gone Initiatives

The run command is just like construct, serving as an enhanced wrapper round go run.

Options

View Assist:


gonectr run -h

Fundamental Utilization


# Run Gone mission in present listing

gonectr run

# Run particular file

gonectr run major.go

# Run with parameters

gonectr run . -config=dev.yaml

FAQ

Q: What's the relationship between gonectr and normal Go instruments?

A: gonectr is a complement to straightforward Go instruments, particularly designed for the Gone framework. It simplifies Gone-specific code era and mission administration processes however nonetheless internally calls normal Go instructions.

Q: improve gonectr to the newest model?

A: Execute go set up github.com/gone-io/gonectr@newest to replace to the newest model.

Q: Ought to *.gone.go information be included in model management?

A: It’s really helpful to incorporate these information in model management as they're a part of the mission construction. Nevertheless, they may also be dynamically generated in CI/CD pipelines.

Extra Sources

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments