Giter Site home page Giter Site logo

go-study's Introduction

go-study

Workspaces

Tutorial: Getting started with multi-module workspaces

Introduction

  • workspaceGo 1.18 版本后引入;
  • workspace 即工作空间,用于统一管理多个软件模块,如可以快速测试、构建和运行多个模块中的代码;
  • workspace 使用 go work 工具进行管理,配置在 go.work 文件中,用法和 go mod 相似;
  • workspace 可以不使用 replace 指令就实现替换模块的功能(见示例)。

Usage

go help work [subcommand]

go work init [moddirs]

在当前目录下创建一个 go.work 文件,即将当前目录标识为一个工作空间:

  • 当忽略 moddirs 时,仅创建一个不包含任何 use 指令的 go.work 文件;
  • 当添加 moddirs 时,需要每个 moddir 下都存在 go.mod 文件,然后会在 go.work 文件中使用 use 指令添加这些 moddir
# Usage 1: go mod init without any moddir
go mod init

# Usage 1: go mod init with one moddir
go mod init ./module1

# Usage 2: go mod init with multiple moddirs
go mod init ./module1 ./module2

当进行上述配置后,可以在工作空间中运行任意模块(即使我们没有在模块内):

go run ./module1

go work use

将指定模块添加到当前工作空间中。

# 将指定模块加入到当前工作空间
go work use ./module2

# 将指定目录下的所有模块都加入到当前工作空间
go work use -r ./modules

go-study's People

Contributors

yobol avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.