Go, Golang: program, package structure for the command line interface

This is a newbie question ... Say I have a Go code in a directory (a repository initiated here as root) called "myprogram". And I write some packages, divided into several subdirectories.

Then i have

root directory

MyProgram
----------- package1
----------- package2
----------- package3

Then in the myprogram directory I will write the code with the main package for the main program, and the main program will call all the packages that are defined in subdirectories, for example:

main.go

import "github.com/username/package1"
import "github.com/username/package2"
import "github.com/username/package3"

func main() {
    package1.Function1()
    ....
}

Then I can just run this code with

$ go run main.go

I have no problems so far. But what if this program has some functions with flags?

$ go run main.go  flag1 flag2

It works, but I want to run something like

$ myprogram
$ flag1
....
$ flag2

myprogram, ,

MyProgram
----------- package1
----------- package2
----------- package3

Vim , - ...

$ vim

, , main?

, ? , , .

go install

, .

!

+3
1

go build. . go build <packagename>, $GOPATH/bin.

+2

All Articles