Thanks to visit codestin.com
Credit goes to github.com

Skip to content

core tool could support a simple solution to the "main" vs. "library" dilemma #1381

@rcoreilly

Description

@rcoreilly

Describe the feature

A constant challenge in Go is the inability to have a given directory contain both an executable and also be importable as a package for use elsewhere: https://groups.google.com/g/Golang-nuts/c/frh9zQPEjUk

If you want the executable to be named the same as the overall importable package, then you need two levels of subdirectories:

mypackage/
    mypackage.go
    ...
    cmd/
        mypackage/
            main.go
            mypackage  <- go build makes this

It would be great if you could instead just have this:

mypackage/
    mypackage.go
    ...
    cmd/
        main.go

and a core build or core run in the mypackage directory would automatically detect the presence of the cmd subdir, do a go build in that directory, and put the output back up at top level with the name mypackage.

How awesome would that be!?

This is actually a fairly urgent issue for me because I want all my sims to be accessible as imports into an overall content interactive doc space, and also available as a local executable command to run on a cluster etc.

I will implement in a PR now -- should take just a few mins.

Relevant code

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions