How could I copy a package from the golang source to hack on

huangapple go评论96阅读模式
英文:

How could I copy a package from the golang source to hack on

问题

我想基本上从golang源代码中复制parse和template包:http://golang.org/pkg/text/

我想能够随意修改代码并进行一些有趣的和学习性质的尝试。

有人可以告诉我如何做到这一点吗?

我可以只复制包文件夹,然后将其移动到我自己的包中,像这样:

$GOPATH/src/github/user/parse
$GOPATH/src/github/user/template

这样做安全吗?它将如何构建?

英文:

I want to basically copy the parse and template packages from the golang source: http://golang.org/pkg/text/

I want to be able to just play around wit the code and hack on it for fun and learning etc.

Can someone tell me how to go about doing this?

Could I just copy the package folders and then somehow move it to my own package like:

$GOPATH/src/github/user/parse
$GOPATH/src/github/user/template

Is this a safe way to do this? How will it build?

答案1

得分: 4

是的,你可以按照你描述的方式直接复制文件夹。

当你在应用程序中导入它时,只需使用新的导入路径:

import (
    "github.com/user/parse"
    "github.com/user/template"
)

这样做是完全安全的。继续编码吧!

附注:

我假设你的路径实际上应该是:

$GOPATH/src/github.com/user/parse

因为如果你使用GitHub来托管你的包,域名(.com)也会包含在go get路径中。

附注2:

记得更新github.com/user/template包中的导入,将其引用你的新的parse包,而不是原始的包。

英文:

Yes, you can just copy the folder like you've described.

When you import it in your application, you just use your new import path:

import (
    "github.com/user/parse"
    "github.com/user/template"
)

It is completely safe to do that. Just Go ahead and code!

Ps.

I assumed your path would actually be:

$GOPATH/src/github.com/user/parse

since the domain (.com) will also be included in the go get path if you use github to host your package.

Ps2.

Remember to update the imports in the github.com/user/template package to refer to your new parse package instead of the original one.

huangapple
  • 本文由 发表于 2014年5月11日 09:03:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/23587880.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定