diff options
| author | Shulhan <m.shulhan@gmail.com> | 2023-11-12 12:47:29 +0700 |
|---|---|---|
| committer | Shulhan <m.shulhan@gmail.com> | 2023-11-12 12:47:29 +0700 |
| commit | 12b6da0d8501baad59466294679c7f39653ecd17 (patch) | |
| tree | b4817c9936849fcd51b83a235e8daddda2cf0dbd | |
| parent | f889527e328c83411ed2562f06f8bb9cd120f2f3 (diff) | |
| parent | 3891a3eb15c053bf644848461c84facbfe1cfb34 (diff) | |
| download | golang-id-tour-12b6da0d8501baad59466294679c7f39653ecd17.tar.xz | |
Merge commit '3891a3eb15c0'
Merge commit dari upstream sebelum semua berkas dihapus karena digabung
dengan golang.org/x/website di commit 241d4738f53e9d
| -rw-r--r-- | CONTRIBUTING.md | 16 | ||||
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | app.yaml | 10 | ||||
| -rw-r--r-- | content/concurrency.article | 4 | ||||
| -rw-r--r-- | content/welcome.article | 16 | ||||
| -rw-r--r-- | go.mod | 5 | ||||
| -rw-r--r-- | go.sum | 2 | ||||
| -rw-r--r-- | local.go | 76 | ||||
| -rw-r--r-- | pic/pic.go | 30 | ||||
| -rw-r--r-- | pic/pic_test.go | 26 | ||||
| -rw-r--r-- | static/js/services.js | 23 | ||||
| -rw-r--r-- | tour.go | 11 |
12 files changed, 132 insertions, 92 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9b377e8..fc23135 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,21 +22,7 @@ The gophers there will answer or ask you to file an issue if you've tripped over In order to verify changes to the slides or code examples while developing locally compile with your local toolchain: - $ go install golang.org/x/tour/gotour - $ $GOPATH/bin/gotour - -## Running the App Engine version locally - -To view the App Engine version of the slides while developing locally, install -the [Go App Engine SDK](https://cloud.google.com/appengine/downloads?hl=en) -and then: - - $ cd $GOPATH/src/golang.org/x/tour - $ $SDK_PATH/dev_appserver.py . - -The App Engine version runs code examples against the service at play.golang.org. -To verify changes to the code examples you must use your local toolchain to compile -and run `gotour` locally. + $ go run golang.org/x/tour ## Contributing code @@ -1,6 +1,9 @@ # Go Tour -Tur Bahasa Pemrograman Go adalah sebuah pengenalan dari bahasa pemrograman Go. +[](https://pkg.go.dev/github.com/golang-id/tour) + +Tur Bahasa Pemrograman Go adalah sebuah situs pengenalan untuk bahasa +pemrograman Go. Kunjungi situs https://tour.golang-id.org untuk memulai tur. ## Unduh/Pasang @@ -2,7 +2,6 @@ service: default runtime: go118 env_variables: - GOLANGORG_CHECK_COUNTRY: true TOUR_ANALYTICS: | <script async src="https://www.googletagmanager.com/gtag/js?id=UA-2502278-11"></script> <script> @@ -14,9 +13,10 @@ env_variables: default_expiration: "7d" +handlers: + # Keep these static file handlers in sync with local.go. # They're here for improved latency across global regions. -handlers: - url: /favicon.ico static_files: static/img/favicon.ico upload: static/img/favicon.ico @@ -27,3 +27,9 @@ handlers: - url: /static static_dir: static secure: always + +# This is here to redirect all HTTP traffic to an HTTPS URL +# with the same path. +- url: /.* + script: auto + secure: always diff --git a/content/concurrency.article b/content/concurrency.article index e5700d0..5aba00e 100644 --- a/content/concurrency.article +++ b/content/concurrency.article @@ -227,9 +227,7 @@ konkuren! #appengine: melanjutkan. Dokumentasi tersebut berisi referensi, tutorial, video, dan banyak lagi. -Untuk belajar cara mengorganisir dan bekerja dengan kode Go, lihat -[[https://www.youtube.com/watch?v=XCsL89YtqCs][siaran berikut]] -atau baca +Untuk belajar cara mengorganisir dan bekerja dengan kode Go, bacalah [[https://golang.org/doc/code.html][Cara Menulis Kode Go]]. Jika anda membutuhkan bantuan dengan pustaka Go, lihat diff --git a/content/welcome.article b/content/welcome.article index 76b43e0..4646ead 100644 --- a/content/welcome.article +++ b/content/welcome.article @@ -58,25 +58,17 @@ di bawah atau tekan `PageDown`. Tur ini tersedia dalam beberapa bahasa: -- [[https://go-tour-ar.appspot.com/][Arabic — العربية]] - [[https://go-tour-br.appspot.com/][Brazilian Portuguese — Português do Brasil]] - [[https://go-tour-ca.appspot.com/][Catalan — Català]] - [[https://tour.go-zh.org/][Simplified Chinese — 中文(简体)]] -- [[https://go-tour-zh-tw.appspot.com/][Traditional Chinese — 中文(繁體)]] - [[https://go-tour-cz.appspot.com/][Czech — Česky]] - [[https://tour.golang.org/][English - English]] - [[https://go-tour-fr.appspot.com/][French — Français]] -- [[https://go-tour-de.appspot.com/][German — Deutsch]] -- [[https://go-tour-he.appspot.com/][Hebrew — עִבְרִית]] -- [[https://go-tour-ita.appspot.com/][Italian — Italiano]] +- [[https://go-tour-id2.appspot.com/][Indonesian — Bahasa Indonesia]] - [[https://go-tour-jp.appspot.com/][Japanese — 日本語]] -- [[https://go-tour-kr.appspot.com/][Korean — 한국어]] -- [[https://go-tour-ro.appspot.com/][Romanian — Română]] -- [[https://go-tour-ru-ru.appspot.com/][Russian - Русский]] -- [[https://gotour-es.appspot.com/][Spanish — Español]] -- [[https://go-tour-th.appspot.com/][Thai - ภาษาไทย]] -- [[https://go-tour-turkish.appspot.com/][Turkish - Türkçe]] -- [[https://go-tour-ua.appspot.com/][Ukrainian — Українська]] +- [[https://go-tour-ko.appspot.com/][Korean — 한국어]] +- [[https://go-tour-pl1.appspot.com/][Polish — Polski]] +- [[https://go-tour-th.appspot.com/][Thai — ภาษาไทย]] - [[https://go-tour-uz.appspot.com/][Uzbek — Ўзбекча]] Klik tombol @@ -2,7 +2,10 @@ module github.com/golang-id/tour go 1.18 -require golang.org/x/tools v0.6.0 +require ( + golang.org/x/tools v0.6.0 + golang.org/x/tour v0.1.0 +) require ( github.com/yuin/goldmark v1.5.4 // indirect @@ -8,3 +8,5 @@ golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tour v0.1.0 h1:OWzbINRoGf1wwBhKdFDpYwM88NM0d1SL/Nj6PagS6YE= +golang.org/x/tour v0.1.0/go.mod h1:DUZC6G8mR1AXgXy73r8qt/G5RsefKIlSj6jBMc8b9Wc= @@ -5,8 +5,8 @@ package main import ( + "encoding/json" "flag" - "fmt" "go/build" "html/template" "io" @@ -18,6 +18,7 @@ import ( "os/exec" "path/filepath" "runtime" + "runtime/debug" "strings" "time" @@ -40,9 +41,6 @@ var ( ) var ( - // GOPATH containing the tour packages - gopath = os.Getenv("GOPATH") - httpAddr string ) @@ -56,20 +54,41 @@ func isRoot(path string) bool { return err == nil } -func findRoot() (string, error) { - ctx := build.Default - p, err := ctx.Import(basePkg, "", build.FindOnly) +// findRoot is a best-effort attempt to find a tour directory +// that contains the files it needs. It may not always work. +// +// TODO: Delete after Go 1.17 is out and we can just use embed; see CL 291849. +func findRoot() (string, bool) { + // Try finding the golang.org/x/tour package in the + // legacy GOPATH mode workspace or in build list. + p, err := build.Import(basePkg, "", build.FindOnly) if err == nil && isRoot(p.Dir) { - return p.Dir, nil + return p.Dir, true } - tourRoot := filepath.Join(runtime.GOROOT(), "misc", "tour") - ctx.GOPATH = tourRoot - p, err = ctx.Import(basePkg, "", build.FindOnly) - if err == nil && isRoot(tourRoot) { - gopath = tourRoot - return tourRoot, nil + // If that didn't work, perhaps we're not inside any module + // and the binary was built in module mode (e.g., 'go install + // golang.org/x/tour@latest' or 'go get golang.org/x/tour' + // outside a module). + // In that's the case, find out what version it is, + // and access its content from the module cache. + if info, ok := debug.ReadBuildInfo(); ok && + info.Main.Path == basePkg && + info.Main.Replace == nil && + info.Main.Version != "(devel)" { + // Make some assumptions for brevity: + // • the 'go' binary is in $PATH + // • the main module isn't replaced + // • the version isn't "(devel)" + // They should hold for the use cases we care about, until this + // entire mechanism is obsoleted by file embedding. + out, execError := exec.Command("go", "mod", "download", "-json", "--", basePkg+`@`+info.Main.Version).Output() + var tourRoot struct{ Dir string } + jsonError := json.Unmarshal(out, &tourRoot) + if execError == nil && jsonError == nil && isRoot(tourRoot.Dir) { + return tourRoot.Dir, true + } } - return "", fmt.Errorf("could not find go-tour content; check $GOROOT and $GOPATH") + return "", false } func main() { @@ -82,9 +101,9 @@ func main() { } // find and serve the go tour files - root, err := findRoot() - if err != nil { - log.Fatalf("Couldn't find tour files: %v", err) + root, ok := findRoot() + if !ok { + log.Fatalln("Couldn't find files for the Go tour. Try reinstalling it.") } log.Println("Serving content from", root) @@ -166,27 +185,6 @@ If you don't understand this message, hit Control-C to terminate this process. WARNING! WARNING! WARNING! ` -type response struct { - Output string `json:"output"` - Errors string `json:"compile_errors"` -} - -func init() { - socket.Environ = environ -} - -// environ returns the original execution environment with GOPATH -// replaced (or added) with the value of the global var gopath. -func environ() (env []string) { - for _, v := range os.Environ() { - if !strings.HasPrefix(v, "GOPATH=") { - env = append(env, v) - } - } - env = append(env, "GOPATH="+gopath) - return -} - // waitServer waits some time for the http Server to start // serving url. The return value reports whether it starts. func waitServer(url string) bool { @@ -1,18 +1,27 @@ -// Copyright 2011 The Go Authors. All rights reserved. +// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package pic mengimplementasikan fungsi untuk menampilkan gambar di +// Go Playground. package pic // import "github.com/golang-id/tour/pic" import ( - "bytes" + "bufio" "encoding/base64" - "fmt" "image" "image/png" + "io" + "os" ) -func Show(f func(int, int) [][]uint8) { +// Show menampilkan gambar dari fungsi f saat di eksekusi di Go Playground. +// +// f mengembalikan sebuah slice dengan panjang dy, setiap elemen dari slice +// tersebut adalah sebuah slice dx, 8-bit unsigned int. +// Nilai integer diinterpretasikan sebagai nilai rentang warna biru, yang +// mana nilai 0 berarti biru, dan 255 berwarna putih. +func Show(f func(dx, dy int) [][]uint8) { const ( dx = 256 dy = 256 @@ -32,12 +41,17 @@ func Show(f func(int, int) [][]uint8) { ShowImage(m) } +// ShowImage displays the image m +// when executed on the Go Playground. func ShowImage(m image.Image) { - var buf bytes.Buffer - err := png.Encode(&buf, m) + w := bufio.NewWriter(os.Stdout) + defer w.Flush() + io.WriteString(w, "IMAGE:") + b64 := base64.NewEncoder(base64.StdEncoding, w) + err := (&png.Encoder{CompressionLevel: png.BestCompression}).Encode(b64, m) if err != nil { panic(err) } - enc := base64.StdEncoding.EncodeToString(buf.Bytes()) - fmt.Println("IMAGE:" + enc) + b64.Close() + io.WriteString(w, "\n") } diff --git a/pic/pic_test.go b/pic/pic_test.go new file mode 100644 index 0000000..0e8ccf5 --- /dev/null +++ b/pic/pic_test.go @@ -0,0 +1,26 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package pic_test + +import "golang.org/x/tour/pic" + +func ExampleShow() { + f := func(dx, dy int) [][]uint8 { + ss := make([][]uint8, dy) + for y := 0; y < dy; y++ { + s := make([]uint8, dx) + for x := 0; x < dx; x++ { + s[x] = uint8((x + y) / 2) + } + ss[y] = s + } + return ss + } + + pic.Show(f) + + // Output: + // IMAGE:iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAACaUlEQVR42uzVMRGAAAzAwLSHf8tgAAf95QVkyVNvNRN50FWBl10V6ABa0AFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIB6ADqEAHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdAA6gBZ0ANIBSAcgHYB0ANIBSAcgHYB0ANIBSAcgHYB0ANIBSAcgHYB0ANIBSAcgHYB0ANIBSAcgHYB0ANIBSAcgHYB0ANIBSAcgHYB0ANIBSAcgHYB0ANIBSAcgHYB0ANIBSAcgHYB0ANIBSAcgHYB0ANIB6AAq0AFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgHQA0gFIByAdgA6gAh2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADSAUgHIB2AdADyxy8AAP//YSoDD5pLB7MAAAAASUVORK5CYII= +} diff --git a/static/js/services.js b/static/js/services.js index dd4563f..da5f79c 100644 --- a/static/js/services.js +++ b/static/js/services.js @@ -49,6 +49,29 @@ factory('run', ['$window', 'editor', }; }; return function(code, output, options, done) { + // We want to build tour snippets in module mode, so append + // a default go.mod file when it is not already included in + // the txtar archive. + // + // The exercises use golang.org/x/tour/{pic,reader,tree,wc} + // packages, so include the golang.org/x/tour module in the + // build list. + const hasGoMod = code.indexOf('\n-- go.mod --\n') !== -1 || code.startsWith('-- go.mod --\n'); + if (!hasGoMod) { + code += '\n' + + '-- go.mod --\n' + + 'module example\n' + + 'require golang.org/x/tour v0.0.0-20201207214521-004403599411\n' + + '-- go.sum --\n' + + 'golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=\n' + + 'golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=\n' + + 'golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=\n' + + 'golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=\n' + + 'golang.org/x/tools v0.0.0-20190312164927-7b79afddac43/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=\n' + + 'golang.org/x/tour v0.0.0-20201207214521-004403599411 h1:dJ4kVwSGlrLZXW6eo2IOer4Pm3wl2GIG4fytRziMgL8=\n' + + 'golang.org/x/tour v0.0.0-20201207214521-004403599411/go.mod h1:qMugOFWX59KzC8Nx7f2uvXxKxAqJfi1J6ZUHAWKnrRA=\n'; + } + // PlaygroundOutput is defined in playground.js which is prepended // to the generated script.js in gotour/tour.go. // The next line removes the jshint warning. @@ -223,17 +223,6 @@ func renderUI(w io.Writer) error { return err } -// nocode returns true if the provided Section contains -// no Code elements with Play enabled. -func nocode(s present.Section) bool { - for _, e := range s.Elem { - if c, ok := e.(present.Code); ok && c.Play { - return false - } - } - return true -} - // initScript concatenates all the javascript files needed to render // the tour UI and serves the result on /script.js. func initScript(root string) error { |
