├── codereview.cfg ├── .gitignore ├── content ├── img │ ├── tree.png │ └── newton.png ├── flowcontrol │ ├── forever.go │ ├── defer.go │ ├── for.go │ ├── for-continued.go │ ├── for-is-gos-while.go │ ├── exercise-loops-and-functions.go │ ├── defer-multi.go │ ├── if.go │ ├── if-with-a-short-statement.go │ ├── switch-with-no-condition.go │ ├── switch.go │ ├── if-and-else.go │ └── switch-evaluation-order.go ├── welcome │ ├── hello.go │ └── sandbox.go ├── basics │ ├── exported-names.go │ ├── type-inference.go │ ├── imports.go │ ├── packages.go │ ├── variables.go │ ├── functions.go │ ├── functions-continued.go │ ├── zero.go │ ├── named-results.go │ ├── variables-with-initializers.go │ ├── multiple-results.go │ ├── short-variable-declarations.go │ ├── type-conversions.go │ ├── constants.go │ ├── basic-types.go │ └── numeric-constants.go ├── moretypes │ ├── structs.go │ ├── slices.go │ ├── exercise-slices.go │ ├── nil-slices.go │ ├── range.go │ ├── struct-fields.go │ ├── struct-pointers.go │ ├── exercise-maps.go │ ├── slice-bounds.go │ ├── array.go │ ├── range-continued.go │ ├── map-literals-continued.go │ ├── maps.go │ ├── exercise-fibonacci-closure.go │ ├── map-literals.go │ ├── slices-pointers.go │ ├── function-closures.go │ ├── struct-literals.go │ ├── function-values.go │ ├── making-slices.go │ ├── mutating-maps.go │ ├── slice-literals.go │ ├── pointers.go │ ├── slice-len-cap.go │ ├── append.go │ └── slices-of-slice.go ├── methods │ ├── exercise-images.go │ ├── images.go │ ├── exercise-errors.go │ ├── exercise-reader.go │ ├── nil-interface-values.go │ ├── empty-interface.go │ ├── methods-funcs.go │ ├── methods.go │ ├── exercise-rot-reader.go │ ├── methods-continued.go │ ├── type-assertions.go │ ├── stringer.go │ ├── exercise-stringer.go │ ├── reader.go │ ├── type-switches.go │ ├── interfaces-are-satisfied-implicitly.go │ ├── methods-pointers.go │ ├── methods-pointers-explained.go │ ├── errors.go │ ├── indirection.go │ ├── indirection-values.go │ ├── interface-values-with-nil.go │ ├── methods-with-pointer-receivers.go │ ├── interface-values.go │ └── interfaces.go ├── concurrency │ ├── buffered-channels.go │ ├── goroutines.go │ ├── range-and-close.go │ ├── exercise-equivalent-binary-trees.go │ ├── channels.go │ ├── default-selection.go │ ├── select.go │ ├── mutex-counter.go │ └── exercise-web-crawler.go ├── content_test.go ├── flowcontrol.article ├── welcome.article ├── basics.article ├── concurrency.article └── moretypes.article ├── static ├── img │ ├── gopher.png │ └── favicon.ico ├── partials │ ├── lesson.html │ ├── toc-button.html │ ├── feedback-button.html │ ├── list.html │ ├── toc.html │ └── editor.html ├── lib │ └── codemirror │ │ ├── README.md │ │ ├── LICENSE │ │ ├── AUTHORS │ │ ├── lib │ │ └── codemirror.css │ │ └── mode │ │ └── go │ │ └── go.js ├── js │ ├── app.js │ ├── controllers.js │ ├── values.js │ ├── services.js │ └── directives.js └── css │ └── app.css ├── AUTHORS ├── CONTRIBUTORS ├── solutions ├── README ├── maps.go ├── fib.go ├── slices.go ├── loops.go ├── stringers.go ├── image.go ├── errors.go ├── http.go ├── rot13.go ├── binarytrees.go ├── binarytrees_quit.go └── webcrawler.go ├── README ├── app.yaml ├── reader └── validate.go ├── pic └── pic.go ├── tree └── tree.go ├── template ├── action.tmpl └── index.tmpl ├── tools ├── map.sh └── mapping.old ├── gotour ├── fmt.go ├── appengine.go ├── local.go └── tour.go ├── wc └── wc.go ├── TRANSLATE ├── LICENSE ├── CONTRIBUTING.md └── TODO /codereview.cfg: -------------------------------------------------------------------------------- 1 | issuerepo: golang/go 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | last-change 2 | *.orig 3 | *.rej 4 | -------------------------------------------------------------------------------- /content/img/tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang-tr/tour/HEAD/content/img/tree.png -------------------------------------------------------------------------------- /static/img/gopher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang-tr/tour/HEAD/static/img/gopher.png -------------------------------------------------------------------------------- /content/img/newton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang-tr/tour/HEAD/content/img/newton.png -------------------------------------------------------------------------------- /static/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang-tr/tour/HEAD/static/img/favicon.ico -------------------------------------------------------------------------------- /content/flowcontrol/forever.go: -------------------------------------------------------------------------------- 1 | // +build no-run OMIT 2 | 3 | package main 4 | 5 | func main() { 6 | for { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /content/welcome/hello.go: -------------------------------------------------------------------------------- 1 | // +build OMIT 2 | 3 | package main 4 | 5 | import "fmt" 6 | 7 | func main() { 8 | fmt.Println("Hello, 世界") 9 | } 10 | -------------------------------------------------------------------------------- /static/partials/lesson.html: -------------------------------------------------------------------------------- 1 |
{{description}}
4 |{{m.title}}
10 | 11 | 12 |{{m.lesson[l].Description}}
15 |{{range .Lines}}{{.}}{{end}}
22 | {{else}}
23 | 24 | {{range $i, $l := .Lines}}{{if $i}}{{template "newline"}} 25 | {{end}}{{style $l}}{{end}} 26 |
27 | {{end}} 28 | {{end}} 29 | 30 | {{define "code"}} 31 | {{if .Play}} 32 | {{/* playable code is not displayed in the slides */}} 33 | {{else}} 34 |' + text + ''); 72 | } 73 | 74 | function clearOutput() { 75 | $('.output.active').html(''); 76 | } 77 | 78 | function file() { 79 | return lessons[$scope.lessonId].Pages[$scope.curPage - 1].Files[$scope.curFile]; 80 | } 81 | 82 | $scope.run = function() { 83 | log('info', i18n.l('waiting')); 84 | var f = file(); 85 | $scope.job = run(f.Content, $('.output.active > pre')[0], { 86 | path: f.Name 87 | }, function() { 88 | $scope.job = null; 89 | $scope.$apply(); 90 | }); 91 | }; 92 | 93 | $scope.kill = function() { 94 | if ($scope.job !== null) $scope.job.Kill(); 95 | }; 96 | 97 | $scope.format = function() { 98 | log('info', i18n.l('waiting')); 99 | fmt(file().Content).then( 100 | function(data) { 101 | if (data.data.Error !== '') { 102 | log('stderr', data.data.Error); 103 | return; 104 | } 105 | clearOutput(); 106 | file().Content = data.data.Body; 107 | }, 108 | function(error) { 109 | log('stderr', error); 110 | }); 111 | }; 112 | 113 | $scope.reset = function() { 114 | file().Content = file().OrigContent; 115 | }; 116 | } 117 | ]); 118 | -------------------------------------------------------------------------------- /static/lib/codemirror/AUTHORS: -------------------------------------------------------------------------------- 1 | List of CodeMirror contributors. Updated before every release. 2 | 3 | 4r2r 4 | Aaron Brooks 5 | Adam King 6 | adanlobato 7 | Adán Lobato 8 | aeroson 9 | Ahmad Amireh 10 | Ahmad M. Zawawi 11 | ahoward 12 | Akeksandr Motsjonov 13 | Albert Xing 14 | Alexander Pavlov 15 | Alexander Schepanovski 16 | alexey-k 17 | Alex Piggott 18 | Amy 19 | Ananya Sen 20 | Andre von Houck 21 | Andrey Lushnikov 22 | Andy Kimball 23 | Andy Li 24 | angelozerr 25 | angelo.zerr@gmail.com 26 | Ankit Ahuja 27 | Ansel Santosa 28 | Anthony Grimes 29 | areos 30 | Atul Bhouraskar 31 | Aurelian Oancea 32 | Bastian Müller 33 | benbro 34 | Benjamin DeCoste 35 | Ben Keen 36 | boomyjee 37 | borawjm 38 | Brandon Frohs 39 | Brian Sletten 40 | Bruce Mitchener 41 | Chandra Sekhar Pydi 42 | Charles Skelton 43 | Chris Coyier 44 | Chris Granger 45 | Chris Morgan 46 | Christopher Brown 47 | CodeAnimal 48 | ComFreek 49 | dagsta 50 | Dan Heberden 51 | Daniel, Dao Quang Minh 52 | Daniel Faust 53 | Daniel Huigens 54 | Daniel Neel 55 | Daniel Parnell 56 | Danny Yoo 57 | David Mignot 58 | David Pathakjee 59 | deebugger 60 | Deep Thought 61 | Dominator008 62 | Domizio Demichelis 63 | Drew Bratcher 64 | Drew Hintz 65 | Drew Khoury 66 | Dror BG 67 | duralog 68 | edsharp 69 | ekhaled 70 | Eric Allam 71 | eustas 72 | Fauntleroy 73 | fbuchinger 74 | feizhang365 75 | Felipe Lalanne 76 | Felix Raab 77 | Filip Noetzel 78 | flack 79 | Ford_Lawnmower 80 | Gabriel Nahmias 81 | galambalazs 82 | Gautam Mehta 83 | Glenn Ruehle 84 | Golevka 85 | Gordon Smith 86 | greengiant 87 | Guillaume Massé 88 | Hans Engel 89 | Hardest 90 | Hasan Karahan 91 | Hocdoc 92 | Ian Beck 93 | Ian Wehrman 94 | Ian Wetherbee 95 | Ice White 96 | ICHIKAWA, Yuji 97 | Ingo Richter 98 | Irakli Gozalishvili 99 | Ivan Kurnosov 100 | Jacob Lee 101 | Jakub Vrana 102 | James Campos 103 | James Thorne 104 | Jamie Hill 105 | Jan Jongboom 106 | jankeromnes 107 | Jan Keromnes 108 | Jan T. Sott 109 | Jason 110 | Jason Grout 111 | Jason Johnston 112 | Jason San Jose 113 | Jason Siefken 114 | Jean Boussier 115 | jeffkenton 116 | Jeff Pickhardt 117 | jem (graphite) 118 | Jochen Berger 119 | John Connor 120 | John Lees-Miller 121 | John Snelson 122 | jongalloway 123 | Joost-Wim Boekesteijn 124 | Joseph Pecoraro 125 | Joshua Newman 126 | jots 127 | Juan Benavides Romero 128 | Jucovschi Constantin 129 | jwallers@gmail.com 130 | kaniga 131 | Ken Newman 132 | Ken Rockot 133 | Kevin Sawicki 134 | Klaus Silveira 135 | Koh Zi Han, Cliff 136 | komakino 137 | Konstantin Lopuhin 138 | koops 139 | ks-ifware 140 | Lanny 141 | leaf corcoran 142 | Leonya Khachaturov 143 | Liam Newman 144 | List of contributors. Updated before every release. 145 | LM 146 | Lorenzo Stoakes 147 | lynschinzer 148 | Maksim Lin 149 | Maksym Taran 150 | Marat Dreizin 151 | Marco Aurélio 152 | Marijn Haverbeke 153 | Mario Pietsch 154 | Mark Lentczner 155 | Mason Malone 156 | Mateusz Paprocki 157 | mats cronqvist 158 | Matthew Beale 159 | Matthias BUSSONNIER 160 | Matt McDonald 161 | Matt Pass 162 | Matt Sacks 163 | Maximilian Hils 164 | Max Kirsch 165 | mbarkhau 166 | Metatheos 167 | Micah Dubinko 168 | Michael Lehenbauer 169 | Michael Zhou 170 | Mighty Guava 171 | Miguel Castillo 172 | Mike 173 | Mike Brevoort 174 | Mike Diaz 175 | Mike Ivanov 176 | Mike Kadin 177 | MinRK 178 | misfo 179 | mps 180 | Narciso Jaramillo 181 | Nathan Williams 182 | nerbert 183 | nguillaumin 184 | Niels van Groningen 185 | Nikita Beloglazov 186 | Nikita Vasilyev 187 | nlwillia 188 | pablo 189 | Page 190 | Patrick Strawderman 191 | Paul Garvin 192 | Paul Ivanov 193 | Pavel Feldman 194 | Paweł Bartkiewicz 195 | peteguhl 196 | peterkroon 197 | Peter Kroon 198 | prasanthj 199 | Prasanth J 200 | Rahul 201 | Randy Edmunds 202 | Richard Z.H. Wang 203 | robertop23 204 | Robert Plummer 205 | Ruslan Osmanov 206 | sabaca 207 | Samuel Ainsworth 208 | sandeepshetty 209 | santec 210 | Sascha Peilicke 211 | satchmorun 212 | sathyamoorthi 213 | SCLINIC\jdecker 214 | shaund 215 | shaun gilchrist 216 | Shmuel Englard 217 | sonson 218 | spastorelli 219 | Stas Kobzar 220 | Stefan Borsje 221 | Steffen Beyer 222 | Steve O'Hara 223 | Tarmil 224 | tfjgeorge 225 | Thaddee Tyl 226 | think 227 | Thomas Dvornik 228 | Thomas Schmid 229 | Tim Baumann 230 | Timothy Farrell 231 | Timothy Hatcher 232 | Tomas Varaneckas 233 | Tom Erik Støwer 234 | Tom MacWright 235 | Tony Jian 236 | Vestimir Markov 237 | vf 238 | Volker Mische 239 | William Jamieson 240 | Wojtek Ptak 241 | Xavier Mendez 242 | Yunchi Luo 243 | Yuvi Panda 244 | Zachary Dremann 245 | -------------------------------------------------------------------------------- /content/flowcontrol.article: -------------------------------------------------------------------------------- 1 | Akış kontrol deyimleri: for, if, else, switch ve defer 2 | Kodunuzun akışını koşullar, döngüler, "switch"ler ve "defer"ler ile nasıl kontrol edeceğinizi öğrenin. 3 | 4 | Go Yazarları Sunar 5 | https://golang.org 6 | 7 | * For 8 | 9 | Go dilinde döngü yapısı olarak sadece `for` mevcuttur. 10 | 11 | `for` döngüsü noktalı virgüller ayrılmış üç kısımdan oluşur: 12 | 13 | - ilklendirme deyimi: ilk döngüden önce çalıştırılır 14 | - koşul ifadesi: her döngüden önce değerlendirilir 15 | - sonlandırma deyimi: her döngünün sonunda çalıştırılır 16 | 17 | İlklendirme deyimi sıklıkla kısa bir değişken bildirimidir ve bildirilen değişkenler sadece `for` deyiminin kapsamında geçerlidir. 18 | 19 | Döngü koşulu `false` olarak değerlendirildiğinde döngüye girilmeden deyim sonlanır. 20 | 21 | _Not_: C, Java ve Javascript gibi dillerden farklı olarak `for` deyiminin üç kısımlı başlangıcı etrafında `(`)` parantezleri bulunmaz, fakat `{`}` parantezleri daima gereklidir. 22 | 23 | .play flowcontrol/for.go 24 | 25 | * For devam 26 | 27 | İlklendirme (birinci) ve sonlandırma (üçüncü) deyimlerini boş bırakabilirsiniz. 28 | 29 | .play flowcontrol/for-continued.go 30 | 31 | * For, Go'nun "while"ıdır 32 | 33 | Bu aşamada `for` deyimindeki noktalı virgülleri de bir köşeye atabilirsiniz: C'deki `while` deyiminin Go'da karşılığı `for` deyimidir. 34 | 35 | .play flowcontrol/for-is-gos-while.go 36 | 37 | * Sonsuza dek 38 | 39 | Eğer döngü koşulunu belirtmezseniz, sonsuz döngü oluşacaktır. 40 | 41 | Sonsuzluğu küçücük bir alana sığdırdık. 42 | 43 | .play flowcontrol/forever.go 44 | 45 | * If 46 | 47 | Go'da `if` deyimleri görünüm olarak `for` döngüleri gibidir; koşul ifadesinde `(`)` (parantezler) kullanılmaz, ama `{`}` (süslü parantez) kullanılması zorunludur. 48 | 49 | .play flowcontrol/if.go 50 | 51 | * Kısa bir deyim ile if kullanımı 52 | 53 | `for` deyiminde olduğu gibi, `if` deyimi de koşuldan önce çalıştırılacak kısa bir deyim ile başlayabilir. 54 | 55 | Bu kısa deyimde belirtilen değişkenler, `if` koşulunun kapsamı içinde geçerlidir. 56 | 57 | (En sondaki return deyiminde `lim` yerine `v` kullanmayı deneyin.) 58 | 59 | .play flowcontrol/if-with-a-short-statement.go 60 | 61 | * If ve else 62 | 63 | `if` deyiminin kapsamında geçerli olan kısa atama ile atanan değişkenler, `else` blokları içinde de geçerlidir. 64 | 65 | (Her iki `pow` çağrısı da gerçekleşir ve `main`de `fmt.Println` çağrısı başlamadan tamamlanır.) 66 | 67 | .play flowcontrol/if-and-else.go 68 | 69 | * Alıştırma: Döngüler ve Fonksiyonlar 70 | 71 | Karekök alma fonksiyonunu Newton metoduyla gerçekleyin. 72 | 73 | Newton metodunda; bir _z_ başlangıç noktası seçilir ve 74 | 75 | .image /content/img/newton.png 76 | 77 | formülünü tekrarlayarak `Sqrt(x)` ("karekök x") değerine yaklaşılır. 78 | 79 | Başlangıç olarak bu hesaplamayı 10 defa tekrar edin ve (1, 2, 3, ...) çeşitli değerlerle cevaba ne kadar yaklaştığınızı görün. 80 | 81 | Daha sonra döngü koşulunu, sonuç değeri değişmeyi bıraktığında (ya da çok küçük bir fark ile değiştiğinde) döngünün durmasını sağlayacak şekilde düzenleyin. Döngünün daha fazla veya daha az çalışıp çalışmadığına bakın. [[https://golang.org/pkg/math/#Sqrt][Math.sqrt]] fonksiyonunun verdiği sonuca ne kadar yakın bir cevap elde ettiniz? 82 | 83 | İpucu: bir kayan noktalı sayı değeri ("floating point value") bildirmek ve ilklendirmek için ya kayan noktalı sayı bildirimi sözdizimini kullanın ya da dönüştürme işlemi uygulayın: 84 | 85 | z := float64(1) 86 | z := 1.0 87 | 88 | .play flowcontrol/exercise-loops-and-functions.go 89 | 90 | * Switch 91 | 92 | Muhtemelen `switch` (anahtarlama) deyiminin neye benzediğini biliyorsunuzdur. 93 | 94 | `fallthrough` deyimi ile sonlanana kadar, `case` gövdesi otomatik olarak sonlanacaktır. 95 | 96 | .play flowcontrol/switch.go 97 | 98 | * Switch değerlendirme sırası 99 | 100 | "Switch" deyiminde "case"ler yukarıdan aşağıya değerlendirir ve "case"lerden biri doğrulandığında değerlendirme sonlanır. 101 | 102 | (Örneğin, 103 | 104 | switch i { 105 | case 0: 106 | case f(): 107 | } 108 | 109 | eğer `i==0` ise `f` fonksiyonu çağırılmaz.) 110 | 111 | #appengine: *Not:* Go Playground'ta zaman her daim 2009-11-10 23:00:00 UTC'den başlar, 112 | #appengine: bu değerin önemi okuyucu için bir alıştırma niteliğinde olmasıdır. 113 | 114 | .play flowcontrol/switch-evaluation-order.go 115 | 116 | * Koşulsuz Switch 117 | 118 | Koşul belirtilmemiş bir `switch` deyimi, `switch`true` deyimiyle eşdeğerdir. 119 | 120 | Bu yapı uzun "if-then-else" zincirleri yerine kullanılabilecek temiz bir yöntemdir. 121 | 122 | .play flowcontrol/switch-with-no-condition.go 123 | 124 | * Defer 125 | 126 | defer deyimi, kendisini çevreleyen fonksiyon dönene kadar fonksiyonun çalışmasını erteler. 127 | 128 | Ertelenmiş fonksiyon çağrısının argümanları anında değerlendirilir, fakat fonksiyon çağrısı kendisini çevreleyen fonksiyon dönmeden işleme sokulmaz. 129 | 130 | .play flowcontrol/defer.go 131 | 132 | * Defer yığını 133 | 134 | Ertelenmiş fonksiyon çağrıları yığının tepesine yerleştirilir. Bir fonksiyon döndüğü zaman, onun çevrelediği ertelenmiş fonksiyonlar son-giren-ilk-çıkar (LIFO) sırasına göre çağrılır. 135 | 136 | defer deyimleri hakkında daha fazlasını öğrenmek için şu [[https://blog.golang.org/defer-panic-and-recover][blog yazısını]] okuyun. 137 | 138 | .play flowcontrol/defer-multi.go 139 | 140 | * Tebrikler! 141 | 142 | Bu dersin sonuna geldiniz! 143 | 144 | Daha neler öğreneceğinizi görmek için [[/list][bölüm listesine]] geri dönün ya da [[javascript:click('.next-page')][bir sonraki derse]] geçin. 145 | -------------------------------------------------------------------------------- /content/welcome.article: -------------------------------------------------------------------------------- 1 | Hoşgeldiniz! 2 | Bu turu nasıl kullanacağınızı öğrenin: diğer derslere nasıl geçiş yapacağınızı ve kodları nasıl çalıştıracağınızı. 3 | 4 | Go Yazarları Sunar 5 | https://golang.org 6 | 7 | * Merhaba, 世界 8 | 9 | [[https://golang.org/][Go programlama dili]] turuna hoşgeldiniz. 10 | 11 | Tur bir dizi bölümlerden oluşmaktadır. 12 | Sayfanın sol üst köşesindeki [[javascript:highlight(".logo")][Go Turu]] yazısına tıklayarak ilgili bölümlere erişim sağlayabilirsiniz. 13 | 14 | Ayrıca sayfanın sağ üst köşesindeki [[javascript:highlightAndClick(".nav")][menü]] yazısına tıklayarak da tüm tur içeriğini görebilirsiniz. 15 | 16 | Turumuz boyunca, slaytlar ve tamamlamanız için sunulmuş alıştırmalar ile karşılaşacaksınız. 17 | 18 | Bunların arasında gezinmek için şu yöntemleri kullanın: 19 | 20 | - Bir önceki sayfaya gitmek için [[javascript:highlight(".prev-page")]["önceki"]] veya `PageUp`, 21 | 22 | - Bir sonraki sayfaya gitmek için [[javascript:highlight(".next-page")]["sonraki"]] veya `PageDown` . 23 | 24 | Turumuz etkileşimlidir. 25 | Programı 26 | #appengine: uzak sunucuda 27 | kendi bilgisayarınızda çalıştırmak için [[javascript:highlightAndClick("#run")][Çalıştır]] butonuna (veya `shift-enter` tuşlarına basın). Program çıktısını, kodun hemen altında görebilirsiniz. 28 | 29 | Bu örnekler Go dilinin farklı yönlerini açıklamaktadır. Bu programlar Go dili deneyimleriniz için birer başlangıç noktası olarak seçilmiştir. 30 | 31 | Programı düzenleyin ve tekrar çalıştırın. 32 | 33 | [[javascript:highlightAndClick("#format")][Biçimle]] veya `ctrl-enter` tuşlarına bastığınızda, editördeki yazı [[https://golang.org/cmd/gofmt/][gofmt]] aracını kullanarak biçimlendirilir. 34 | Sözdizimi renklendirmesini [[javascript:highlightAndClick(".syntax-checkbox")][Renklendirme]] butonuna basarak açıp kapatabilirsiniz. 35 | 36 | İlerlemeye hazır olduğunuzda, sayfanın altındaki [[javascript:highlightAndClick(".next-page")][sağ oka]] tıklayın ya da `PageDown` tuşuna basın. 37 | 38 | .play welcome/hello.go 39 | 40 | * Dilinizde Go 41 | 42 | Bu tur şu dillerde de mevcuttur: 43 | 44 | - [[https://go-tour-de.appspot.com/][Almanca — Deutsch]] 45 | - [[https://tour.go-zh.org/][Basitleştirilmiş Çince — 中文(简体)]] 46 | - [[https://go-tour-br.appspot.com/][Brezilya Portekizcesi — Português do Brasil]] 47 | - [[https://go-tour-id2.appspot.com/][Endonezce — Bahasa]] 48 | - [[https://go-tour-fr.appspot.com/][Fransızca — Français]] 49 | - [[https://go-tour-zh-tw.appspot.com/][Geleneksel Çince — 中文(繁體)]] 50 | - [[https://go-tour-he.appspot.com/][İbranice — עִבְרִית]] 51 | - [[https://tour.golang.org/][İngilizce — English]] 52 | - [[https://go-tour-es.appspot.com/][İspanyolca — Español]] 53 | - [[https://go-tour-ita.appspot.com/][İtalyanca — Italiano]] 54 | - [[https://go-tour-jp.appspot.com/][Japonca — 日本語]] 55 | - [[https://go-tour-ca.appspot.com/][Katalanca — Català]] 56 | - [[https://go-tour-kr.appspot.com/][Korece — 한국어]] 57 | - [[https://go-tour-uz.appspot.com/][Özbekçe — Ўзбекча]] 58 | - [[https://go-tour-ro.appspot.com/][Rumence — Româna]] 59 | - [[https://go-tour-turkish.appspot.com/][Türkçe - Türkçe]] 60 | - [[https://go-tour-ua.appspot.com/][Ukraynaca — Українська]] 61 | 62 | Devam etmek için [[javascript:highlightAndClick(".next-page")]["ileri"]] butonuna tıklayın ya da `PageDown` tuşlayın. 63 | 64 | #appengine: * Çevrimdışı Go 65 | #appengine: 66 | #appengine: Bu tur, İnternet erişimi olmadan kullanabileceğiniz bağımsız bir program 67 | #appengine: halinde de mevcuttur. 68 | #appengine: 69 | #appengine: Bağımsız tur, kodları kendi makinenizde inşa edip çalıştırdığından 70 | #appengine: daha hızlıdır. 71 | #appengine: 72 | #appengine: Tur'u yerelde çalıştırmak için öncelikle 73 | #appengine: [[http://golang.org/dl/][Go'yu indirin ve kurun]] 74 | #appengine: ve Tur'u komut satırında başlatın: 75 | #appengine: 76 | #appengine: go tool tour 77 | #appengine: 78 | #appengine: Tur programı Tur'un yerel sürümünü görüntüleyen bir web tarayıcı 79 | #appengine: açacaktır 80 | #appengine: 81 | #appengine: Veya dilerseniz Tur'a bu web sitesi üzerinden devam edebilirsiniz. 82 | 83 | #appengine: * Go Playground 84 | #appengine: 85 | #appengine: Bu tur [[https://golang.org/][golang.org]] sunucuları üzerinde çalışan 86 | #appengine: [[https://play.golang.org/][Go Playground]] web servisi üzerine kurulmuştur. 87 | #appengine: 88 | #appengine: Servis, Go programını, bir korunaklı sanal alan ("sandbox") içerisine alıp, 89 | #appengine: derler, bağlar, çalıştırır ve bu programın çıktısını döndürür. 90 | #appengine: 91 | #appengine: Playground içinde çalıştırılabilen programlar birtakım kısıtlamalara maruz kalır: 92 | #appengine: 93 | #appengine: - Playground standart kütüphanenin çoğunu; ağ ve dosya sistemi erişimi eksiklikleri 94 | #appengine: gibi göze çarpan bazı istisnalar dışında, kullanabilir. Bu nedenle, 95 | #appengine: playground programının dış dünyayla tek iletişimi "standard output" ve 96 | #appengine: "standard error"dur. 97 | #appengine: 98 | #appengine: - Playground'ta zamanın başlangıcı 2009-11-10 23:00:00 UTC tarihine 99 | #appengine: karşılık gelir (bu tarihin öneminin ne olduğunu bulmak okuyucu için 100 | #appengine: alıştırma niteliğindedir). Bu, programlara rastgele olmayan çıktılar 101 | #appengine: vererek önbelleğe alınmalarını kolaylaştırır. 102 | #appengine: 103 | #appengine: - Yürütme zamanı ("execution time"), işlemci, bellek kullanımında da kısıtlamalar 104 | #appengine: mevcuttur ve program dış ağ sunucularına erişemez. 105 | #appengine: 106 | #appengine: Playground, Go'nun en son kararlı sürümünü kullanır. 107 | #appengine: 108 | #appengine: Daha fazla bilgi için "[[https://blog.golang.org/playground][Inside the Go Playground]]" 109 | #appengine: kaynağını okuyun. 110 | #appengine: 111 | #appengine: .play welcome/sandbox.go 112 | 113 | * Tebrikler 114 | 115 | Turun ilk bölümünü bitirdiniz! 116 | 117 | Şimdi Go hakkında daha neler öğrenebileceğinizi görmek için [[javascript:highlightAndClick(".logo")][Go Turu]] logosuna veya bir sonraki derse doğrudan gitmek için [[javascript:click('.next-page')][bir sonraki ders]] yazısına tıklayın. 118 | -------------------------------------------------------------------------------- /gotour/local.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !appengine 6 | 7 | package main 8 | 9 | import ( 10 | "flag" 11 | "fmt" 12 | "go/build" 13 | "io" 14 | "log" 15 | "net" 16 | "net/http" 17 | "net/url" 18 | "os" 19 | "os/exec" 20 | "path/filepath" 21 | "runtime" 22 | "strings" 23 | "time" 24 | 25 | "golang.org/x/tools/playground/socket" 26 | 27 | // Imports so that go build/install automatically installs them. 28 | _ "golang.org/x/tour/pic" 29 | _ "golang.org/x/tour/tree" 30 | _ "golang.org/x/tour/wc" 31 | ) 32 | 33 | const ( 34 | basePkg = "golang.org/x/tour/" 35 | socketPath = "/socket" 36 | ) 37 | 38 | var ( 39 | httpListen = flag.String("http", "127.0.0.1:3999", "host:port to listen on") 40 | openBrowser = flag.Bool("openbrowser", true, "open browser automatically") 41 | ) 42 | 43 | var ( 44 | // GOPATH containing the tour packages 45 | gopath = os.Getenv("GOPATH") 46 | 47 | httpAddr string 48 | ) 49 | 50 | // isRoot reports whether path is the root directory of the tour tree. 51 | // To be the root, it must have content and template subdirectories. 52 | func isRoot(path string) bool { 53 | _, err := os.Stat(filepath.Join(path, "content", "welcome.article")) 54 | if err == nil { 55 | _, err = os.Stat(filepath.Join(path, "template", "index.tmpl")) 56 | } 57 | return err == nil 58 | } 59 | 60 | func findRoot() (string, error) { 61 | ctx := build.Default 62 | p, err := ctx.Import(basePkg, "", build.FindOnly) 63 | if err == nil && isRoot(p.Dir) { 64 | return p.Dir, nil 65 | } 66 | tourRoot := filepath.Join(runtime.GOROOT(), "misc", "tour") 67 | ctx.GOPATH = tourRoot 68 | p, err = ctx.Import(basePkg, "", build.FindOnly) 69 | if err == nil && isRoot(tourRoot) { 70 | gopath = tourRoot 71 | return tourRoot, nil 72 | } 73 | return "", fmt.Errorf("could not find go-tour content; check $GOROOT and $GOPATH") 74 | } 75 | 76 | func main() { 77 | flag.Parse() 78 | 79 | // find and serve the go tour files 80 | root, err := findRoot() 81 | if err != nil { 82 | log.Fatalf("Couldn't find tour files: %v", err) 83 | } 84 | 85 | log.Println("Serving content from", root) 86 | 87 | host, port, err := net.SplitHostPort(*httpListen) 88 | if err != nil { 89 | log.Fatal(err) 90 | } 91 | if host == "" { 92 | host = "localhost" 93 | } 94 | if host != "127.0.0.1" && host != "localhost" { 95 | log.Print(localhostWarning) 96 | } 97 | httpAddr = host + ":" + port 98 | 99 | if err := initTour(root, "SocketTransport"); err != nil { 100 | log.Fatal(err) 101 | } 102 | 103 | http.HandleFunc("/", rootHandler) 104 | http.HandleFunc("/lesson/", lessonHandler) 105 | 106 | origin := &url.URL{Scheme: "http", Host: host + ":" + port} 107 | http.Handle(socketPath, socket.NewHandler(origin)) 108 | 109 | // Keep these static file handlers in sync with ../app.yaml. 110 | static := http.FileServer(http.Dir(root)) 111 | http.Handle("/content/img/", static) 112 | http.Handle("/static/", static) 113 | imgDir := filepath.Join(root, "static", "img") 114 | http.Handle("/favicon.ico", http.FileServer(http.Dir(imgDir))) 115 | 116 | go func() { 117 | url := "http://" + httpAddr 118 | if waitServer(url) && *openBrowser && startBrowser(url) { 119 | log.Printf("A browser window should open. If not, please visit %s", url) 120 | } else { 121 | log.Printf("Please open your web browser and visit %s", url) 122 | } 123 | }() 124 | log.Fatal(http.ListenAndServe(httpAddr, nil)) 125 | } 126 | 127 | // rootHandler returns a handler for all the requests except the ones for lessons. 128 | func rootHandler(w http.ResponseWriter, r *http.Request) { 129 | if err := renderUI(w); err != nil { 130 | log.Println(err) 131 | } 132 | } 133 | 134 | // lessonHandler handler the HTTP requests for lessons. 135 | func lessonHandler(w http.ResponseWriter, r *http.Request) { 136 | lesson := strings.TrimPrefix(r.URL.Path, "/lesson/") 137 | if err := writeLesson(lesson, w); err != nil { 138 | if err == lessonNotFound { 139 | http.NotFound(w, r) 140 | } else { 141 | log.Println(err) 142 | } 143 | } 144 | } 145 | 146 | const localhostWarning = ` 147 | WARNING! WARNING! WARNING! 148 | 149 | I appear to be listening on an address that is not localhost. 150 | Anyone with access to this address and port will have access 151 | to this machine as the user running gotour. 152 | 153 | If you don't understand this message, hit Control-C to terminate this process. 154 | 155 | WARNING! WARNING! WARNING! 156 | ` 157 | 158 | type response struct { 159 | Output string `json:"output"` 160 | Errors string `json:"compile_errors"` 161 | } 162 | 163 | func init() { 164 | socket.Environ = environ 165 | } 166 | 167 | // environ returns the original execution environment with GOPATH 168 | // replaced (or added) with the value of the global var gopath. 169 | func environ() (env []string) { 170 | for _, v := range os.Environ() { 171 | if !strings.HasPrefix(v, "GOPATH=") { 172 | env = append(env, v) 173 | } 174 | } 175 | env = append(env, "GOPATH="+gopath) 176 | return 177 | } 178 | 179 | // waitServer waits some time for the http Server to start 180 | // serving url. The return value reports whether it starts. 181 | func waitServer(url string) bool { 182 | tries := 20 183 | for tries > 0 { 184 | resp, err := http.Get(url) 185 | if err == nil { 186 | resp.Body.Close() 187 | return true 188 | } 189 | time.Sleep(100 * time.Millisecond) 190 | tries-- 191 | } 192 | return false 193 | } 194 | 195 | // startBrowser tries to open the URL in a browser, and returns 196 | // whether it succeed. 197 | func startBrowser(url string) bool { 198 | // try to start the browser 199 | var args []string 200 | switch runtime.GOOS { 201 | case "darwin": 202 | args = []string{"open"} 203 | case "windows": 204 | args = []string{"cmd", "/c", "start"} 205 | default: 206 | args = []string{"xdg-open"} 207 | } 208 | cmd := exec.Command(args[0], append(args[1:], url)...) 209 | return cmd.Start() == nil 210 | } 211 | 212 | // prepContent for the local tour simply returns the content as-is. 213 | func prepContent(r io.Reader) io.Reader { return r } 214 | 215 | // socketAddr returns the WebSocket handler address. 216 | func socketAddr() string { return "ws://" + httpAddr + socketPath } 217 | -------------------------------------------------------------------------------- /static/lib/codemirror/lib/codemirror.css: -------------------------------------------------------------------------------- 1 | /* BASICS */ 2 | 3 | .CodeMirror { 4 | /* Set height, width, borders, and global font properties here */ 5 | font-family: monospace; 6 | height: 300px; 7 | } 8 | .CodeMirror-scroll { 9 | /* Set scrolling behaviour here */ 10 | overflow: auto; 11 | } 12 | 13 | /* PADDING */ 14 | 15 | .CodeMirror-lines { 16 | padding: 4px 0; /* Vertical padding around content */ 17 | } 18 | .CodeMirror pre { 19 | padding: 0 4px; /* Horizontal padding of content */ 20 | } 21 | 22 | .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { 23 | background-color: white; /* The little square between H and V scrollbars */ 24 | } 25 | 26 | /* GUTTER */ 27 | 28 | .CodeMirror-gutters { 29 | border-right: 1px solid #ddd; 30 | background-color: #f7f7f7; 31 | white-space: nowrap; 32 | } 33 | .CodeMirror-linenumbers {} 34 | .CodeMirror-linenumber { 35 | padding: 0 3px 0 5px; 36 | min-width: 20px; 37 | text-align: right; 38 | color: #999; 39 | } 40 | 41 | /* CURSOR */ 42 | 43 | .CodeMirror div.CodeMirror-cursor { 44 | border-left: 1px solid black; 45 | z-index: 3; 46 | } 47 | /* Shown when moving in bi-directional text */ 48 | .CodeMirror div.CodeMirror-secondarycursor { 49 | border-left: 1px solid silver; 50 | } 51 | .CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursor { 52 | width: auto; 53 | border: 0; 54 | background: #7e7; 55 | z-index: 1; 56 | } 57 | /* Can style cursor different in overwrite (non-insert) mode */ 58 | .CodeMirror div.CodeMirror-cursor.CodeMirror-overwrite {} 59 | 60 | .cm-tab { display: inline-block; } 61 | 62 | /* DEFAULT THEME */ 63 | 64 | .cm-s-default .cm-keyword {color: #708;} 65 | .cm-s-default .cm-atom {color: #219;} 66 | .cm-s-default .cm-number {color: #164;} 67 | .cm-s-default .cm-def {color: #00f;} 68 | .cm-s-default .cm-variable {color: black;} 69 | .cm-s-default .cm-variable-2 {color: #05a;} 70 | .cm-s-default .cm-variable-3 {color: #085;} 71 | .cm-s-default .cm-property {color: black;} 72 | .cm-s-default .cm-operator {color: black;} 73 | .cm-s-default .cm-comment {color: #a50;} 74 | .cm-s-default .cm-string {color: #a11;} 75 | .cm-s-default .cm-string-2 {color: #f50;} 76 | .cm-s-default .cm-meta {color: #555;} 77 | .cm-s-default .cm-error {color: #f00;} 78 | .cm-s-default .cm-qualifier {color: #555;} 79 | .cm-s-default .cm-builtin {color: #30a;} 80 | .cm-s-default .cm-bracket {color: #997;} 81 | .cm-s-default .cm-tag {color: #170;} 82 | .cm-s-default .cm-attribute {color: #00c;} 83 | .cm-s-default .cm-header {color: blue;} 84 | .cm-s-default .cm-quote {color: #090;} 85 | .cm-s-default .cm-hr {color: #999;} 86 | .cm-s-default .cm-link {color: #00c;} 87 | 88 | .cm-negative {color: #d44;} 89 | .cm-positive {color: #292;} 90 | .cm-header, .cm-strong {font-weight: bold;} 91 | .cm-em {font-style: italic;} 92 | .cm-link {text-decoration: underline;} 93 | 94 | .cm-invalidchar {color: #f00;} 95 | 96 | div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;} 97 | div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} 98 | .CodeMirror-activeline-background {background: #e8f2ff;} 99 | 100 | /* STOP */ 101 | 102 | /* The rest of this file contains styles related to the mechanics of 103 | the editor. You probably shouldn't touch them. */ 104 | 105 | .CodeMirror { 106 | line-height: 1; 107 | position: relative; 108 | overflow: hidden; 109 | background: white; 110 | color: black; 111 | } 112 | 113 | .CodeMirror-scroll { 114 | /* 30px is the magic margin used to hide the element's real scrollbars */ 115 | /* See overflow: hidden in .CodeMirror */ 116 | margin-bottom: -30px; margin-right: -30px; 117 | padding-bottom: 30px; padding-right: 30px; 118 | height: 100%; 119 | outline: none; /* Prevent dragging from highlighting the element */ 120 | position: relative; 121 | } 122 | .CodeMirror-sizer { 123 | position: relative; 124 | } 125 | 126 | /* The fake, visible scrollbars. Used to force redraw during scrolling 127 | before actuall scrolling happens, thus preventing shaking and 128 | flickering artifacts. */ 129 | .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { 130 | position: absolute; 131 | z-index: 6; 132 | display: none; 133 | } 134 | .CodeMirror-vscrollbar { 135 | right: 0; top: 0; 136 | overflow-x: hidden; 137 | overflow-y: scroll; 138 | } 139 | .CodeMirror-hscrollbar { 140 | bottom: 0; left: 0; 141 | overflow-y: hidden; 142 | overflow-x: scroll; 143 | } 144 | .CodeMirror-scrollbar-filler { 145 | right: 0; bottom: 0; 146 | } 147 | .CodeMirror-gutter-filler { 148 | left: 0; bottom: 0; 149 | } 150 | 151 | .CodeMirror-gutters { 152 | position: absolute; left: 0; top: 0; 153 | padding-bottom: 30px; 154 | z-index: 3; 155 | } 156 | .CodeMirror-gutter { 157 | white-space: normal; 158 | height: 100%; 159 | padding-bottom: 30px; 160 | margin-bottom: -32px; 161 | display: inline-block; 162 | /* Hack to make IE7 behave */ 163 | *zoom:1; 164 | *display:inline; 165 | } 166 | .CodeMirror-gutter-elt { 167 | position: absolute; 168 | cursor: default; 169 | z-index: 4; 170 | } 171 | 172 | .CodeMirror-lines { 173 | cursor: text; 174 | } 175 | .CodeMirror pre { 176 | /* Reset some styles that the rest of the page might have set */ 177 | -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0; 178 | border-width: 0; 179 | background: transparent; 180 | font-family: inherit; 181 | font-size: inherit; 182 | margin: 0; 183 | white-space: pre; 184 | word-wrap: normal; 185 | line-height: inherit; 186 | color: inherit; 187 | z-index: 2; 188 | position: relative; 189 | overflow: visible; 190 | } 191 | .CodeMirror-wrap pre { 192 | word-wrap: break-word; 193 | white-space: pre-wrap; 194 | word-break: normal; 195 | } 196 | .CodeMirror-code pre { 197 | border-right: 30px solid transparent; 198 | width: -webkit-fit-content; 199 | width: -moz-fit-content; 200 | width: fit-content; 201 | } 202 | .CodeMirror-wrap .CodeMirror-code pre { 203 | border-right: none; 204 | width: auto; 205 | } 206 | .CodeMirror-linebackground { 207 | position: absolute; 208 | left: 0; right: 0; top: 0; bottom: 0; 209 | z-index: 0; 210 | } 211 | 212 | .CodeMirror-linewidget { 213 | position: relative; 214 | z-index: 2; 215 | overflow: auto; 216 | } 217 | 218 | .CodeMirror-widget { 219 | } 220 | 221 | .CodeMirror-wrap .CodeMirror-scroll { 222 | overflow-x: hidden; 223 | } 224 | 225 | .CodeMirror-measure { 226 | position: absolute; 227 | width: 100%; height: 0px; 228 | overflow: hidden; 229 | visibility: hidden; 230 | } 231 | .CodeMirror-measure pre { position: static; } 232 | 233 | .CodeMirror div.CodeMirror-cursor { 234 | position: absolute; 235 | visibility: hidden; 236 | border-right: none; 237 | width: 0; 238 | } 239 | .CodeMirror-focused div.CodeMirror-cursor { 240 | visibility: visible; 241 | } 242 | 243 | .CodeMirror-selected { background: #d9d9d9; } 244 | .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; } 245 | 246 | .cm-searching { 247 | background: #ffa; 248 | background: rgba(255, 255, 0, .4); 249 | } 250 | 251 | /* IE7 hack to prevent it from returning funny offsetTops on the spans */ 252 | .CodeMirror span { *vertical-align: text-bottom; } 253 | 254 | @media print { 255 | /* Hide the cursor when printing */ 256 | .CodeMirror div.CodeMirror-cursor { 257 | visibility: hidden; 258 | } 259 | } 260 | -------------------------------------------------------------------------------- /static/js/values.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 The Go Authors. All rights reserved. 2 | * Use of this source code is governed by a BSD-style 3 | * license that can be found in the LICENSE file. 4 | */ 5 | 'use strict'; 6 | 7 | angular.module('tour.values', []). 8 | 9 | // List of modules with description and lessons in it. 10 | value('tableOfContents', [{ 11 | 'id': 'mechanics', 12 | 'title': 'Go turu kullanımı', 13 | 'description': '
Go programlama dili turuna hoşgeldiniz. Turumuz, dilin en önemli özelliklerini kapsayan üç ana bölümden oluşuyor:
', 14 | 'lessons': ['welcome'] 15 | }, { 16 | 'id': 'basics', 17 | 'title': 'Temel kavramlar', 18 | 'description': 'Başlangıç olarak, dilin temellerini öğrenin.
Değişken tanımlama, fonksiyon çağırma ve diğer konulara geçmeden önce bilmeniz gereken herşey.
', 19 | 'lessons': ['basics', 'flowcontrol', 'moretypes'] 20 | }, { 21 | 'id': 'methods', 22 | 'title': 'Metodlar ve arayüzler', 23 | 'description': 'Türlere metod tanımlamayı, arayüz bildirmeyi ve bunların hepsini nasıl bir arada kullanacağınızı öğrenin.
', 24 | 'lessons': ['methods'] 25 | }, { 26 | 'id': 'concurrency', 27 | 'title': 'Eşzamanlılık', 28 | 'description': 'Go, eşzamanlılık özelliklerini dilin temel bir parçası olarak sunar.
Bu bölüm, go rutinlerin ve kanalların eşzamanlılık desenlerini gerçeklemede nasıl kullanıldığı anlatır.
', 29 | 'lessons': ['concurrency'] 30 | }]). 31 | 32 | // translation 33 | value('translation', { 34 | 'off': 'kapalı', 35 | 'on': 'açık', 36 | 'syntax': 'Sözdizimi Renklendirmesi', 37 | 'lineno': 'Satır Numaraları', 38 | 'reset': 'Slaytı Sıfırla', 39 | 'format': 'Kaynak Kodu Biçimle', 40 | 'kill': 'Programı Öldür', 41 | 'run': 'Çalıştır', 42 | 'compile': 'Derle ve Çalıştır', 43 | 'more': 'Seçenekler', 44 | 'toc': 'İçindekiler', 45 | 'prev': 'Geri', 46 | 'next': 'İleri', 47 | 'waiting': 'Sunucu bekleniyor...', 48 | 'errcomm': 'Sunucu iletişiminde hata.', 49 | 'submit-feedback': 'Bu sayfa hakkında geri bildirimde bulun', 50 | 51 | // GitHub issue template: update repo and messaging when translating. 52 | 'github-repo': 'github.com/golang-tr/tour', 53 | 'issue-title': 'tur: [KISA AÇIKLAMA İLE DEĞİŞTİRİN]', 54 | 'issue-message': 'Yukarıdaki başlığı sorunu tarif edecek şekilde değiştirin ve geri bildiriminizi (gerekiyorsa ilgili kodla birlikte) buraya ekleyin', 55 | 'context': 'Bağlam', 56 | }). 57 | 58 | // Config for codemirror plugin 59 | value('ui.config', { 60 | codemirror: { 61 | mode: 'text/x-go', 62 | matchBrackets: true, 63 | lineNumbers: true, 64 | autofocus: true, 65 | indentWithTabs: true, 66 | indentUnit: 4, 67 | tabSize: 4, 68 | lineWrapping: true, 69 | extraKeys: { 70 | 'Shift-Enter': function() { 71 | $('#run').click(); 72 | }, 73 | 'Ctrl-Enter': function() { 74 | $('#format').click(); 75 | }, 76 | 'PageDown': function() { 77 | return false; 78 | }, 79 | 'PageUp': function() { 80 | return false; 81 | }, 82 | }, 83 | // TODO: is there a better way to do this? 84 | // AngularJS values can't depend on factories. 85 | onChange: function() { 86 | if (window.codeChanged !== null) window.codeChanged(); 87 | } 88 | } 89 | }). 90 | 91 | // mapping from the old paths (#42) to the new organization. 92 | // The values have been generated with the map.sh script in the tools directory. 93 | value('mapping', { 94 | '#1': '/welcome/1', // Hello, 世界 95 | '#2': '/welcome/2', // Go local 96 | '#3': '/basics/1', // Packages 97 | '#4': '/basics/2', // Imports 98 | '#5': '/basics/3', // Exported names 99 | '#6': '/basics/4', // Functions 100 | '#7': '/basics/5', // Functions continued 101 | '#8': '/basics/6', // Multiple results 102 | '#9': undefined, // Named results 103 | '#10': '/basics/8', // Variables 104 | '#11': '/basics/9', // Variables with initializers 105 | '#12': '/basics/10', // Short variable declarations 106 | '#13': '/basics/11', // Basic types 107 | '#14': '/basics/13', // Type conversions 108 | '#15': '/basics/15', // Constants 109 | '#16': '/basics/16', // Numeric Constants 110 | '#17': '/flowcontrol/1', // For 111 | '#18': '/flowcontrol/2', // For continued 112 | '#19': '/flowcontrol/3', // For is Go's "while" 113 | '#20': '/flowcontrol/4', // Forever 114 | '#21': '/flowcontrol/5', // If 115 | '#22': '/flowcontrol/6', // If with a short statement 116 | '#23': '/flowcontrol/7', // If and else 117 | '#24': '/flowcontrol/8', // Exercise: Loops and Functions 118 | '#25': '/moretypes/2', // Structs 119 | '#26': '/moretypes/3', // Struct Fields 120 | '#27': '/moretypes/1', // Pointers 121 | '#28': '/moretypes/5', // Struct Literals 122 | '#29': undefined, // The new function 123 | '#30': '/moretypes/6', // Arrays 124 | '#31': '/moretypes/7', // Slices 125 | '#32': '/moretypes/8', // Slicing slices 126 | '#33': '/moretypes/9', // Making slices 127 | '#34': '/moretypes/10', // Nil slices 128 | '#35': '/moretypes/12', // Range 129 | '#36': '/moretypes/13', // Range continued 130 | '#37': '/moretypes/14', // Exercise: Slices 131 | '#38': '/moretypes/15', // Maps 132 | '#39': '/moretypes/16', // Map literals 133 | '#40': '/moretypes/17', // Map literals continued 134 | '#41': '/moretypes/18', // Mutating Maps 135 | '#42': '/moretypes/19', // Exercise: Maps 136 | '#43': '/moretypes/20', // Function values 137 | '#44': '/moretypes/21', // Function closures 138 | '#45': '/moretypes/22', // Exercise: Fibonacci closure 139 | '#46': '/flowcontrol/9', // Switch 140 | '#47': '/flowcontrol/10', // Switch evaluation order 141 | '#48': '/flowcontrol/11', // Switch with no condition 142 | '#49': undefined, // Advanced Exercise: Complex cube roots 143 | '#50': undefined, // Methods and Interfaces 144 | '#51': '/methods/1', // Methods 145 | '#52': '/methods/2', // Methods continued 146 | '#53': '/methods/3', // Methods with pointer receivers 147 | '#54': '/methods/4', // Interfaces 148 | '#55': '/methods/5', // Interfaces are satisfied implicitly 149 | '#56': '/methods/8', // Errors 150 | '#57': '/methods/9', // Exercise: Errors 151 | '#58': '/methods/13', // Web servers 152 | '#59': '/methods/14', // Exercise: HTTP Handlers 153 | '#60': '/methods/15', // Images 154 | '#61': '/methods/16', // Exercise: Images 155 | '#62': undefined, // Exercise: Rot13 Reader 156 | '#63': undefined, // Concurrency 157 | '#64': '/concurrency/1', // Goroutines 158 | '#65': '/concurrency/2', // Channels 159 | '#66': '/concurrency/3', // Buffered Channels 160 | '#67': '/concurrency/4', // Range and Close 161 | '#68': '/concurrency/5', // Select 162 | '#69': '/concurrency/6', // Default Selection 163 | '#70': '/concurrency/7', // Exercise: Equivalent Binary Trees 164 | '#71': '/concurrency/8', // Exercise: Equivalent Binary Trees 165 | '#72': '/concurrency/9', // Exercise: Web Crawler 166 | '#73': '/concurrency/10', // Where to Go from here... 167 | }); 168 | -------------------------------------------------------------------------------- /static/lib/codemirror/mode/go/go.js: -------------------------------------------------------------------------------- 1 | function goMode(commentsOnly) { 2 | return function(config) { 3 | var indentUnit = config.indentUnit; 4 | 5 | var keywords = { 6 | "break":true, "case":true, "chan":true, "const":true, "continue":true, 7 | "default":true, "defer":true, "else":true, "fallthrough":true, "for":true, 8 | "func":true, "go":true, "goto":true, "if":true, "import":true, 9 | "interface":true, "map":true, "package":true, "range":true, "return":true, 10 | "select":true, "struct":true, "switch":true, "type":true, "var":true, 11 | "bool":true, "byte":true, "complex64":true, "complex128":true, "error":true, 12 | "float32":true, "float64":true, "int8":true, "int16":true, "int32":true, 13 | "int64":true, "rune":true, "string":true, "uint8":true, "uint16":true, "uint32":true, 14 | "uint64":true, "int":true, "uint":true, "uintptr":true 15 | }; 16 | 17 | var atoms = { 18 | "true":true, "false":true, "iota":true, "nil":true, "append":true, 19 | "cap":true, "close":true, "complex":true, "copy":true, "delete":true, "imag":true, 20 | "len":true, "make":true, "new":true, "panic":true, "print":true, 21 | "println":true, "real":true, "recover":true 22 | }; 23 | 24 | var isOperatorChar = /[+\-*&^%:=<>!|\/]/; 25 | 26 | var curPunc; 27 | 28 | function tokenBase(stream, state) { 29 | var ch = stream.next(); 30 | if (ch == '"' || ch == "'" || ch == "`") { 31 | state.tokenize = tokenString(ch); 32 | return state.tokenize(stream, state); 33 | } 34 | if (/[\d\.]/.test(ch)) { 35 | if (ch == ".") { 36 | stream.match(/^[0-9]+([eE][\-+]?[0-9]+)?/); 37 | } else if (ch == "0") { 38 | stream.match(/^[xX][0-9a-fA-F]+/) || stream.match(/^0[0-7]+/); 39 | } else { 40 | stream.match(/^[0-9]*\.?[0-9]*([eE][\-+]?[0-9]+)?/); 41 | } 42 | return "number"; 43 | } 44 | if (/[\[\]{}\(\),;\:\.]/.test(ch)) { 45 | curPunc = ch; 46 | return null; 47 | } 48 | if (ch == "/") { 49 | if (stream.eat("*")) { 50 | state.tokenize = tokenComment; 51 | return tokenComment(stream, state); 52 | } 53 | if (stream.eat("/")) { 54 | stream.skipToEnd(); 55 | return "comment"; 56 | } 57 | } 58 | if (isOperatorChar.test(ch)) { 59 | stream.eatWhile(isOperatorChar); 60 | return "operator"; 61 | } 62 | stream.eatWhile(/[\w\$_]/); 63 | var cur = stream.current(); 64 | if (keywords.propertyIsEnumerable(cur)) { 65 | if (cur == "case" || cur == "default") curPunc = "case"; 66 | return "keyword"; 67 | } 68 | if (atoms.propertyIsEnumerable(cur)) return "atom"; 69 | return "variable"; 70 | } 71 | 72 | function tokenString(quote) { 73 | return function(stream, state) { 74 | var escaped = false, 75 | next, end = false; 76 | while ((next = stream.next()) != null) { 77 | if (next == quote && !escaped) { 78 | end = true; 79 | break; 80 | } 81 | escaped = !escaped && next == "\\"; 82 | } 83 | if (end || !(escaped || quote == "`")) 84 | state.tokenize = tokenBase; 85 | return "string"; 86 | }; 87 | } 88 | 89 | function tokenComment(stream, state) { 90 | var maybeEnd = false, 91 | ch; 92 | while (ch = stream.next()) { 93 | if (ch == "/" && maybeEnd) { 94 | state.tokenize = tokenBase; 95 | break; 96 | } 97 | maybeEnd = (ch == "*"); 98 | } 99 | return "comment"; 100 | } 101 | 102 | function Context(indented, column, type, align, prev) { 103 | this.indented = indented; 104 | this.column = column; 105 | this.type = type; 106 | this.align = align; 107 | this.prev = prev; 108 | } 109 | 110 | function pushContext(state, col, type) { 111 | return state.context = new Context(state.indented, col, type, null, state.context); 112 | } 113 | 114 | function popContext(state) { 115 | var t = state.context.type; 116 | if (t == ")" || t == "]" || t == "}") 117 | state.indented = state.context.indented; 118 | return state.context = state.context.prev; 119 | } 120 | 121 | // Interface 122 | 123 | return { 124 | startState: function(basecolumn) { 125 | return { 126 | tokenize: null, 127 | context: new Context((basecolumn || 0) - indentUnit, 0, "top", false), 128 | indented: 0, 129 | startOfLine: true 130 | }; 131 | }, 132 | 133 | token: function(stream, state) { 134 | var ctx = state.context; 135 | if (stream.sol()) { 136 | if (ctx.align == null) ctx.align = false; 137 | state.indented = stream.indentation(); 138 | state.startOfLine = true; 139 | if (ctx.type == "case") ctx.type = "}"; 140 | } 141 | if (stream.eatSpace()) return null; 142 | curPunc = null; 143 | var style = (state.tokenize || tokenBase)(stream, state); 144 | if (style == "comment") return style; 145 | if (ctx.align == null) ctx.align = true; 146 | 147 | if (curPunc == "{") pushContext(state, stream.column(), "}"); 148 | else if (curPunc == "[") pushContext(state, stream.column(), "]"); 149 | else if (curPunc == "(") pushContext(state, stream.column(), ")"); 150 | else if (curPunc == "case") ctx.type = "case"; 151 | else if (curPunc == "}" && ctx.type == "}") ctx = popContext(state); 152 | else if (curPunc == ctx.type) popContext(state); 153 | state.startOfLine = false; 154 | if (commentsOnly) return ""; 155 | return style; 156 | }, 157 | 158 | indent: function(state, textAfter) { 159 | if (state.tokenize != tokenBase && state.tokenize != null) return 0; 160 | var ctx = state.context, 161 | firstChar = textAfter && textAfter.charAt(0); 162 | if (ctx.type == "case" && /^(?:case|default)\b/.test(textAfter)) { 163 | state.context.type = "}"; 164 | return ctx.indented; 165 | } 166 | var closing = firstChar == ctx.type; 167 | if (ctx.align) return ctx.column + (closing ? 0 : 1); 168 | else return ctx.indented + (closing ? 0 : indentUnit); 169 | }, 170 | 171 | electricChars: "{}:", 172 | blockCommentStart: "/*", 173 | blockCommentEnd: "*/", 174 | lineComment: "//" 175 | }; 176 | } 177 | } 178 | 179 | CodeMirror.defineMode("go", goMode(false)); 180 | CodeMirror.defineMIME("text/x-go", "go"); 181 | 182 | CodeMirror.defineMode("goComments", goMode(true)); 183 | CodeMirror.defineMIME("text/x-go-comments", "goComments"); 184 | -------------------------------------------------------------------------------- /gotour/tour.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main // import "golang.org/x/tour/gotour" 6 | 7 | import ( 8 | "bytes" 9 | "crypto/sha1" 10 | "encoding/base64" 11 | "encoding/json" 12 | "fmt" 13 | "html/template" 14 | "io" 15 | "io/ioutil" 16 | "net/http" 17 | "os" 18 | "path/filepath" 19 | "strings" 20 | "time" 21 | 22 | "golang.org/x/tools/godoc/static" 23 | "golang.org/x/tools/present" 24 | ) 25 | 26 | var ( 27 | uiContent []byte 28 | lessons = make(map[string][]byte) 29 | lessonNotFound = fmt.Errorf("lesson not found") 30 | ) 31 | 32 | // initTour loads tour.article and the relevant HTML templates from the given 33 | // tour root, and renders the template to the tourContent global variable. 34 | func initTour(root, transport string) error { 35 | // Make sure playground is enabled before rendering. 36 | present.PlayEnabled = true 37 | 38 | // Set up templates. 39 | action := filepath.Join(root, "template", "action.tmpl") 40 | tmpl, err := present.Template().ParseFiles(action) 41 | if err != nil { 42 | return fmt.Errorf("parse templates: %v", err) 43 | } 44 | 45 | // Init lessons. 46 | contentPath := filepath.Join(root, "content") 47 | if err := initLessons(tmpl, contentPath); err != nil { 48 | return fmt.Errorf("init lessons: %v", err) 49 | } 50 | 51 | // Init UI 52 | index := filepath.Join(root, "template", "index.tmpl") 53 | ui, err := template.ParseFiles(index) 54 | if err != nil { 55 | return fmt.Errorf("parse index.tmpl: %v", err) 56 | } 57 | buf := new(bytes.Buffer) 58 | 59 | data := struct { 60 | SocketAddr string 61 | Transport template.JS 62 | }{socketAddr(), template.JS(transport)} 63 | 64 | if err := ui.Execute(buf, data); err != nil { 65 | return fmt.Errorf("render UI: %v", err) 66 | } 67 | uiContent = buf.Bytes() 68 | 69 | return initScript(root) 70 | } 71 | 72 | // initLessonss finds all the lessons in the passed directory, renders them, 73 | // using the given template and saves the content in the lessons map. 74 | func initLessons(tmpl *template.Template, content string) error { 75 | dir, err := os.Open(content) 76 | if err != nil { 77 | return err 78 | } 79 | files, err := dir.Readdirnames(0) 80 | if err != nil { 81 | return err 82 | } 83 | for _, f := range files { 84 | if filepath.Ext(f) != ".article" { 85 | continue 86 | } 87 | content, err := parseLesson(tmpl, filepath.Join(content, f)) 88 | if err != nil { 89 | return fmt.Errorf("parsing %v: %v", f, err) 90 | } 91 | name := strings.TrimSuffix(f, ".article") 92 | lessons[name] = content 93 | } 94 | return nil 95 | } 96 | 97 | // File defines the JSON form of a code file in a page. 98 | type File struct { 99 | Name string 100 | Content string 101 | Hash string 102 | } 103 | 104 | // Page defines the JSON form of a tour lesson page. 105 | type Page struct { 106 | Title string 107 | Content string 108 | Files []File 109 | } 110 | 111 | // Lesson defines the JSON form of a tour lesson. 112 | type Lesson struct { 113 | Title string 114 | Description string 115 | Pages []Page 116 | } 117 | 118 | // parseLesson parses and returns a lesson content given its name and 119 | // the template to render it. 120 | func parseLesson(tmpl *template.Template, path string) ([]byte, error) { 121 | f, err := os.Open(path) 122 | if err != nil { 123 | return nil, err 124 | } 125 | defer f.Close() 126 | doc, err := present.Parse(prepContent(f), path, 0) 127 | if err != nil { 128 | return nil, err 129 | } 130 | 131 | lesson := Lesson{ 132 | doc.Title, 133 | doc.Subtitle, 134 | make([]Page, len(doc.Sections)), 135 | } 136 | 137 | for i, sec := range doc.Sections { 138 | p := &lesson.Pages[i] 139 | w := new(bytes.Buffer) 140 | if err := sec.Render(w, tmpl); err != nil { 141 | return nil, fmt.Errorf("render section: %v", err) 142 | } 143 | p.Title = sec.Title 144 | p.Content = w.String() 145 | codes := findPlayCode(sec) 146 | p.Files = make([]File, len(codes)) 147 | for i, c := range codes { 148 | f := &p.Files[i] 149 | f.Name = c.FileName 150 | f.Content = string(c.Raw) 151 | hash := sha1.Sum(c.Raw) 152 | f.Hash = base64.StdEncoding.EncodeToString(hash[:]) 153 | } 154 | } 155 | 156 | w := new(bytes.Buffer) 157 | if err := json.NewEncoder(w).Encode(lesson); err != nil { 158 | return nil, fmt.Errorf("encode lesson: %v", err) 159 | } 160 | return w.Bytes(), nil 161 | } 162 | 163 | // findPlayCode returns a slide with all the Code elements in the given 164 | // Elem with Play set to true. 165 | func findPlayCode(e present.Elem) []*present.Code { 166 | var r []*present.Code 167 | switch v := e.(type) { 168 | case present.Code: 169 | if v.Play { 170 | r = append(r, &v) 171 | } 172 | case present.Section: 173 | for _, s := range v.Elem { 174 | r = append(r, findPlayCode(s)...) 175 | } 176 | } 177 | return r 178 | } 179 | 180 | // writeLesson writes the tour content to the provided Writer. 181 | func writeLesson(name string, w io.Writer) error { 182 | if uiContent == nil { 183 | panic("writeLesson called before successful initTour") 184 | } 185 | if len(name) == 0 { 186 | return writeAllLessons(w) 187 | } 188 | l, ok := lessons[name] 189 | if !ok { 190 | return lessonNotFound 191 | } 192 | _, err := w.Write(l) 193 | return err 194 | } 195 | 196 | func writeAllLessons(w io.Writer) error { 197 | if _, err := fmt.Fprint(w, "{"); err != nil { 198 | return err 199 | } 200 | nLessons := len(lessons) 201 | for k, v := range lessons { 202 | if _, err := fmt.Fprintf(w, "%q:%s", k, v); err != nil { 203 | return err 204 | } 205 | nLessons-- 206 | if nLessons != 0 { 207 | if _, err := fmt.Fprint(w, ","); err != nil { 208 | return err 209 | } 210 | } 211 | } 212 | _, err := fmt.Fprint(w, "}") 213 | return err 214 | } 215 | 216 | // renderUI writes the tour UI to the provided Writer. 217 | func renderUI(w io.Writer) error { 218 | if uiContent == nil { 219 | panic("renderUI called before successful initTour") 220 | } 221 | _, err := w.Write(uiContent) 222 | return err 223 | } 224 | 225 | // nocode returns true if the provided Section contains 226 | // no Code elements with Play enabled. 227 | func nocode(s present.Section) bool { 228 | for _, e := range s.Elem { 229 | if c, ok := e.(present.Code); ok && c.Play { 230 | return false 231 | } 232 | } 233 | return true 234 | } 235 | 236 | // initScript concatenates all the javascript files needed to render 237 | // the tour UI and serves the result on /script.js. 238 | func initScript(root string) error { 239 | modTime := time.Now() 240 | b := new(bytes.Buffer) 241 | 242 | content, ok := static.Files["playground.js"] 243 | if !ok { 244 | return fmt.Errorf("playground.js not found in static files") 245 | } 246 | b.WriteString(content) 247 | 248 | // Keep this list in dependency order 249 | files := []string{ 250 | "static/lib/jquery.min.js", 251 | "static/lib/jquery-ui.min.js", 252 | "static/lib/angular.min.js", 253 | "static/lib/codemirror/lib/codemirror.js", 254 | "static/lib/codemirror/mode/go/go.js", 255 | "static/lib/angular-ui.min.js", 256 | "static/js/app.js", 257 | "static/js/controllers.js", 258 | "static/js/directives.js", 259 | "static/js/services.js", 260 | "static/js/values.js", 261 | } 262 | 263 | for _, file := range files { 264 | f, err := ioutil.ReadFile(filepath.Join(root, file)) 265 | if err != nil { 266 | return fmt.Errorf("couldn't open %v: %v", file, err) 267 | } 268 | _, err = b.Write(f) 269 | if err != nil { 270 | return fmt.Errorf("error concatenating %v: %v", file, err) 271 | } 272 | } 273 | 274 | http.HandleFunc("/script.js", func(w http.ResponseWriter, r *http.Request) { 275 | w.Header().Set("Content-type", "application/javascript") 276 | // Set expiration time in one week. 277 | w.Header().Set("Cache-control", "max-age=604800") 278 | http.ServeContent(w, r, "", modTime, bytes.NewReader(b.Bytes())) 279 | }) 280 | 281 | return nil 282 | } 283 | -------------------------------------------------------------------------------- /content/basics.article: -------------------------------------------------------------------------------- 1 | Paketler, değişkenler ve fonksiyonlar 2 | Bir programının temel bileşenlerini öğrenin. 3 | 4 | Go Yazarları Sunar 5 | https://golang.org 6 | 7 | * Paketler 8 | 9 | Her Go programı paketlerden oluşur. 10 | 11 | Programlar `main` paketinde çalışmaya başlar. 12 | 13 | Bu örnek program `"fmt"` ve `"math/rand"` paketlerinin yolunu içe aktararak ("import") kullanıyor. 14 | 15 | Geleneksel olarak, paket isimleri import yolunun son elementi ile isimlendirilir. Örneğin, `"math/rand"` paketi, `package`rand` deyimi ile başlayan dosyaları kapsar. 16 | 17 | #appengine: *Not:* Bu programların yürütüldüğü ortamda rastgelelik olmadığı için 18 | #appengine: örnek program her çalıştırıldığında `rand.Intn` aynı sayıyı döndürecektir. 19 | #appengine: 20 | #appengine: (Farklı bir sayı görmek için, sayı üreticisini besleyin; bkz. [[https://golang.org/pkg/math/rand/#Seed][`rand.Seed`]]) 21 | 22 | .play basics/packages.go 23 | 24 | * İçe Aktarımlar 25 | 26 | Bu kod, içe aktarılan paketleri, parantezlenmiş ve parçalara ayrılmış import deyimi şeklinde gruplar. 27 | 28 | Ayrıca çoklu import deyimleri de kullanabilirsiniz: 29 | 30 | import "fmt" 31 | import "math" 32 | 33 | Fakat parçalara ayrılmış import deyimi kullanımı daha güzel bir görünüm sunar. 34 | 35 | .play basics/imports.go 36 | 37 | * Dışa Aktarılan İsimler 38 | 39 | Go'da, dışa aktarılmış bir isim büyük harf ile başlar. 40 | Örneğin, `Pizza` dışa aktarılmış bir isimdir, tıpkı `math` paketi tarafından ithal edilen `Pi` gibi. 41 | 42 | `pizza` ve `pi` büyük harfle başlamadığından dışa aktarılan isimler değildir. 43 | 44 | Bir paket içe aktarıldığında, pakette sadece dışa aktarılmış isimleri kullanabilirsiniz. 45 | "Dışa aktarılmamış" isimler paketin dışından erişilemez. 46 | 47 | Yandaki kodu çalıştırın. Hata iletisine dikkat edin. 48 | 49 | Hatayı düzeltmek için `math.pi` yi `math.Pi` şeklinde değiştirip yeniden çalıştırın. 50 | 51 | .play basics/exported-names.go 52 | 53 | * Fonksiyonlar 54 | 55 | Bir fonksiyon bir veya birden fazla sayıda argüman alabileceği gibi hiç argüman almayabilir. 56 | 57 | Bu örnekte, `add` fonksiyonu `int` türünde iki parametre alıyor. 58 | 59 | Değişken türünün değişken adından _sonra_ geldiğine dikkat edin. 60 | 61 | (Değişken türlerinin neden bu şekilde tanımlandıkları hakkında daha fazla bilgi için; [[https://blog.golang.org/gos-declaration-syntax][Go dilinde bildirim sözdizimi]] makalesine bakın.) 62 | 63 | .play basics/functions.go 64 | 65 | * Fonksiyonlar devam 66 | 67 | İki ya da daha fazla ardışık fonksiyon parametresi aynı türde ise tür bilgisini, en sonda bulunan hariç, diğer parametreler için belirtmeseniz de olur. 68 | 69 | Bu örnekte 70 | 71 | x int, y int 72 | 73 | fonksiyon parametrelerini şöyle kısalttık: 74 | 75 | x, y int 76 | 77 | .play basics/functions-continued.go 78 | 79 | * Çoklu sonuçlar 80 | 81 | Bir fonksiyon herhangi bir sayıda sonuç döndürebilir. 82 | 83 | Örnekteki `swap` fonksiyonu, dizgi ("string") türünde iki sonuç döndürüyor. 84 | 85 | .play basics/multiple-results.go 86 | 87 | * Adlandırılmış sonuçlar 88 | 89 | Go'nun sonuç değerleri aynı bir değişken gibi adlandırılabilir. Böyle yapıldığında değişken sanki fonksiyonun başında tanımlanmış gibi muamele görür. 90 | 91 | Sonuçlar manalarına, işlevlerine göre adlandırılmalıdır. 92 | 93 | Argümansız bir `return` deyimi adlandırılmış sonuç değerlerini döndürür. Bu "çıplak" return olarak bilinir. 94 | 95 | Çıplak return deyimleri, aynı örnekteki gibi, sadece kısa fonksiyonlarda kullanılmalıdır. Uzun fonksiyonlarda kullanılırlarsa kodun okunabilirliğini azaltırlar. 96 | 97 | .play basics/named-results.go 98 | 99 | * Değişkenler 100 | 101 | `var` deyimi değişkenler tanımlamaya yarar. Ve tıpkı fonksiyon argümanlarında olduğu gibi tür bilgisi sona yazılır. 102 | 103 | `var` deyimi paket veya fonksiyon düzeyinde olabilir. Biz bu örnekte ikisini de görüyoruz. 104 | 105 | .play basics/variables.go 106 | 107 | * Değişkenleri ilklendirme 108 | 109 | Bir `var` deyimi her bir değişken için bir ilklendirme değeri içerebilir. 110 | 111 | Eğer bir ilklendirme mevcut ise tür tanımlaması atlanabilir. Bu halde değişken, ilklendirme değeri ile aynı türde olacaktır. 112 | 113 | .play basics/variables-with-initializers.go 114 | 115 | * Kısaltılmış değişken bildirimleri 116 | 117 | Bir fonksiyon içerisinde, türü belirtilmiş bir `var` bildirimi yerine `:=` kısa atama deyimi kullanılabilir. 118 | 119 | Fonksiyon alanının dışında, her yapı bir anahtar kelime (`var`, `func` vs.) ile başlar ve `:=` yapısını kullanmak mümkün değildir. 120 | 121 | .play basics/short-variable-declarations.go 122 | 123 | * Basit türler 124 | 125 | Go'nun basit türleri şunlardır 126 | 127 | bool 128 | 129 | string 130 | 131 | int int8 int16 int32 int64 132 | uint uint8 uint16 uint32 uint64 uintptr 133 | 134 | byte // diğer adıyla uint8 135 | 136 | rune // diğer adıyla int32 137 | // Unicode karakter kodlarını ifade eder 138 | 139 | float32 float64 140 | 141 | complex64 complex128 142 | 143 | Bu örnekte birçok çeşit türden değişken tanımlanmıştır. 144 | Değişken tanımlamaları, import deyiminde de, olduğu gibi bloklara ayrılmış olarak yapılabilir. 145 | 146 | `int`, `uint` ve `uintptr` veri türleri genellikle 32-bit sistemlerde 32 bit, 64-bit sistemlerde 64 bit genişliğindedir. 147 | Bir tamsayı değeri gerektiğinde, boyutlandırılmış veya işaretsiz bir tamsayı türü kullanmanızı gerektiren özel bir neden olmadığı sürece `int` kullanmalısınız. 148 | 149 | .play basics/basic-types.go 150 | 151 | * Sıfır değerleri 152 | 153 | İlklendirilmemiş her değişken başlangıç değeri olarak kendi "sıfır değeri"ni alır. 154 | 155 | Sıfır değerleri şunlardır: 156 | 157 | - Sayı türleri için `0`, 158 | - Mantıksal (boolean) tür için `false` 159 | - Dizgi (string) türü için `""` (boş dizgi) 160 | 161 | .play basics/zero.go 162 | 163 | * Tür dönüşümleri 164 | 165 | `T(v)` ifadesi `v` değerini `T` türüne dönüştürür. 166 | 167 | Bazı sayısal dönüşümler: 168 | 169 | var i int = 42 170 | var f float64 = float64(i) 171 | var u uint = uint(f) 172 | 173 | Veya basitçesi: 174 | 175 | i := 42 176 | f := float64(i) 177 | u := uint(f) 178 | 179 | Go'da türdeş olmayan ögeler arasında gerçekleşen atamalarda, C dilinden farklı olarak, açık dönüşüm yapılması gerekir. 180 | Örnekteki `float64` veya `uint` dönüşümlerini kaldırmayı deneyin ve ne olduğunu gözlemleyin. 181 | 182 | .play basics/type-conversions.go 183 | 184 | * Tür çıkarımı 185 | 186 | Eğer bir değişken türü belirtilmeden tanımlanırsa (yani `:=` sözdizimi veya `var` ifade sözdizimi kullanılarak), değişkenin türünü sağ taraftaki değer belirler. 187 | 188 | Tanımlamanın sağ tarafı türü belirli olan bir değişken ise, yeni değişkenimiz bu tür ile aynı türe sahip olur: 189 | 190 | var i int 191 | j := i // j int türünden olur 192 | 193 | Fakat sağ taraf türü belirtilmemiş bir sayısal sabit ise, yeni değişken sabitin hassasiyet seviyesine göre `int`, `float64` veya `complex128` türlerinden biri olarak belirlenir: 194 | 195 | i := 42 // int 196 | f := 3.142 // float64 197 | g := 0.867 + 0.5i // complex128 198 | 199 | Örnek koddaki `v` değerinin başlangıç değerini değiştirin ve girdiğiniz değerlerin türün belirlenmesindeki etkisini gözlemleyin. 200 | 201 | .play basics/type-inference.go 202 | 203 | * Sabitler 204 | 205 | Sabitler de değişkenler ile aynı şekilde bildirilir ancak sabitler bildirilirken `const` anahtar kelimesi kullanılır. 206 | 207 | Sabitler; karakter, dizgi ("string"), mantıksal ("boolean") ya da sayısal değerler alabilir. 208 | 209 | Sabitler `:=` operatörü kullanılarak bildirilemezler. 210 | 211 | .play basics/constants.go 212 | 213 | * Sayısal Sabitler 214 | 215 | Sayısal sabitler yüksek hassasiyetli _değerlerdir_. 216 | 217 | Tür bilgisi olmayan bir sabit, bağlamının gerektirdiği "tür"den olur. 218 | 219 | `needInt(Big)` yazdırmayı da deneyin. 220 | 221 | (Bir `int` en fazla 64 bit genişliğinde bir tamsayı depolar. Genişlik bazen bunun da altındadır.) 222 | 223 | .play basics/numeric-constants.go 224 | 225 | * Tebrikler! 226 | 227 | Bu dersin sonuna geldiniz! 228 | 229 | Daha neler öğreneceğinizi görmek için [[/list][bölüm listesine]] geri dönün ya da [[javascript:click('.next-page')][bir sonraki derse]] geçin. 230 | -------------------------------------------------------------------------------- /static/js/services.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 The Go Authors. All rights reserved. 2 | * Use of this source code is governed by a BSD-style 3 | * license that can be found in the LICENSE file. 4 | */ 5 | 'use strict'; 6 | 7 | /* Services */ 8 | 9 | angular.module('tour.services', []). 10 | 11 | // Google Analytics 12 | factory('analytics', ['$window', 13 | function(win) { 14 | var track = win.trackPageview || (function() {}); 15 | return { 16 | trackView: track 17 | }; 18 | } 19 | ]). 20 | 21 | // Internationalization 22 | factory('i18n', ['translation', 23 | function(translation) { 24 | return { 25 | l: function(key) { 26 | if (translation[key]) return translation[key]; 27 | return '(no translation for ' + key + ')'; 28 | } 29 | }; 30 | } 31 | ]). 32 | 33 | // Running code 34 | factory('run', ['$window', 'editor', 35 | function(win, editor) { 36 | var writeInterceptor = function(writer, done) { 37 | return function(write) { 38 | if (write.Kind == 'stderr') { 39 | var lines = write.Body.split('\n'); 40 | for (var i in lines) { 41 | var match = lines[i].match(/.*\.go:([0-9]+): ([^\n]*)/); 42 | if (match !== null) { 43 | editor.highlight(match[1], match[2]); 44 | } 45 | } 46 | } 47 | writer(write); 48 | if (write.Kind == 'end') done(); 49 | }; 50 | }; 51 | return function(code, output, options, done) { 52 | // PlaygroundOutput is defined in playground.js which is prepended 53 | // to the generated script.js in gotour/tour.go. 54 | // The next line removes the jshint warning. 55 | // global PlaygroundOutput 56 | return win.transport.Run(code, writeInterceptor(PlaygroundOutput(output), done), options); 57 | }; 58 | } 59 | ]). 60 | 61 | // Formatting code 62 | factory('fmt', ['$http', 63 | function($http) { 64 | return function(body) { 65 | var params = $.param({ 66 | 'body': body 67 | }); 68 | var headers = { 69 | 'Content-Type': 'application/x-www-form-urlencoded' 70 | }; 71 | return $http.post('/fmt', params, { 72 | headers: headers 73 | }); 74 | }; 75 | } 76 | ]). 77 | 78 | // Local storage, persistent to page refreshing. 79 | factory('storage', ['$window', 80 | function(win) { 81 | try { 82 | // This will raise an exception if cookies are disabled. 83 | win.localStorage = win.localStorage; 84 | return { 85 | get: function(key) { 86 | return win.localStorage.getItem(key); 87 | }, 88 | set: function(key, val) { 89 | win.localStorage.setItem(key, val); 90 | } 91 | }; 92 | } catch (e) { 93 | return { 94 | get: function() { 95 | return null; 96 | }, 97 | set: function() {} 98 | }; 99 | } 100 | } 101 | ]). 102 | 103 | // Editor context service, kept through the whole app. 104 | factory('editor', ['$window', 'storage', 105 | function(win, storage) { 106 | var ctx = { 107 | syntax: storage.get('syntax') === 'true', 108 | toggleSyntax: function() { 109 | ctx.syntax = !ctx.syntax; 110 | storage.set('syntax', ctx.syntax); 111 | ctx.paint(); 112 | }, 113 | paint: function() { 114 | var mode = ctx.syntax && 'text/x-go' || 'text/x-go-comment'; 115 | // Wait for codemirror to start. 116 | var set = function() { 117 | if ($('.CodeMirror').length > 0) { 118 | var cm = $('.CodeMirror')[0].CodeMirror; 119 | if (cm.getOption('mode') == mode) { 120 | cm.refresh(); 121 | return; 122 | } 123 | cm.setOption('mode', mode); 124 | } 125 | win.setTimeout(set, 10); 126 | }; 127 | set(); 128 | }, 129 | highlight: function(line, message) { 130 | $('.CodeMirror-code > div:nth-child(' + line + ')') 131 | .addClass('line-error').attr('title', message); 132 | }, 133 | onChange: function() { 134 | $('.line-error').removeClass('line-error').attr('title', null); 135 | } 136 | }; 137 | // Set in the window so the onChange function in the codemirror config 138 | // can call it. 139 | win.codeChanged = ctx.onChange; 140 | return ctx; 141 | } 142 | ]). 143 | 144 | // Table of contents management and navigation 145 | factory('toc', ['$http', '$q', '$log', 'tableOfContents', 'storage', 146 | function($http, $q, $log, tableOfContents, storage) { 147 | var modules = tableOfContents; 148 | 149 | var lessons = {}; 150 | 151 | var prevLesson = function(id) { 152 | var mod = lessons[id].module; 153 | var idx = mod.lessons.indexOf(id); 154 | if (idx < 0) return ''; 155 | if (idx > 0) return mod.lessons[idx - 1]; 156 | 157 | idx = modules.indexOf(mod); 158 | if (idx <= 0) return ''; 159 | mod = modules[idx - 1]; 160 | return mod.lessons[mod.lessons.length - 1]; 161 | }; 162 | 163 | var nextLesson = function(id) { 164 | var mod = lessons[id].module; 165 | var idx = mod.lessons.indexOf(id); 166 | if (idx < 0) return ''; 167 | if (idx + 1 < mod.lessons.length) return mod.lessons[idx + 1]; 168 | 169 | idx = modules.indexOf(mod); 170 | if (idx < 0 || modules.length <= idx + 1) return ''; 171 | mod = modules[idx + 1]; 172 | return mod.lessons[0]; 173 | }; 174 | 175 | $http.get('/lesson/').then( 176 | function(data) { 177 | lessons = data.data; 178 | for (var m = 0; m < modules.length; m++) { 179 | var module = modules[m]; 180 | module.lesson = {}; 181 | for (var l = 0; l < modules[m].lessons.length; l++) { 182 | var lessonName = module.lessons[l]; 183 | var lesson = lessons[lessonName]; 184 | lesson.module = module; 185 | module.lesson[lessonName] = lesson; 186 | 187 | // replace file contents with locally stored copies. 188 | for (var p = 0; p < lesson.Pages.length; p++) { 189 | var page = lesson.Pages[p]; 190 | for (var f = 0; f < page.Files.length; f++) { 191 | page.Files[f].OrigContent = page.Files[f].Content; 192 | var val = storage.get(page.Files[f].Hash); 193 | if (val !== null) { 194 | page.Files[f].Content = val; 195 | } 196 | } 197 | } 198 | } 199 | } 200 | moduleQ.resolve(modules); 201 | lessonQ.resolve(lessons); 202 | }, 203 | function(error) { 204 | $log.error('error loading lessons : ', error); 205 | moduleQ.reject(error); 206 | lessonQ.reject(error); 207 | } 208 | ); 209 | 210 | var moduleQ = $q.defer(); 211 | var lessonQ = $q.defer(); 212 | 213 | return { 214 | modules: moduleQ.promise, 215 | lessons: lessonQ.promise, 216 | prevLesson: prevLesson, 217 | nextLesson: nextLesson 218 | }; 219 | } 220 | ]); 221 | -------------------------------------------------------------------------------- /static/js/directives.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 The Go Authors. All rights reserved. 2 | * Use of this source code is governed by a BSD-style 3 | * license that can be found in the LICENSE file. 4 | */ 5 | 'use strict'; 6 | 7 | /* Directives */ 8 | 9 | angular.module('tour.directives', []). 10 | 11 | // onpageup executes the given expression when Page Up is released. 12 | directive('onpageup', function() { 13 | return function(scope, elm, attrs) { 14 | elm.attr('tabindex', 0); 15 | elm.keyup(function(evt) { 16 | var key = evt.which || evt.keyCode; 17 | if (key == 33 && !evt.ctrlKey) { 18 | scope.$apply(attrs.onpageup); 19 | evt.preventDefault(); 20 | } 21 | }); 22 | }; 23 | }). 24 | 25 | // onpagedown executes the given expression when Page Down is released. 26 | directive('onpagedown', function() { 27 | return function(scope, elm, attrs) { 28 | elm.attr('tabindex', 0); 29 | elm.keyup(function(evt) { 30 | var key = evt.which || evt.keyCode; 31 | if (key == 34 && !evt.ctrlKey) { 32 | scope.$apply(attrs.onpagedown); 33 | evt.preventDefault(); 34 | } 35 | }); 36 | }; 37 | }). 38 | 39 | // autofocus sets the focus on the given element when the condition is true. 40 | directive('autofocus', function() { 41 | return function(scope, elm, attrs) { 42 | elm.attr('tabindex', 0); 43 | scope.$watch(function() { 44 | return scope.$eval(attrs.autofocus); 45 | }, function(val) { 46 | if (val === true) $(elm).focus(); 47 | }); 48 | }; 49 | }). 50 | 51 | // syntax-checkbox activates and deactivates 52 | directive('syntaxCheckbox', ['editor', 53 | function(editor) { 54 | return function(scope, elm) { 55 | elm.click(function() { 56 | editor.toggleSyntax(); 57 | scope.$digest(); 58 | }); 59 | scope.editor = editor; 60 | }; 61 | } 62 | ]). 63 | 64 | // verticalSlide creates a sliding separator between the left and right elements. 65 | // e.g.: 66 | //