diff --git a/content/flowcontrol/for-continued.go b/content/flowcontrol/for-continued.go index 5f6fce4..71c9686 100644 --- a/content/flowcontrol/for-continued.go +++ b/content/flowcontrol/for-continued.go @@ -6,7 +6,7 @@ import "fmt" func main() { sum := 1 - for sum < 1000 { + for ; sum < 1000; { sum += sum } fmt.Println(sum) diff --git a/content/methods/exercise-reader.go b/content/methods/exercise-reader.go index 7428ae9..b68157e 100644 --- a/content/methods/exercise-reader.go +++ b/content/methods/exercise-reader.go @@ -4,7 +4,7 @@ import "code.google.com/p/go-tour/reader" type MyReader struct{} -// TODO: Add a Read(byte) (int, error) method to MyReader. +// TODO: Add a Read([]byte) (int, error) method to MyReader. func main() { reader.Validate(MyReader{}) diff --git a/content/welcome.article b/content/welcome.article index 136535d..6502d57 100644 --- a/content/welcome.article +++ b/content/welcome.article @@ -69,7 +69,7 @@ http://golang.org #appengine: #appengine: - 在 Playground 中,时间从 2009-11-10 23:00:00 UTC(了解这个日期的重要含义是留给读者的练习)。这使得根据可预见的输出来缓存程序变得容易。 #appengine: -#appengine: - 对于运行时间、CPU 和内存的使用同样也有限制,并且程序是限制单一线程运行(但是可以有多个 goroutine)。 +#appengine: - 对于运行时间、CPU 和内存的使用同样也有限制,并且程序不能访问外部网络中的主机。 #appengine: #appengine: Playground 使用最后发布的 Go 的稳定版本。 #appengine: diff --git a/gotour/appengine.go b/gotour/appengine.go index 0fdc19c..45a8394 100644 --- a/gotour/appengine.go +++ b/gotour/appengine.go @@ -15,7 +15,7 @@ import ( "appengine" - _ "code.google.com/p/go.tools/playground" + _ "golang.org/x/tools/playground" ) const runUrl = "http://golang.org/compile" diff --git a/gotour/local.go b/gotour/local.go index 3fdb0dd..f9ef837 100644 --- a/gotour/local.go +++ b/gotour/local.go @@ -22,8 +22,8 @@ import ( "strings" "time" - "code.google.com/p/go.tools/playground/socket" - + "golang.org/x/tools/playground/socket" + // Imports so that go build/install automatically installs them. _ "bitbucket.org/mikespook/go-tour-zh/pic" _ "bitbucket.org/mikespook/go-tour-zh/tree" @@ -41,7 +41,6 @@ var ( ) var ( - // GOPATH containing the tour packages gopath = os.Getenv("GOPATH") @@ -77,12 +76,12 @@ func findRoot() (string, error) { func main() { flag.Parse() - // find and serve the go tour files root, err := findRoot() if err != nil { log.Fatalf("Couldn't find tour files: %v", err) } + log.Println("Serving content from", root) host, port, err := net.SplitHostPort(*httpListen) @@ -170,10 +169,9 @@ func init() { func environ() (env []string) { for _, v := range os.Environ() { if !strings.HasPrefix(v, "GOPATH=") { - env = append(env, v) + env = append(env, v) } } - env = append(env, "GOPATH="+gopath) return } diff --git a/gotour/tour.go b/gotour/tour.go index a2bad1c..4957bae 100644 --- a/gotour/tour.go +++ b/gotour/tour.go @@ -17,8 +17,8 @@ import ( "strings" "time" - "code.google.com/p/go.tools/godoc/static" - "code.google.com/p/go.tools/present" + "golang.org/x/tools/godoc/static" + "golang.org/x/tools/present" ) var ( diff --git a/static/css/app.css b/static/css/app.css index 06deff0..1158d7c 100755 --- a/static/css/app.css +++ b/static/css/app.css @@ -259,6 +259,13 @@ ul { font-family:'Inconsolata', monospace; line-height: 1.2em; } +.CodeMirror-code > .line-error { + background: #FF8080; +} +.CodeMirror-code > .line-error .CodeMirror-linenumber { + color: #FF5555; + font-weight: bolder; +} #file-editor .CodeMirror-gutters { width: 32px; } diff --git a/static/js/services.js b/static/js/services.js index fa2e55a..c507af2 100755 --- a/static/js/services.js +++ b/static/js/services.js @@ -31,14 +31,28 @@ factory('i18n', ['translation', ]). // Running code -factory('run', ['$window', - function(win) { +factory('run', ['$window', 'editor', + function(win, editor) { + var writeInterceptor = function(writer) { + return function(write) { + if (write.Kind == 'stderr') { + var lines = write.Body.split('\n'); + for (var i in lines) { + var match = lines[i].match(/.*\.go:([0-9]+): ([^\n]*)/); + if (match !== null) { + editor.highlight(match[1], match[2]); + } + } + } + writer(write); + }; + }; return function(code, output, options) { // 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. // global PlaygroundOutput - win.transport.Run(code, PlaygroundOutput(output), options); + win.transport.Run(code, writeInterceptor(PlaygroundOutput(output)), options); }; } ]). @@ -108,7 +122,17 @@ factory('editor', ['$window', 'storage', }; set(); }, + highlight: function(line, message) { + $('.CodeMirror-code > div:nth-child(' + line + ')') + .addClass('line-error').attr('title', message); + }, + onChange: function() { + $('.line-error').removeClass('line-error').attr('title', null); + } }; + // Set in the window so the onChange function in the codemirror config + // can call it. + win.codeChanged = ctx.onChange; return ctx; } ]). @@ -171,7 +195,8 @@ factory('toc', ['$http', '$q', '$log', 'tableOfContents', 'storage', } moduleQ.resolve(modules); lessonQ.resolve(lessons); - }, function(error) { + }, + function(error) { $log.error('error loading lessons : ', error); moduleQ.reject(error); lessonQ.reject(error); diff --git a/static/js/values.js b/static/js/values.js index e127f3a..f45f503 100644 --- a/static/js/values.js +++ b/static/js/values.js @@ -72,6 +72,11 @@ value('ui.config', { 'PageUp': function() { return false; }, + }, + // TODO: is there a better way to do this? + // AngularJS values can't depend on factories. + onChange: function() { + if (window.codeChanged !== null) window.codeChanged(); } } });