Add German translation for chapter 1
This commit is contained in:
105
de/01.3.md
105
de/01.3.md
@@ -1,106 +1,109 @@
|
||||
#1.3 Go commands
|
||||
#1.3 Go Befehle
|
||||
|
||||
## Go commands
|
||||
## Go Befehle
|
||||
|
||||
The Go language comes with a complete set of command operation tools. You can execute the command line `go` to see them:
|
||||
Die Programmiersprache Go bringt viele nützliche Befehle für diverse Anwendungszwecke mit sich. Du erhälst eine Übersicht, indem Du `go` im Terminal ausführst.
|
||||
|
||||

|
||||
|
||||
Figure 1.3 Go command displays detailed information
|
||||
Figure 1.3 Eine detaillierte Übersicht aller Go Befehle
|
||||
|
||||
These are all useful for us. Let's see how to use some of them.
|
||||
Jeder Befehl kann nützlich für uns sein. Betrachten wir den Anwendungszweck von ein paar Befehlen.
|
||||
|
||||
## go build
|
||||
|
||||
This command is for compiling tests. It will compile dependence packages if it's necessary.
|
||||
Dieser Befehl ist für die Kompilierung und das Testen des Quellcodes verantwortlich. Abhängige Pakete werden ebenfalls mit kompiliert, sofern dies nötig ist.
|
||||
|
||||
- If the package is not the `main` package such as `mymath` in section 1.2, nothing will be generated after you execute `go build`. If you need package file `.a` in `$GOPATH/pkg`, use `go install` instead.
|
||||
- If the package is the `main` package, it will generate an executable file in the same folder. If you want the file to be generated in `$GOPATH/bin`, use `go install` or `go build -o ${PATH_HERE}/a.exe.`
|
||||
- If there are many files in the folder, but you just want to compile one of them, you should append the file name after `go build`. For example, `go build a.go`. `go build` will compile all the files in the folder.
|
||||
- You can also assign the name of the file that will be generated. For instance, in the `mathapp` project (in section 1.2), using `go build -o astaxie.exe` will generate `astaxie.exe` instead of `mathapp.exe`. The default name is your folder name (non-main package) or the first source file name (main package).
|
||||
- Wenn das Paket nicht `main` entspricht, wie unser `mymath` Paket aus Abschnitt 1.2 nicht ausgeführt, nachdem Du `go build` ausgeführt hast. Solltest Du Paket-Dateien mit der Endung `.a` in `$GOPATH/pkg`, nutze stattdessen `go install`.
|
||||
- Sollte das Paket `main` entsprechen, dann wird eine ausführbare Binärdatei im selben Verzeichnis generiert. Möchtest Du stattdessen, dass Die Binärdatei in `$GOPATH/bin` generiert wird, nutze den Befehl `go install` oder `go build -o ${PATH_HERE}/a.exe.`.
|
||||
- Befinden sich viele Dateien in einem Ordner, aber Du möchtest nur eine bestimmte Datei kompilieren, dann füge den Dateinamen am Ende von `go build` hinzu. Ein Beispiel wäre `go build a.go`. `go build` wird alle Dateien im selben Ordner kompilieren.
|
||||
- Du kannst alternativ auch den Namen der ausführbaren Binärdatei ändern. So erhält das `mathapp` Projekt (aus Abschnitt 1.2) mit dem Befehl `go build -o astaxie.exe` den Namen `astaxie.exe`, statt `mathapp.exe`. Der Standardname ist immer der Verzeichnisname (sofern es kein `main` Paket ist) oder der Name der ersten, ausführbaren Datei (`main` Paket).
|
||||
|
||||
(According to [The Go Programming Language Specification](https://golang.org/ref/spec), package names should be the name after the word `package` in the first line of your source files. It doesn't have to be the same as the folder name, and the executable file name will be your folder name by default.])
|
||||
Laut den [Spezifikationen der Go Programmiersprache](https://golang.org/ref/spec) sollten Pakete den Namen tragen, der nach dem Schlüsselwort `package` in der ersten Zeile einer Quellcodedatei steht. Dieser muss nicht gleich dem Verzeichnisnamen sein und die ausführbare Binärdatei wird standardmäßig den Verzeichnisnamen annehmen.
|
||||
|
||||
- `go build` ignores files whose names start with `_` or `.`.
|
||||
- If you want to have different source files for every operating system, you can name files with the system name as a suffix. Suppose there are some source files for loading arrays. They could be named as follows:
|
||||
- `go build` ignoriert Dateien, die mit `_` oder `.` beginnen.
|
||||
- Möchtest Du für jedes Betriebssystem andere Quellcodedateien erstellen, dann kannst Du den Systemnamen als Suffix im Dateinamen verwenden. Stell Dir vor, Du hast Quellcodedateien zum Laden von Arrays. Sie könnten nach dem folgenden Schema benannt sein:
|
||||
|
||||
array_linux.go | array_darwin.go | array_windows.go | array_freebsd.go
|
||||
|
||||
`go build` chooses the one that's associated with your operating system. For example, it only compiles array_linux.go in Linux systems, and ignores all the others.
|
||||
`go build` wählt als Suffix den Namen, der mit Deinem Betriebssystem assoziiert ist. So wird einzig `array_linux.go` auf Linux-Systemen kompiliert. Alle anderen Dateien werden ignoriert.
|
||||
|
||||
## go clean
|
||||
|
||||
This command is for cleaning files that are generated by compilers, including the following files:
|
||||
Dieser Befehl löscht alle Dateien, die vom Kompiler generiert wurden, einschließlich der unten gelisteten Dateien und Verzeichnisse.
|
||||
|
||||
_obj/ // old directory of object, left by Makefiles
|
||||
_test/ // old directory of test, left by Makefiles
|
||||
_testmain.go // old directory of gotest, left by Makefiles
|
||||
test.out // old directory of test, left by Makefiles
|
||||
build.out // old directory of test, left by Makefiles
|
||||
*.[568ao] // object files, left by Makefiles
|
||||
_obj/ // Altes Verzeichnis von object, als Überreste von Makefiles
|
||||
_test/ // Altes Verzeichnis von test, als Überreste von Makefiles
|
||||
_testmain.go // Altes Verzeichnis von gotest, als Überreste von Makefiles
|
||||
test.out // Altes Verzeichnis von test, als Überreste von Makefiles
|
||||
build.out // Altes Verzeichnis von test, als Überreste von Makefiles
|
||||
*.[568ao] // object Dateien, als Überreste von Makefiles
|
||||
|
||||
DIR(.exe) // generated by go build
|
||||
DIR.test(.exe) // generated by go test -c
|
||||
MAINFILE(.exe) // generated by go build MAINFILE.go
|
||||
|
||||
I usually use this command to clean up my files before I upload my project to Github. These are useful for local tests, but useless for version control.
|
||||
DIR(.exe) // Generiert von go build
|
||||
DIR.test(.exe) // Generiert von go test -c
|
||||
MAINFILE(.exe) // Generiert von go build MAINFILE.go
|
||||
|
||||
## go fmt and gofmt
|
||||
Überlicherweise nutze ich diese Befehle zum Säubern von Projekten, bevor ich diese auf Github hochlade. Sie sind nützlich für lokale Tests, aber nutzlos zur Versionskontrolle.
|
||||
|
||||
The people who are working with C/C++ should know that people are always arguing about which code style is better: K&R-style or ANSI-style. However in Go, there is only one code style which is enforced. For example, left braces must only be inserted at the end of lines, and they cannot be on their own lines, otherwise you will get compile errors! Fortunately, you don't have to remember these rules. `go fmt` does this job for you. Just execute the command `go fmt <File name>.go` in terminal. I don't use this command very much because IDEs usually execute this command automatically when you save source files. I will talk about IDEs more in the next section.
|
||||
## go fmt und gofmt
|
||||
|
||||
`go fmt` is just an alias, which runs the command 'gofmt -l -w' on the packages named by the import paths.
|
||||
Programmierer, die mit C/C++ arbeiten, sollten wissen, das Personen immer darüber debattieren, welcher Code-Stil besser sei: K&R-Stil oder ANSI-Stil. In Go gibt nur einen einzigen, welcher vorrausgesetzt wird. So müssen zum Beispiel offene, geschwungene Schleifen nur am Ende von Zeilen eingefügt werden und können nicht in einer eigenen stehen, da dies einen Kompilierungsfehler zur Folge hat! Jedoch musst Du Dir diese Regeln nicht merken. `go fmt` übernimmt diese Aufgabe für Dich. Führe einfach den Befehl `go fmt <Dateiname>.go` im Terminal aus. Persönlich nutze ich diesen Befehl selten, da die meisten IDEs diesen Befehl meist automatisch ausführen, sobald ich eine Datei speichere. Im nächsten Abschnitt werde ich näher auf IDEs eingehen.
|
||||
|
||||
We usually use `gofmt -w` instead of `go fmt`. The latter will not rewrite your source files after formatting code. `gofmt -w src` formats the whole project.
|
||||
|
||||
`go fmt` ist nur ein Alias, welcher den Befehl `gofmt -l -w` bei Paketen anwendet, die in den Importpfaden genannt werden.
|
||||
|
||||
Wir nutzen üblicherweise `gofmt -w` statt `go fmt`. Somit wird Deine Quellcodedatei nicht umgeschrieben, nachdem sie formatiert wurde. `gofmt -w src` formatiert dagegen ein gesamtes Projekt.
|
||||
|
||||
## go get
|
||||
|
||||
This command is for getting remote packages. So far, it supports BitBucket, Github, Google Code and Launchpad. There are actually two things that happen after we execute this command. The first thing is that Go downloads the source code, then executes `go install`. Before you use this command, make sure you have installed all of the related tools.
|
||||
Dieser Befehl ermöglicht es, Remote Packages herunterzuladen. Bisher untersützt es Bitbucket, Github, Google Code und Launchpad. Es geschehen zwei Dinge, nachdem wir den Befehl ausgeführt haben. Als erstes lädt Go den Quellcode herunter und führt danach `go install` aus. Bevor Du `go get` nutzt, solltest Du vorher die benötigten Versionskontrollsysteme herunterladen.
|
||||
|
||||
BitBucket (Mercurial Git)
|
||||
Github (git)
|
||||
BitBucket (Mercurial und Git)
|
||||
Github (Git)
|
||||
Google Code (Git, Mercurial, Subversion)
|
||||
Launchpad (Bazaar)
|
||||
|
||||
In order to use this command, you have to install these tools correctly. Don't forget to set `$PATH`. By the way, it also supports customized domain names. Use `go help remote` for more details about this.
|
||||
|
||||
Um den Befehl auch nutzen zu können, musst Du diese Programme korrekt installieren. Vergiss nicht, `$PATH` zu setzen. Angemerkt sei, dass auch angepasste Domainnamen unterstützt werden. Nutze `go help remote`, um weitere Informationen zu erhalten.
|
||||
|
||||
## go install
|
||||
|
||||
This command compiles all packages and generates files, then moves them to `$GOPATH/pkg` or `$GOPATH/bin`.
|
||||
Dieser Befehl kompiliert alle Pakete und generiert Dateien, die entweder nach `$GOPATH/pkg` oder `$GOPATH/bin` verschoben werden.
|
||||
|
||||
## go test
|
||||
|
||||
This command loads all files whose name include `*_test.go` and generates test files, then prints information that looks like the following.
|
||||
Dieser Befehl läd alle Dateinen, dessen Name `*_test.go` beinhaltet, generiert Dateien für Tests und gibt anschließend dessen Ergebnisse aus, die wie folgt aussehen können:
|
||||
|
||||
ok archive/tar 0.011s
|
||||
FAIL archive/zip 0.022s
|
||||
ok compress/gzip 0.033s
|
||||
...
|
||||
|
||||
It tests all your test files by default. Use command `go help testflag` for more details.
|
||||
Es nutzt standardmäßig alle vorhanden Test-Dateien. Schaue unter `go help testflag` für Details.
|
||||
|
||||
## godoc
|
||||
|
||||
Many people say that we don't need any third-party documentation for programming in Go (actually I've made a [CHM](https://github.com/astaxie/godoc) already). Go has a powerful tool to manage documentation natively.
|
||||
Viele Personen sagen, man brauche kein Dokumentationswerkzeug von Dritten, wenn man Go nutzt (obwohl ich mit [CHM](https://github.com/astaxie/godoc) selbst eins schrieb). Go besitzt ein mächtiges Wergzeug, um Dokumentationen nativ zu verwalten.
|
||||
|
||||
So how do we look up package information in documentation? For instance, if you want to get more details about the `builtin` package, use the `godoc builtin` command. Similarly, use the `godoc net/http` command to look up the `http` package documentation. If you want to see more details about specific functions, use the `godoc fmt Printf` and `godoc -src fmt Printf` commands to view the source code.
|
||||
Aber wie können wir bestimmte Informationen über ein Paket einsehen? So möchtest Du zum Beispiel mehr über das `builtin` Paket wissen. Nutze hierfür `godoc builtin`. Mach es mit `godoc net/http` genauso, wenn Du mehr über das `http` Paket in Erfahrung bringen möchtest. Ist jedoch eine spezifische Funktion gefragt, benutze die `godoc fmt Printf` und `godoc -src fmt Printf` Befehle, um den Quellcode zu betrachten.
|
||||
|
||||
Execute the `godoc -http=:8080` command, then open `127.0.0.1:8080` in your browser. You should see a localized golang.org. It can not only show the standard packages' information, but also packages in your `$GOPATH/pkg`. It's great for people who are suffering from the Great Firewall of China.
|
||||
Führe den Befehl `godoc -http=:8080` aus und öffne dann `127.0.0.1:8080` in Deinem Browser. Nun solltest Du eine Deiner Sprache angepassten (lokalisierten) Version von golang.org sehen. So kannst Du nicht nur die Dokumentationen zu Paketen der Standardbibliothek ansehen, sondern auch aller Pakete, die unter `$GOPATH/pkg` gepspeichert sind. Dies ist großartig für Menschen, die von der Great Firewall of China im Internet eingeschränkt werden.
|
||||
|
||||
## Other commands
|
||||
## Andere Befehle
|
||||
|
||||
Go provides more commands than those we've just talked about.
|
||||
Go verfügt über noch mehr Befehle, die wir nicht behandelt haben.
|
||||
|
||||
go fix // upgrade code from an old version before go1 to a new version after go1
|
||||
go version // get information about your version of Go
|
||||
go env // view environment variables about Go
|
||||
go list // list all installed packages
|
||||
go run // compile temporary files and run the application
|
||||
|
||||
go fix // Überführt alten Go Code von Go1 oder niedriger in eine neuere Version
|
||||
go version // Erhalte nähere Informationen über Deine Go Version
|
||||
go env // Zeigt die alle Umgebungsvariablen von Go
|
||||
go list // Listed alle installierten Pakete
|
||||
go run // Kompiliert temporäre Dateien und führt diese aus
|
||||
|
||||
There are also more details about the commands that I've talked about. You can use `go help <command>` to look them up.
|
||||
Es gibt noch weitere Aspekte zu den Befehlen, über die ich nicht gesprochen habe. Du kannst `go help <command>` nutzen, um diese nachzulesen.
|
||||
|
||||
## Links
|
||||
|
||||
- [Directory](preface.md)
|
||||
- Previous section: [$GOPATH and workspace](01.2.md)
|
||||
- Next section: [Go development tools](01.4.md)
|
||||
- [Inhaltsverzeichnis](preface.md)
|
||||
- Vorheriger Abschnitt: [$GOPATH und Workspaces](01.2.md)
|
||||
- Nächster Abschnitt: [Go Entwicklungswerkzeuge](01.4.md)
|
||||
|
||||
Reference in New Issue
Block a user