Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
130 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
include $(GOROOT)/src/Make.$(GOARCH) | ||
include $(GOROOT)/src/Make.inc | ||
|
||
TARG=hello_world | ||
GOFILES=hello_world.go | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
include $(GOROOT)/src/Make.$(GOARCH) | ||
include $(GOROOT)/src/Make.inc | ||
|
||
TARG=functions | ||
GOFILES=functions.go | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,10 @@ | ||
include $(GOROOT)/src/Make.$(GOARCH) | ||
include $(GOROOT)/src/Make.inc | ||
|
||
.SUFFIXES: .go .$O | ||
TARG=factorial_example | ||
|
||
OBJS=factorial.$O main.$O | ||
TARG=factorial | ||
GOFILES=\ | ||
main.go\ | ||
|
||
GOFILES=factorial.go | ||
include $(GOROOT)/src/Make.cmd | ||
|
||
factorial: $(OBJS) | ||
$(LD) -o factorial $(OBJS) | ||
|
||
clean: | ||
rm -f $(OBJS) factorial | ||
|
||
.go.$O: | ||
$(GC) $< | ||
|
||
test: | ||
gotest | ||
|
||
testpackage-clean: | ||
rm -f _test/$(TARG).a _gotest_.$O | ||
|
||
testpackage: _test/$(TARG).a | ||
|
||
_test/$(TARG).a: _gotest_.$O $(OFILES) | ||
@mkdir -p _test/$(dir) | ||
rm -f _test/$(TARG).a | ||
gopack grc $@ _gotest_.$O $(OFILES) | ||
|
||
_gotest_.$O: $(GOFILES) $(GOTESTFILES) $(PREREQ) | ||
$(GC) -o $@ $(GOFILES) $(GOTESTFILES) | ||
|
||
importpath: | ||
@echo $(TARG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
include $(GOROOT)/src/Make.inc | ||
|
||
TARG=factorial | ||
GOFMT=gofmt -spaces=true -tabindent=false -tabwidth=4 | ||
|
||
GOFILES=\ | ||
factorial.go\ | ||
|
||
include $(GOROOT)/src/Make.pkg | ||
|
||
format: | ||
${GOFMT} -w factorial.go | ||
${GOFMT} -w main.go | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package factorial | ||
|
||
// Functions those start from uppercase are pulic and would be imported | ||
// to access from other packages | ||
func Calc( n int ) (rv int) { | ||
if n == 0 { | ||
rv = 1 | ||
} else { | ||
rv = n * Calc( n - 1 ) | ||
} | ||
return rv | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package factorial_test | ||
|
||
import ( | ||
"testing"; | ||
"factorial"; | ||
) | ||
|
||
func TestCalc(t *testing.T){ | ||
if factorial.Calc( 5 ) != 120 { | ||
t.Errorf("Error calculation factorial\nExpected 120 was %d\n", factorial.Calc( 5 ) ) | ||
} | ||
if factorial.Calc( 0 ) != 1 { | ||
t.Errorf("Error calculation factorial\nExpected 1 was %d\n", factorial.Calc( 0 ) ) | ||
} | ||
if factorial.Calc( 1 ) != 1 { | ||
t.Errorf("Error calculation factorial\nExpected 1 was %d\n", factorial.Calc( 1 ) ) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
include $(GOROOT)/src/Make.$(GOARCH) | ||
include $(GOROOT)/src/Make.inc | ||
|
||
TARG=arrays | ||
GOFILES=arrays.go | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
include $(GOROOT)/src/Make.$(GOARCH) | ||
include $(GOROOT)/src/Make.inc | ||
|
||
TARG=slices | ||
GOFILES=slices.go | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
include $(GOROOT)/src/Make.$(GOARCH) | ||
include $(GOROOT)/src/Make.inc | ||
|
||
TARG=maps | ||
GOFILES=maps.go | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,7 @@ | ||
include $(GOROOT)/src/Make.$(GOARCH) | ||
include $(GOROOT)/src/Make.inc | ||
|
||
.SUFFIXES: .go .$O | ||
|
||
OBJS=super_point.$O structs.$O | ||
TARG=structs | ||
|
||
structs: $(OBJS) | ||
$(LD) -o structs $(OBJS) | ||
|
||
clean: | ||
rm -f $(OBJS) structs | ||
|
||
.go.$O: | ||
$(GC) $< | ||
|
||
GOFILES=structs.go super_point.go | ||
|
||
include $(GOROOT)/src/Make.cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package super_point | ||
package main | ||
|
||
// type for export should start with Uppercase | ||
type SuperPoint struct { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright 2009 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. | ||
|
||
include $(GOROOT)/src/Make.inc | ||
|
||
TARG=10_http | ||
GOFILES=\ | ||
http.go\ | ||
|
||
include $(GOROOT)/src/Make.cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"http" | ||
"io" | ||
"log" | ||
"template" | ||
) | ||
|
||
var addr = flag.String("addr", ":1718", "http service address") // Q=17, R=18 | ||
var fmap = template.FormatterMap{ | ||
"html": template.HTMLFormatter, | ||
"url+html": UrlHtmlFormatter, | ||
} | ||
var templ = template.MustParse(templateStr, fmap) | ||
|
||
func main() { | ||
flag.Parse() | ||
http.Handle("/", http.HandlerFunc(QR)) | ||
err := http.ListenAndServe(*addr, nil) | ||
if err != nil { | ||
log.Exit("ListenAndServe:", err) | ||
} | ||
} | ||
|
||
func QR(w http.ResponseWriter, req *http.Request) { | ||
templ.Execute(req.FormValue("s"), w) | ||
} | ||
|
||
func UrlHtmlFormatter(w io.Writer, v interface{}, fmt string) { | ||
template.HTMLEscape(w, []byte(http.URLEscape(v.(string)))) | ||
} | ||
|
||
|
||
const templateStr = ` | ||
<html> | ||
<head> | ||
<title>QR Link Generator</title> | ||
</head> | ||
<body> | ||
{.section @} | ||
<img src="http://chart.apis.google.com/chart?chs=300x300&cht=qr&choe=UTF-8&chl={@|url+html}" | ||
/> | ||
<br> | ||
{@|html} | ||
<br> | ||
<br> | ||
{.end} | ||
<form action="/" name=f method="GET"><input maxLength=1024 size=70 | ||
name=s value="" title="Text to QR Encode"><input type=submit | ||
value="Show QR" name=qr> | ||
</form> | ||
</body> | ||
</html> | ||
` | ||
|