Skip to content

Commit

Permalink
primeira versão traduzida
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Vargas committed Jul 18, 2012
0 parents commit 8982a2d
Show file tree
Hide file tree
Showing 71 changed files with 6,877 additions and 0 deletions.
Binary file added .hg/00changelog.i
Binary file not shown.
1 change: 1 addition & 0 deletions .hg/branch
@@ -0,0 +1 @@
default
2 changes: 2 additions & 0 deletions .hg/cache/branchheads
@@ -0,0 +1,2 @@
ca1c030f0dfbc502d98a8de2f6c8cc2eb31015b5 68
ca1c030f0dfbc502d98a8de2f6c8cc2eb31015b5 default
3 changes: 3 additions & 0 deletions .hg/cache/tags
@@ -0,0 +1,3 @@
68 ca1c030f0dfbc502d98a8de2f6c8cc2eb31015b5 9326940580ddc2dff15d11388956b335b7c492a1

dd4b1d7bebbd608f280c15b2fe76d9da3ac91c10 go.r60
Binary file added .hg/dirstate
Binary file not shown.
2 changes: 2 additions & 0 deletions .hg/hgrc
@@ -0,0 +1,2 @@
[paths]
default = https://code.google.com/p/go-tour
4 changes: 4 additions & 0 deletions .hg/requires
@@ -0,0 +1,4 @@
revlogv1
fncache
store
dotencode
Binary file added .hg/store/00changelog.i
Binary file not shown.
Binary file added .hg/store/00manifest.i
Binary file not shown.
Binary file added .hg/store/data/_a_u_t_h_o_r_s.i
Binary file not shown.
Binary file added .hg/store/data/_c_o_n_t_r_i_b_u_t_o_r_s.i
Binary file not shown.
Binary file added .hg/store/data/_l_i_c_e_n_s_e.i
Binary file not shown.
Binary file added .hg/store/data/_r_e_a_d_m_e.i
Binary file not shown.
Binary file added .hg/store/data/appengine/_r_e_a_d_m_e.i
Binary file not shown.
Binary file added .hg/store/data/appengine/app.yaml.i
Binary file not shown.
Binary file added .hg/store/data/appengine/goplay/compile.go.i
Binary file not shown.
Binary file added .hg/store/data/codereview.cfg.i
Binary file not shown.
Binary file added .hg/store/data/gotour/goplay.go.i
Binary file not shown.
Binary file added .hg/store/data/gotour/local.go.i
Binary file not shown.
Binary file added .hg/store/data/lib/codereview/codereview.cfg.i
Binary file not shown.
Binary file added .hg/store/data/pic/pic.go.i
Binary file not shown.
Binary file added .hg/store/data/static/codemirror/_l_i_c_e_n_s_e.i
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .hg/store/data/static/codemirror/lib/overlay.js.i
Binary file not shown.
Binary file added .hg/store/data/static/codemirror/lib/runmode.js.i
Binary file not shown.
Binary file added .hg/store/data/static/codemirror/theme/default.css.i
Binary file not shown.
Binary file added .hg/store/data/static/favicon.ico.i
Binary file not shown.
Binary file added .hg/store/data/static/fig4.png.i
Binary file not shown.
Binary file added .hg/store/data/static/index.html.i
Binary file not shown.
Binary file added .hg/store/data/static/jquery.js.i
Binary file not shown.
Binary file added .hg/store/data/static/mode.js.i
Binary file not shown.
Binary file added .hg/store/data/static/playground.js.i
Binary file not shown.
Binary file added .hg/store/data/static/tour.css.i
Binary file not shown.
Binary file added .hg/store/data/static/tour.js.i
Binary file not shown.
Binary file not shown.
Binary file added .hg/store/data/tree/tree.go.i
Binary file not shown.
Binary file added .hg/store/data/wc/wc.go.i
Binary file not shown.
Binary file added .hg/store/data/~2ehgtags.i
Binary file not shown.
30 changes: 30 additions & 0 deletions .hg/store/fncache
@@ -0,0 +1,30 @@
data/gotour/goplay.go.i
data/appengine/app.yaml.i
data/AUTHORS.i
data/CONTRIBUTORS.i
data/static/codemirror/lib/codemirror.css.i
data/static/favicon.ico.i
data/talks/2012-04-25-NewYorkMeetup/index.html.i
data/codereview.cfg.i
data/wc/wc.go.i
data/gotour/local.go.i
data/static/mode.js.i
data/lib/codereview/codereview.cfg.i
data/LICENSE.i
data/static/fig4.png.i
data/static/jquery.js.i
data/static/codemirror/theme/default.css.i
data/appengine/goplay/compile.go.i
data/appengine/README.i
data/tree/tree.go.i
data/static/codemirror/lib/codemirror.js.i
data/static/index.html.i
data/static/playground.js.i
data/static/codemirror/lib/overlay.js.i
data/static/codemirror/lib/runmode.js.i
data/static/tour.css.i
data/.hgtags.i
data/README.i
data/static/codemirror/LICENSE.i
data/static/tour.js.i
data/pic/pic.go.i
Binary file added .hg/store/undo
Binary file not shown.
Empty file added .hg/undo.bookmarks
Empty file.
1 change: 1 addition & 0 deletions .hg/undo.branch
@@ -0,0 +1 @@
default
3 changes: 3 additions & 0 deletions .hg/undo.desc
@@ -0,0 +1,3 @@
0
pull
https://code.google.com/p/go-tour
Empty file added .hg/undo.dirstate
Empty file.
1 change: 1 addition & 0 deletions .hgtags
@@ -0,0 +1 @@
dd4b1d7bebbd608f280c15b2fe76d9da3ac91c10 go.r60
3 changes: 3 additions & 0 deletions AUTHORS
@@ -0,0 +1,3 @@
# This source code refers to The Go Authors for copyright purposes.
# The master list of authors is in the main Go distribution,
# visible at http://tip.golang.org/AUTHORS.
3 changes: 3 additions & 0 deletions CONTRIBUTORS
@@ -0,0 +1,3 @@
# This source code was written by the Go contributors.
# The master list of contributors is in the main Go distribution,
# visible at http://tip.golang.org/CONTRIBUTORS.
27 changes: 27 additions & 0 deletions LICENSE
@@ -0,0 +1,27 @@
Copyright (c) 2011 The Go Tour Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6 changes: 6 additions & 0 deletions README
@@ -0,0 +1,6 @@
Este é um Passeio por Go, uma introdução à linguagem de programação Go.

