Add German translation for chapter 1

This commit is contained in:
digitalcraftsman
2015-06-24 13:02:34 +02:00
parent 9a58a97375
commit 69213a0d5a
6 changed files with 297 additions and 285 deletions

View File

@@ -1,39 +1,40 @@
#1.2 $GOPATH and workspace
#1.2 $GOPATH und Workspaces
## $GOPATH
Go commands all rely on one important environment variable called $GOPATH. Notice that this is not the $GOROOT variable where Go is installed. This variable points to the workspace of Go on your computer (I use this path on my computer; if you don't have the same directory structure, please replace by yourself).
Alle Go-Befehle bauen auf einer wichtigen Umgebungsvariable mit dem Namen $GOPATH. Bedenke, dass es sich nicht um $GOROOT, also den Installationspfad von Go, handelt. Diese Variable verweist vielmehr auf den Go Workspace auf Deinem Computer (Ich benutze den unten stehenden Pfad auf meinem Computer; solltest Du eine andere Ordnerstruktur haben, musst Du den Pfad anpassen).
In UNIX-ähnlichen System sollte die Variable dieser ähnlich sein:
In Unix-like systems, the variable should be used like this:
export GOPATH=/home/apple/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*** )
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.
In Windows musst Du eine neue Umgebungsvariable mit dem Namen $GOPATH erstellen und ihren Wert auf `C:\mygo`( ***Dieser Wert ist abhängig von dem Pfad Deines Workspaces*** ) setzen.
In $GOPATH, you must have three folders as follows.
Es ist in Ordnung, mehr als einen Pfad (bzw. Workspace) im $GOPATH zu speichern, aber bedenke, dass Du die Pfade mit `:` (oder `;` unter Windows) von einander trennen musst. `go get` wird Pakete stets unter dem ersten, angegebenen Workspace speichern.
- `src` for source files whose suffix is .go, .c, .g, .s.
- `pkg` for compiled files whose suffix is .a.
- `bin` for executable files
IM $GOPATH müssen die drei bestimmte Verzeichnisse vorhanden sein:
In this book, I use `mygo` as my only path in $GOPATH.
- `src` für Quellcode mit der Dateiendung .go, .c, .g, .s.
- `pkg` für kompilierte Dateien mit der Dateiendung .a.
- `bin` für ausführbare Dateien
## 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 same name for the folder where contains package source files***)
In diesem Buch ist `mygo` mein einziger Pfad in $GOPATH.
Every time you create a package, you should create a new folder in the `src` directory. Folder names are usually the same as the package that you are going to use. You can have multi-level directories if you want to. For example, if you create the directory `$GOPATH/src/github.com/astaxie/beedb`, then the package path would be `github.com/astaxie/beedb`. The package name will be the last directory in your path, which is `beedb` in this case.
## Paketverzeichnis
Execute following commands. ( ***Now author goes back to talk examples*** )
Erstelle Quellcodedateien und Ordner wie `$GOPATH/src/mymath/sqrt.go` (`mymath` ist der Paketname) ( ***Der Autor nutzt `mymath` als Paketnamen und gibt den Verzeichnissen, welche die Quellcodedateien beinhalten, den selben Namen***).
Jedes Mal, wenn Du ein neues Paket erstellt, solltest Du einen neuen Ordner im `src` Verzeichnis erstellen. Diese Ordner haben überlicherweise den selben Namen, wie das Paket, welches Du nutzen möchtest. Die Verzeichnisse können zudem beliebig verschachtelt werden. Erstellst Du beispielsweise das Verzeichnis `$GOPATH/src/github.com/astaxie/beedb`, dann wäre das entsprechende Paket `github.com/astaxie/beedb`. Das Paket ist immer das letzte Verzeichnis im Pfad, in diesem Fall `beedb`.
Führe die Folgenden Befehle aus. ( ***Nun widmet sich der Autor wieder den praktischen Dingen.*** )
cd $GOPATH/src
mkdir mymath
Create a new file called `sqrt.go`, type following content to your file.
Erstelle eine neue Datei mit dem Namen `sqrt.go`, die folgendes beinhalten soll.
// Source code of $GOPATH/src/mymath/sqrt.go
// Quellcode von $GOPATH/src/mymath/sqrt.go
package mymath
func Sqrt(x float64) float64 {
@@ -44,35 +45,36 @@ Create a new file called `sqrt.go`, type following content to your file.
return z
}
Now my package directory has been created and its 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.
Nun haben wir das Paketverzeichnis und den dazugehörigen Quellcode. Ich empfehle Dir, alle Paketverzeichnisse nach dem Paket selbst zu benennen und den gesamten, dazugehörigen Quellcode dort zu speichern.
## Compile packages
## Pakete kompilieren
We've already created our package above, but how do we compile it for practical purposes? There are two ways to do this.
Oben haben wir bereits unser Paket erstellt, aber wie kompilieren wir es, um es nutzen zu können? Dafür gibt es zwei Wege.
1. Switch your work path to the directory of your package, then execute the `go install` command.
2. Execute the above command except with a file name, like `go install mymath`.
1. Navigiere im Terminal zum Paketverzeichnis und führe den `go install` Befehl aus.
2. Führe den oberen Befehl aus, diesmal jedoch mit einem Dateinamen wie `go install mymath`.
After compiling, we can open the following folder.
Nach der Kompilierung können wir den folgenden Ordner öffnen.
cd $GOPATH/pkg/${GOOS}_${GOARCH}
// you can see the file was generated
// Wie Du siehst, wurde eine neue Datei erstellt
mymath.a
The file whose suffix is `.a` is the binary file of our package. How do we use it?
Die Datei mit der Endung `.a` ist die Binärdatei unseres Pakets. Aber wie nutzen wie diese nun?
Obviously, we need to create a new application to use it.
Logischerweise müssen wir dafür eine neue Anwendung schreiben, um das Paket zu nutzen.
Create a new application package called `mathapp`.
Erstelle ein neues Paket für die Anwendung mit dem Namen `mathapp`.
cd $GOPATH/src
mkdir mathapp
cd mathapp
vim main.go
code
Und der Code:
//$GOPATH/src/mathapp/main.go source code.
// Quellcode von $GOPATH/src/mathapp/main.go
package main
import (
@@ -81,24 +83,24 @@ code
)
func main() {
fmt.Printf("Hello, world. Sqrt(2) = %v\n", mymath.Sqrt(2))
fmt.Printf("Hallo, Welt. Sqrt(2) = %v\n", mymath.Sqrt(2))
}
To compile this application, you need to switch to the application directory, which in this case is `$GOPATH/src/mathapp`, then execute the `go install` command. Now you should see an executable file called `mathapp` was generated in the directory `$GOPATH/bin/`. To run this program, use the `./mathapp` command. You should see the following content in your terminal.
Um die Anwendung zu kompilieren, müssen wir zurück in das Verzeichnis, in welchem die Anwendung liegt; in diesem diesem Falle unter `$GOPATH/src/mathapp`. Führe nun den Befehl `go install` aus. Nun solltest Du eine neue ausführbare Datei mit dem Namen `mathapp` im Verzeichnis `$GOPATH/bin/` vorfinden. Um das Programm auszuführen, tippe den Befehl `./mathapp` ein. Im Terminal solltest Du nun den unteren Text lesen können.
Hello world. Sqrt(2) = 1.414213562373095
Hallo, Welt. Sqrt(2) = 1.414213562373095
## Install remote packages
## Installation von Paketen Dritter (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.
Go umfasst ein Werkzeug zum Installieren von Remote Packages, also Paketen die von anderen Programmierern erstellt wurden. Mit dem Befehl `go get` kannst Du diese für die eigene Nutzung installieren. Es unterstützt die meisten Open Source Communities wie Github, Google Code, Bitbucket und Launchpad.
go get github.com/astaxie/beedb
You can use `go get -u …` to update your remote packages and it will automatically install all the dependent packages as well.
Du kannst `go get -u …` nutzen, um ein Remote Package zu aktualisieren. Zugleich werden auch alle benötigten Abhängigkeiten mit installiert.
This tool will use different version control tools for different open source platforms. For example, `git` for Github and `hg` for Google Code. Therefore, you have to install these version control tools before you use `go get`.
Dieser Befehl nutzt verschiedene Versionskontrollsysteme für die verschiedenen Open Source Plattformen. So wird beispielsweise `git` für Github und `hg` für Google Code verwendet. Daher musst Du zuerst die entsprechenden Versionskontrollsysteme installieren, ehe Du `go get` nutzen kannst.
After executing the above commands, the directory structure should look like following.
Nach dem Ausführen der oben gezeigten Befehle, sollte die Orderstruktur etwa so aussehen.
$GOPATH
src
@@ -111,15 +113,15 @@ After executing the above commands, the directory structure should look like fol
|-astaxie
|-beedb.a
Actually, `go get` clones source code to the $GOPATH/src of the local file system, then executes `go install`.
Im Hintergrund "klont" `go get` den Quellcode nach $GOPATH/src auf deinem Computer und nutzt dann `go install` zur Installation der Remote Packages.
You can use remote packages in the same way that we use local packages.
Du kannst Remote Packages wie lokale Pakete nutzen.
import "github.com/astaxie/beedb"
## Directory complete structure
## Die komplette Verzeichnisstruktur
If you've followed all of the above steps, your directory structure should now look like the following.
Wenn Du alle Schritte befolgt hast, sollte Deine Verzeichnisstruktur wie folgt aussehen.
bin/
mathapp
@@ -140,12 +142,12 @@ If you've followed all of the above steps, your directory structure should now l
beedb.go
util.go
Now you are able to see the directory structure clearly; `bin` contains executable files, `pkg` contains compiled files and `src` contains package source files.
Nun kannst Du die Ordnerstruktur klar erkennen. `bin` beinhaltet alle ausführbaren Dateien, `pkg` alle compilierten Dateien und `src` den Quellcode der Pakete.
(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.)
(Das Format von Umgebungsvariable unter Windows ist `%GOPATH%`. Da dieses Buch sich jedoch am UNIX-Stil orientiert, müssen Windowsnutzer das Format von Hand ändern.)
## Links
- [Directory](preface.md)
- Previous section: [Installation](01.1.md)
- Next section: [Go commands](01.3.md)
- [Inhaltsverzeichnis](preface.md)
- Vorheriger Abschnitt: [Installation](01.1.md)
- Nächster Abschnitt: [Go Befehle](01.3.md)