首页  

GO自定义模块实例     所属分类 go 浏览量 81
main.go

package main

import (
    "fmt"
    "goproverbs"
)

func main() {
   str := goproverbs.Random()
   fmt.Println(str)  
}

引入自定义模块 goproverbs

目录结构
main.go
goproverbs/goproverbs.go

go run main.go
main.go:5:5: package goproverbs is not in GOROOT (/usr/local/go/src/goproverbs)

cp -r  goproverbs /usr/local/go/src/
cp: /usr/local/go/src/goproverbs: Permission denied
cp: goproverbs: unable to copy extended attributes to /usr/local/go/src/goproverbs: Permission denied
cp: /usr/local/go/src/goproverbs/goproverbs.go: No such file or directory
dugang:goproverbs dugang$ sudo cp -r  goproverbs /usr/local/go/src/
Password:
dugang:goproverbs dugang$ go run main.go
Clear is better than clever.
dugang:goproverbs dugang$ go run main.go
Syscall must always be guarded with build tags.
dugang:goproverbs dugang$ go run main.go
Errors are values.

把 goproverbs 目录复制到 GOROOT 目录下 ,搞定

还有其他方式 实现自定义模块的组织吗?

完整代码
https://gitee.com/dyyx/hellocode/tree/master/web/tech/go/goproverbs


或者直接建链接 sudo ln -s /Users/dugang/dugang/hellocode/web/tech/go/goproverbs2/src/goproverbs2 /usr/local/go/src/goproverbs2 https://gitee.com/dyyx/hellocode/tree/master/web/tech/go/goproverbs2/
GO箴言 goproverbs

上一篇     下一篇
GO多线程异步处理实例

go channel 实例

godoc安装

GO printf 格式化输出

mybatis 结果集处理

Mybatis常用工具类