Salvo disposições em contrário, os arquivos de código-fonte do Passeio por Go são distribuídos sob a licença BSD encontrada no arquivo de LICENSE.

As contribuições devem seguir o mesmo procedimento para o projeto Go:
http://golang.org/doc/contribute.html
2 changes: 2 additions & 0 deletions codereview.cfg
@@ -0,0 +1,2 @@
defaultcc: golang-dev@googlegroups.com
contributors: http://go.googlecode.com/hg/CONTRIBUTORS
37 changes: 37 additions & 0 deletions gotour/goplay.go
@@ -0,0 +1,37 @@
// Copyright 2010 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 main

import (
"encoding/json"
"log"
"net/http"
)

func init() {
http.HandleFunc("/compile", Compile)
}

type Response struct {
Output string `json:"output"`
Errors string `json:"compile_errors"`
}

func Compile(w http.ResponseWriter, req *http.Request) {
resp := new(Response)
out, err := compile(req)
if err != nil {
if len(out) > 0 {
resp.Errors = string(out) + "\n" + err.Error()
} else {
resp.Errors = err.Error()
}
} else {
resp.Output = string(out)
}
if err := json.NewEncoder(w).Encode(resp); err != nil {
log.Println(err)
}
}
192 changes: 192 additions & 0 deletions gotour/local.go
@@ -0,0 +1,192 @@
// 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 main

import (
"bytes"
"flag"
"fmt"
"go/build"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"sync"

// Imports so that goinstall automatically installs them.
_ "code.google.com/p/go-tour/pic"
_ "code.google.com/p/go-tour/tree"
_ "code.google.com/p/go-tour/wc"
)

const basePkg = "code.google.com/p/go-tour/"

var (
httpListen = flag.String("http", "127.0.0.1:3999", "host:port to listen on")
htmlOutput = flag.Bool("html", false, "render program output as HTML")
)

var (
// a source of numbers, for naming temporary files
uniq = make(chan int)
)

func main() {
flag.Parse()

// source of unique numbers
go func() {
for i := 0; ; i++ {
uniq <- i
}
}()

// find and serve the go tour files
p, err := build.Default.Import(basePkg, "", build.FindOnly)
if err != nil {
log.Fatalf("Couldn't find tour files: %v", err)
}
root := p.Dir
log.Println("Serving content from", root)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/favicon.ico" || r.URL.Path == "/" {
fn := filepath.Join(root, "static", r.URL.Path[1:])
http.ServeFile(w, r, fn)
return
}
http.Error(w, "not found", 404)
})
http.Handle("/static/", http.FileServer(http.Dir(root)))
http.Handle("/talks/", http.FileServer(http.Dir(root)))
http.HandleFunc("/kill", kill)

if !strings.HasPrefix(*httpListen, "127.0.0.1") &&
!strings.HasPrefix(*httpListen, "localhost") {
log.Print(localhostWarning)
}

log.Printf("Open your web browser and visit http://%s/", *httpListen)
log.Fatal(http.ListenAndServe(*httpListen, nil))
}

const localhostWarning = `
WARNING! WARNING! WARNING!
I appear to be listening on an address that is not localhost.
Anyone with access to this address and port will have access
to this machine as the user running gotour.
If you don't understand this message, hit Control-C to terminate this process.
WARNING! WARNING! WARNING!
`

var running struct {
sync.Mutex
cmd *exec.Cmd
}

func stopRun() {
running.Lock()
if running.cmd != nil {
running.cmd.Process.Kill()
running.cmd = nil
}
running.Unlock()
}

func kill(w http.ResponseWriter, r *http.Request) {
stopRun()
}

var (
commentRe = regexp.MustCompile(`(?m)^#.*\n`)
tmpdir string
)

func init() {
// find real temporary directory (for rewriting filename in output)
var err error
tmpdir, err = filepath.EvalSymlinks(os.TempDir())
if err != nil {
log.Fatal(err)
}
}

func compile(req *http.Request) (out []byte, err error) {
stopRun()

// x is the base name for .go, .6, executable files
x := filepath.Join(tmpdir, "compile"+strconv.Itoa(<-uniq))
src := x + ".go"
bin := x
if runtime.GOOS == "windows" {
bin += ".exe"
}

// rewrite filename in error output
defer func() {
if err != nil {
// drop messages from the go tool like '# _/compile0'
out = commentRe.ReplaceAll(out, nil)
}
out = bytes.Replace(out, []byte(src+":"), []byte("main.go:"), -1)
}()

// write body to x.go
body := []byte(req.FormValue("body"))
defer os.Remove(src)
if err = ioutil.WriteFile(src, body, 0666); err != nil {
return
}

// build x.go, creating x
dir, file := filepath.Split(src)
out, err = run(dir, "go", "build", "-o", bin, file)
defer os.Remove(bin)
if err != nil {
return
}

// run x
return run("", bin)
}

// run executes the specified command and returns its output and an error.
func run(dir string, args ...string) ([]byte, error) {
var buf bytes.Buffer
cmd := exec.Command(args[0], args[1:]...)
cmd.Dir = dir
cmd.Stdout = &buf
cmd.Stderr = cmd.Stdout

// Start command and leave in 'running'.
running.Lock()
if running.cmd != nil {
defer running.Unlock()
return nil, fmt.Errorf("already running %s", running.cmd.Path)
}
if err := cmd.Start(); err != nil {
running.Unlock()
return nil, err
}
running.cmd = cmd
running.Unlock()

// Wait for the command. Clean up,
err := cmd.Wait()
running.Lock()
if running.cmd == cmd {
running.cmd = nil
}
running.Unlock()
return buf.Bytes(), err
}
40 changes: 40 additions & 0 deletions pic/pic.go
@@ -0,0 +1,40 @@
// 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

import (
"bytes"
"encoding/base64"
"fmt"
"image"
"image/png"
)

func Show(f func(int, int) [][]uint8) {
const (
dx = 256
dy = 256
)
data := f(dx, dy)
m := image.NewNRGBA(image.Rect(0, 0, dx, dy))
for y := 0; y < dy; y++ {
for x := 0; x < dx; x++ {
v := data[y][x]
i := y*m.Stride + x*4
m.Pix[i] = v
m.Pix[i+1] = v
m.Pix[i+2] = 255
m.Pix[i+3] = 255
}
}
ShowImage(m)
}

func ShowImage(m image.Image) {
var buf bytes.Buffer
png.Encode(&buf, m)
enc := base64.StdEncoding.EncodeToString(buf.Bytes())
fmt.Println("IMAGE:" + enc)
}
19 changes: 19 additions & 0 deletions static/codemirror/LICENSE
@@ -0,0 +1,19 @@
Copyright (C) 2011 by Marijn Haverbeke <marijnh@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

0 comments on commit 8982a2d

Please sign in to comment.