Reputation: 41
I have created a package named go-orm in golang and its structure is follows.
go-orm
--| mine.go
--| src
-----| src.go
-----| db
--------| DBConnection.go
When I ran the command "go install" in go-orm directory, it created only go-orm.a but not src.a and db.a (sub directories or packages). When I checked "go install" with mgo package it created .a files for it's sub directory "bson".
I need the same functionality for my package. What change is needed in my package to make this possible.
my package is in GOPATH/src/ directory. All my sub packages(src and db) exist.
Upvotes: 1
Views: 1690
Reputation: 41
After long analysis I found that "import" statement in root directory go file
can do the trick. I created one extra file named create_archieve.go in root directory(go-orm). Inside that I just inserted the following lines which created go-orm.a, src.a and db.a.
package nosql_orm
import _"go-orm/src/db"
Upvotes: -1
Reputation: 166825
Go Path
The Go path is a list of directory trees containing Go source code. It is consulted to resolve imports that cannot be found in the standard Go tree. The default path is the value of the GOPATH environment variable, interpreted as a path list appropriate to the operating system (on Unix, the variable is a colon-separated string; on Windows, a semicolon-separated string; on Plan 9, a list).
Each directory listed in the Go path must have a prescribed structure:
The src/ directory holds source code. The path below 'src' determines the import path or executable name.
The pkg/ directory holds installed package objects. As in the Go tree, each target operating system and architecture pair has its own subdirectory of pkg (pkg/GOOS_GOARCH).
If DIR is a directory listed in the Go path, a package with source in DIR/src/foo/bar can be imported as "foo/bar" and has its compiled form installed to "DIR/pkg/GOOS_GOARCH/foo/bar.a" (or, for gccgo, "DIR/pkg/gccgo/foo/libbar.a").
The bin/ directory holds compiled commands. Each command is named for its source directory, but only using the final element, not the entire path. That is, the command with source in DIR/src/foo/quux is installed into DIR/bin/quux, not DIR/bin/foo/quux. The foo/ is stripped so that you can add DIR/bin to your PATH to get at the installed commands.
Here's an example directory layout:
GOPATH=/home/user/gocode
/home/user/gocode/ src/ foo/ bar/ (go code in package bar) x.go quux/ (go code in package main) y.go bin/ quux (installed command) pkg/ linux_amd64/ foo/ bar.a (installed package object)
Use the prescribed directory structure, including the use of src
as a directory name. Follow the example. Don't use src
, pkg
, or bin
as package names.
go-orm
--| mine.go
--| src <== !? Don't use src as a package name.
-----| src.go
-----| db
--------| DBConnection.go
Upvotes: 2