01.2.md: translation started
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
# 1.2 $GOPATH and workspace
|
||||
# 1.2 $GOPATH و فضای کاری
|
||||
|
||||
## $GOPATH
|
||||
|
||||
Go takes a unique approach to manage the code files with the introduction of a `$GOPATH` directory which contains all the go code in the machine. Note that this is different from the `$GOROOT` environment variable which states where go is installed on the machine. We have to define the `$GOPATH` variable before using the language, in *nix systems there is a file called `.profile` we need to append the below export statement to the file. The concept behind gopath is a novel one, where we can link to any go code at any instant of time without ambiguity.
|
||||
Go با معرفی دایرکتوری `$GOPATH` روش منحصر به فردی برای مدیریت فایل های حاوی کد دارد. در این مسیر تمام کدهای مرتبط با go در سیستم شما قرار گرفته است. توجه داشته باشید که این دایرکتوری با متغیر محیطی `$GOROOT`، که مشخص میکند go در چه مسیری نصب شده است، تفاوت دارد. قبل از اینکه از این زبان برای برنامهنویسی استفاده کنیم باید متغیر `$GOPATH` را تعریف کنیم. در سیستمهای شبه یونیکس (*nix) فایلی به نام `.profile` وجود دارد که باید دستور زیر را به انتهای این فایل اضافه کنیم. مفهوم استفاده از gopath یک مفهوم جدید محسوب می شود که طی آن، هر کد go را می توان در هر زمان و بدون هیچ گونه ابهامی لینک نمود.
|
||||
|
||||
Starting from go 1.8, the GOPATH environment variable now has a default value if it is unset. It defaults to `$HOME/go` on Unix and `%USERPROFILE%/go` on Windows.
|
||||
در ورژن go 1.8 به بعد، اگر متغیر محیطی GOPATH تنظیم نشود، یک مقدار پیش فرض برای آن در نظر گرفته می شود که در یونیکس مقدار `$HOME/go` و در ویندوز مقدار `%USERPROFILE%/go` را دارد.
|
||||
|
||||
In Unix-like systems, the variable should be used like this:
|
||||
|
||||
در سیستمهای شبه یونیکسی، این متغیر را میتوان به صورت زیر مورد استفاده قرار داد:
|
||||
export GOPATH=${HOME}/mygo
|
||||
|
||||
In Windows, you need to create a new environment variable called GOPATH, then set its value to `c:\mygo`( ***This value depends on where your workspace is located*** )
|
||||
در ویندوز، ابتدا باید یک متغیر محیطی به نام GOPATH ایجاد کنید، که با مقدار `c:\mygo` مقداردهی شده باشد. ( ***این مقدار بستگی به این دارد که محیط کاری شما در کجا قرار گرفته باشد*** )
|
||||
|
||||
It's OK to have more than one path (workspace) in `$GOPATH`, but remember that you have to use `:`(`;` in Windows) to break them up. At this point, `go get` will save the content to your first path in `$GOPATH`. It is highly recommended to not have multiples versions, the worst case is to create a folder by the name of your project right inside `$GOPATH`, it breaks everything that the creators were wishing to change in programming with the creation of go language because when you create a folder inside `$GOPATH` you will reference your packages as directly as <packagename>, and this breaks all the applications which will import your package because the `go get` won't find your package. Please follow conventions, there is a reason conventions are created.
|
||||
|
||||
@@ -22,7 +21,7 @@ In `$GOPATH`, you must have three folders as follows:
|
||||
|
||||
In this book, I use `mygo` as my only path in `$GOPATH`.
|
||||
|
||||
## Package directory
|
||||
## دایرکتوری بستهها
|
||||
|
||||
Create package source files and folders like `$GOPATH/src/mymath/sqrt.go` (`mymath` is the package name) ( ***Author uses `mymath` as his package name, and the same name for the folder that contains the package source files***)
|
||||
|
||||
@@ -48,7 +47,7 @@ func Sqrt(x float64) float64 {
|
||||
```
|
||||
Now my package directory has been created and it's code has been written. I recommend that you use the same name for your packages as their corresponding directories, and that the directories contain all of the package source files.
|
||||
|
||||
## Compile packages
|
||||
## کامپایل بستهها
|
||||
|
||||
We've already created our package above, but how do we compile it for practical purposes? There are two ways to do this.
|
||||
|
||||
@@ -93,7 +92,7 @@ To compile this application, you need to switch to the application directory, wh
|
||||
|
||||
Hello world. Sqrt(2) = 1.414213562373095
|
||||
|
||||
## Install remote packages
|
||||
## نصب بستههای ریموت
|
||||
|
||||
Go has a tool for installing remote packages, which is a command called `go get`. It supports most open source communities, including Github, Google Code, BitBucket, and Launchpad.
|
||||
|
||||
@@ -122,7 +121,7 @@ You can use remote packages in the same way that we use local packages.
|
||||
```Go
|
||||
import "github.com/astaxie/beedb"
|
||||
```
|
||||
## Directory complete structure
|
||||
## ساختار کامل دایرکتوری
|
||||
|
||||
If you've followed all of the above steps, your directory structure should now look like the following.
|
||||
|
||||
@@ -149,8 +148,8 @@ Now you are able to see the directory structure clearly; `bin` contains executab
|
||||
|
||||
(The format of environment variables in Windows is `%GOPATH%`, however this book mainly follows the Unix-style, so Windows users need to replace these yourself.)
|
||||
|
||||
## Links
|
||||
## لینکها
|
||||
|
||||
- [Directory](preface.md)
|
||||
- Previous section: [Installation](01.1.md)
|
||||
- Next section: [Go commands](01.3.md)
|
||||
- [فهرست مطالب](preface.md)
|
||||
- بخش قبلی: [نصب](01.1.md)
|
||||
- بخش بعدی: [دستورات Go](01.3.md)
|
||||
|
||||
Reference in New Issue
Block a user