Saturday, May 24, 2025
HomeGolang`gonectr` for the Gone framework - Neighborhood

`gonectr` for the Gone framework – Neighborhood


Command-line device for Gone framework, simplifying venture creation, module administration, and code technology

Introduction

gonectr is the official command-line device for the Gone framework, designed to streamline the event strategy of Gone tasks. It gives a sequence of handy instructions to assist builders shortly create tasks, handle modules, generate code, and construct purposes. Whether or not you’re new to Gone or an skilled developer, gonectr can considerably enhance your improvement effectivity.

Set up

Technique 1: Utilizing go set up (Advisable)

Run the next command to put in gonectr:


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

After set up, gonectr can be situated within the $GOPATH/bin listing. Be certain that this listing is added to your system’s $PATH surroundings variable for world entry to the gonectr command.

Tip: When you’re not sure in regards to the location of $GOPATH, you possibly can test it by working go env GOPATH.

Technique 2: Direct Binary Obtain

It’s also possible to go to the gonectr/releases web page to obtain the most recent model binary on 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, chances are you’ll have to run chmod +x gonectr)

Characteristic Overview

gonectr gives the next core options:

  • Undertaking Creation: Rapidly scaffold Gone venture structure from templates

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

  • Code Era: Mechanically generate crucial Gone framework integration code

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

  • Construct and Run: Simplify venture constructing and working processes

Detailed Utilization Information

1. create Command: Create Gone Initiatives from Templates

The create command helps you shortly create Gone tasks primarily based on preset or customized templates.

View Assist:


gonectr create -h

Fundamental Utilization: Create Undertaking


gonectr create demo-project

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

Create Undertaking with Particular Template


gonectr create demo-project -t template-name

Checklist All Obtainable Templates


gonectr create -ls

This command lists all built-in venture templates with their temporary descriptions.

Create Undertaking with Module Identify


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

That is notably helpful when creating tasks that can be revealed as public packages.

Create Undertaking from Distant Git Repository Template


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

You possibly can instantly use any Git repository that follows the Gone template specification as a venture template.

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

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

Gone Module Greatest Follow: We suggest every Gone module to supply a number of gone.LoadFunc features, equivalent 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 venture 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 operate for initialization.

Uninstall/Modify Module

When executing gonectr set up module command:

  • If the module shouldn't be put in, it will likely be put in

  • If already put in, an interactive choice listing can be displayed the place you possibly can 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 whole Golang module identify.

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

The generate command scans venture 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 automated loading code:


func init() {

gone.

Masses(Load). // Load LoadFunc

Load(&MyGoner{}) // Load Goner

// ... Load extra Goners

}

Observe: If a package deal defines LoadFunc, it can solely load LoadFunc and never instantly load Goners, indicating that the consumer has chosen to manually handle Goners.

  1. Create import.gone.go file in the principle package deal listing to import all found Goner packages:

package deal foremost

import (

_ "take a look at"

_ "take a look at/modules/a"

_ "take a look at/modules/b"

)

Essential: 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 Important Perform Listing


gonectr generate -m cmd/server

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


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

Superior Utilization: Help A number of Gone Cases

When utilizing a number of Gone cases 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 venture 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 characteristic 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 package deal

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 tasks.

Options

View Assist:


gonectr construct -h

Fundamental Utilization


# Construct Gone venture 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 much like construct, serving as an enhanced wrapper round go run.

Options

View Assist:


gonectr run -h

Fundamental Utilization


# Run Gone venture in present listing

gonectr run

# Run particular file

gonectr run foremost.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 technology and venture administration processes however nonetheless internally calls normal Go instructions.

Q: How one can improve gonectr to the most recent model?

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

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

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

Extra Assets

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments