Преглед на файлове

add hello world (cli & web) examples for go and ruby.

Lucas Stadler преди 11 години
родител
ревизия
e9aa2c4ff2
променени са 5 файла, в които са добавени 40 реда и са изтрити 1 реда
  1. 4 1
      go/.gitignore
  2. 7 0
      go/examples/hello.go
  3. 1 0
      go/examples/hello.rb
  4. 17 0
      go/examples/hello_web.go
  5. 11 0
      go/examples/hello_web.rb

+ 4 - 1
go/.gitignore

@ -1,3 +1,6 @@
1 1
.go
2 2
3
qst
3
qst
4
5
examples/hello
6
examples/hello_web

+ 7 - 0
go/examples/hello.go

@ -0,0 +1,7 @@
1
package main
2
3
import "fmt"
4
5
func main() {
6
	fmt.Println("Hello, World!")
7
}

+ 1 - 0
go/examples/hello.rb

@ -0,0 +1 @@
1
puts "Hello, World!"

+ 17 - 0
go/examples/hello_web.go

@ -0,0 +1,17 @@
1
package main
2
3
import "fmt"
4
import "net/http"
5
6
func main() {
7
	http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
8
		name := req.URL.Path[1:]
9
		if name == "" {
10
			name = "World"
11
		}
12
		w.Write([]byte(fmt.Sprintf("Hello, %s!", name)))
13
	})
14
15
	fmt.Println("Running on :8080")
16
	http.ListenAndServe(":8080", nil)
17
}

+ 11 - 0
go/examples/hello_web.rb

@ -0,0 +1,11 @@
1
require 'webrick'
2
3
server = WEBrick::HTTPServer.new :Port => 8080
4
5
server.mount_proc '/' do |req, res|
6
  name = req.path == '/' ? "World" : req.path[1..-1]
7
  res.body = "Hello, #{name}!"
8
end
9
10
trap 'INT' do server.shutdown end
11
server.start