Skip to content

Experimenting with golang 1.18 workspaces, fuzzing and generics

Notifications You must be signed in to change notification settings

xmlking/go-workspace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-workspace

Experimenting with golang-1.18 multi-module workspaces

GitHub go.mod Go version Go

Install

Working with golang 1.18

brew install go 
$ go version 
go version go1.18 darwin/arm64

Run

# run generate first
go generate ./...

# root module
go run ./...
go test -v ./... 
go test -v -fuzz=Fuzz ./internal
# lib module
go test -v ./lib/...
# app modules
go run ./cmd/app1/...
go run ./cmd/app2/...

Build

go generate ./...
go build -v .
# check SBOM
go version -m go-workspace
# run binary
./go-workspace

Workspace commands

$ go help work
Usage:

        go work <command> [arguments]

The commands are:

        edit        edit go.work from tools or scripts
        init        initialize workspace file
        sync        sync workspace build list to modules
        use         add modules to workspace file

Run go work use -r ./ to recursively add directories in the argument directory with a go.mod file to your workspace. If a directory doesn’t have a go.mod file, or no longer exists, the use directive for that directory is removed from your go.work file.

# recursively add directories to go.work
go work use -r .
# pushes the dependencies in the go.work file back into the go.mod files of each workspace module.
go work sync
# provides a command-line interface for editing go.work, for use primarily by tools or scripts.
go work edit
# `go mod` examples
go mod download
go mod graph
go mod tidy
go mod verify
go work sync
go mod why -m github.com/ssoroka/slice

Project structure

.
├── README.md
├── cmd
│   ├── app1
│   │   ├── go.mod
│   │   └── main.go
│   └── app2
│       ├── go.mod
│       └── main.go
├── go.work
├── go.work.sum
└── lib
    ├── binaryheap
    │   ├── binaryheap.go
    │   └── binaryheap_test.go
    ├── filter
    │   ├── filter.go
    │   └── filter_test.go
    └── go.mod

Reference