Go example added to kitchen sink demo
This commit is contained in:
parent
7df563169a
commit
e00b6e656e
2 changed files with 39 additions and 0 deletions
|
|
@ -93,6 +93,7 @@ var modes = [
|
||||||
new Mode("coldfusion", "ColdFusion", ["cfm"]),
|
new Mode("coldfusion", "ColdFusion", ["cfm"]),
|
||||||
new Mode("csharp", "C#", ["cs"]),
|
new Mode("csharp", "C#", ["cs"]),
|
||||||
new Mode("css", "CSS", ["css"]),
|
new Mode("css", "CSS", ["css"]),
|
||||||
|
new Mode("golang", "Go", ["go"]),
|
||||||
new Mode("groovy", "Groovy", ["groovy"]),
|
new Mode("groovy", "Groovy", ["groovy"]),
|
||||||
new Mode("haxe", "haXe", ["hx"]),
|
new Mode("haxe", "haXe", ["hx"]),
|
||||||
new Mode("html", "HTML", ["html", "htm"]),
|
new Mode("html", "HTML", ["html", "htm"]),
|
||||||
|
|
@ -261,6 +262,10 @@ var docs = [
|
||||||
new WrappedDoc(
|
new WrappedDoc(
|
||||||
"pgsql", "pgSQL",
|
"pgsql", "pgSQL",
|
||||||
require("ace/requirejs/text!./docs/pgsql.pgsql")
|
require("ace/requirejs/text!./docs/pgsql.pgsql")
|
||||||
|
),
|
||||||
|
new Doc(
|
||||||
|
"golang", "Go",
|
||||||
|
require("ace/requirejs/text!./docs/golang.go")
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
34
demo/kitchen-sink/docs/golang.go
Normal file
34
demo/kitchen-sink/docs/golang.go
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
// Concurrent computation of pi.
|
||||||
|
// See http://goo.gl/ZuTZM.
|
||||||
|
//
|
||||||
|
// This demonstrates Go's ability to handle
|
||||||
|
// large numbers of concurrent processes.
|
||||||
|
// It is an unreasonable way to calculate pi.
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println(pi(5000))
|
||||||
|
}
|
||||||
|
|
||||||
|
// pi launches n goroutines to compute an
|
||||||
|
// approximation of pi.
|
||||||
|
func pi(n int) float64 {
|
||||||
|
ch := make(chan float64)
|
||||||
|
for k := 0; k <= n; k++ {
|
||||||
|
go term(ch, float64(k))
|
||||||
|
}
|
||||||
|
f := 0.0
|
||||||
|
for k := 0; k <= n; k++ {
|
||||||
|
f += <-ch
|
||||||
|
}
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
func term(ch chan float64, k float64) {
|
||||||
|
ch <- 4 * math.Pow(-1, k) / (2*k + 1)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue