-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
big update and rewrite of web apps chapter
- Loading branch information
Showing
251 changed files
with
4,385 additions
and
22 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,3 +1,39 @@ | ||
Resources for http://GoTutorial.net | ||
|
||
see the above website for details. | ||
|
||
|
||
### Beginner Go | ||
|
||
- Lesson 01: The Basic Basics | ||
- Intro to Syntax, Numbers, Strings | ||
- Lesson 02: Go with the Flow | ||
- Expressions, Statements & Flow Control | ||
- Lesson 03: Intro To Types | ||
- Types, Arrays, Slices, Maps & Structs | ||
|
||
### Advanced Go | ||
|
||
|
||
- Lesson 04: Composition | ||
- Embedded Fields & Interfaces | ||
- Lesson 05: Concurrency | ||
- Goroutines & Channels | ||
- Lesson 06: Toolchain | ||
- Compiling, Formatting, Testing, Profiling & More | ||
- Lesson 07: Idiomatic Go | ||
- Idiomatic Go | ||
- Lesson 08: Web Apps in Go | ||
- net/http, net/http/httptest, html/template, database/sql | ||
- Lesson 09: JSON, JSON, JSON | ||
- Encoder/Decoder, Anonymous Fields, Marshaler/Unmarshaler Interface, RawMessage | ||
- Lesson 10: Testing | ||
- Testing, Benchmarking, Coverage, httptest and more | ||
- Lesson 12: I/O | ||
- Readers, Writers & Buffers | ||
|
||
### Other | ||
|
||
- Lesson 11: Deployment | ||
- Build/Release, Containers & A Case Study | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-16.3 KB
keynote/Go_Lesson_04.key/Data/2-09_1199_Panigale_2880x1620-small-4.jpg
Binary file not shown.
Binary file removed
BIN
-29.4 KB
keynote/Go_Lesson_04.key/Data/2-10-SUPERQUADRO_1631x2178-small-15.jpg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed
BIN
-16.3 KB
keynote/Go_Lesson_07.key/Data/2-09_1199_Panigale_2880x1620-small-4.jpg
Diff not rendered.
Binary file removed
BIN
-29.4 KB
keynote/Go_Lesson_07.key/Data/2-10-SUPERQUADRO_1631x2178-small-15.jpg
Diff not rendered.
Binary file removed
BIN
-30.1 KB
keynote/Go_Lesson_07.key/Data/Screen Shot 2014-09-23 at 9.52-12548.png
Diff not rendered.
Binary file removed
BIN
-179 KB
keynote/Go_Lesson_07.key/Data/Screen Shot 2014-09-23 at 9.52.10 AM-12547.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file not shown.
11 changes: 0 additions & 11 deletions
11
keynote/Go_Lesson_07.key/Metadata/BuildVersionHistory.plist
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file not shown.
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,2 @@ | ||
slv* | ||
gox_build.log |
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,5 @@ | ||
|
||
|
||
## Usage | ||
|
||
./build_all.sh |
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,49 @@ | ||
#!/bin/sh | ||
|
||
# if one of our commands returns an error, stop execution of this script | ||
set -o errexit | ||
|
||
COMPONENT="shortlink" | ||
GO_COMMAND="go" | ||
|
||
# generate | ||
echo "************************" | ||
echo "$GO_COMMAND generate" | ||
$GO_COMMAND generate | ||
|
||
# build on the native or default platform | ||
echo "************************" | ||
echo "building native platform" | ||
$GO_COMMAND build | ||
|
||
echo "************************" | ||
echo "vetting native platform" | ||
$GO_COMMAND vet | ||
|
||
# test on the native or default platform | ||
echo "************************" | ||
echo "testing native platform" | ||
$GO_COMMAND test | ||
|
||
# I like gox as a cross compilation tool: https://github.com/mitchellh/gox | ||
# install with: | ||
# go get github.com/mitchellh/gox | ||
|
||
# build for our test or deployment platforms | ||
# normally we do local development on darwin/amd64 and deploy to linux/amd64. | ||
# feel free to add or remove if your situation differs | ||
# also, in the normal case, most of the output of gox is redundant with | ||
# the output from go build above, so in the normal case, we just | ||
# redirect to a build log | ||
|
||
# currently gox doesn't seem to support vgo... | ||
|
||
GOX_BUILD_LOG="gox_build.log" | ||
date >> $GOX_BUILD_LOG | ||
echo "************************" | ||
echo "crosscompiling: gox -osarch=\"darwin/amd64\" -osarch=\"linux/amd64\"" | ||
if ! gox -osarch="darwin/amd64" -osarch="linux/amd64" >> $GOX_BUILD_LOG 2>&1; then | ||
echo "FAILURE: gox command failed to build for deployment architecture" | ||
echo "check gox_build.log for more info" | ||
fi | ||
|
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,3 @@ | ||
package main | ||
|
||
//REMOVE_TO_ENABLE go:generate stringer -type=EXAMPLE |
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,9 @@ | ||
#!/bin/sh | ||
|
||
# if you are using modules you don't need this file | ||
|
||
# if not, this is a great place to note what third party modules you may need to get. | ||
|
||
go get -u golang.org/x/tools/cmd/stringer | ||
|
||
go get -u github.com/lib/pq |
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,42 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"os" | ||
"runtime" | ||
"time" | ||
) | ||
|
||
var show_h bool | ||
var show_help bool | ||
var show_version bool | ||
|
||
func init() { | ||
flag.BoolVar(&show_h, "h", false, "show help message and exit(0)") | ||
flag.BoolVar(&show_help, "help", false, "show help message and exit(0)") | ||
flag.BoolVar(&show_version, "version", false, "show version info and exit(0)") | ||
} | ||
|
||
func main() { | ||
log.Println(current_function(), "entering") | ||
defer trace(current_function(), time.Now()) | ||
|
||
log.Printf("Starting %v (v%v, build %v, build date:%v)", os.Args[0], Version(), BuildNumber(), BuildDate()) | ||
log.Printf("os.Args: %v", os.Args) | ||
log.Printf("Go (runtime:%v) (GOMAXPROCS:%d) (NumCPUs:%d)\n", runtime.Version(), runtime.GOMAXPROCS(-1), runtime.NumCPU()) | ||
|
||
// command line flags: | ||
flag.Parse() | ||
|
||
if show_version { | ||
os.Exit(0) | ||
} | ||
|
||
if show_h || show_help { | ||
flag.Usage() | ||
os.Exit(0) | ||
} | ||
|
||
log.Println("Hello Gophers!") | ||
} |
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,3 @@ | ||
package main | ||
|
||
// TODO |
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,24 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"runtime" | ||
"time" | ||
) | ||
|
||
// | ||
// Usage example: copy paste the two lines to the beginning of any function | ||
// log.Println(current_function(), "entering") | ||
// defer trace(current_function(), time.Now()) | ||
func trace(function_name string, start_time time.Time) { | ||
elapsed := time.Since(start_time) | ||
log.Printf("%s exiting ~ %s elapsed", function_name, elapsed) | ||
} | ||
|
||
func current_function() string { | ||
pc := make([]uintptr, 15) | ||
n := runtime.Callers(2, pc) | ||
frames := runtime.CallersFrames(pc[:n]) | ||
frame, _ := frames.Next() | ||
return frame.Function | ||
} |
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,31 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
) | ||
|
||
const ( | ||
internal_BUILD_TIMESTAMP = 1500000000 | ||
internal_BUILD_NUMBER = 0 | ||
internal_VERSION_STRING = "0.0.0" | ||
) | ||
|
||
func BuildDate() time.Time { | ||
return time.Unix(internal_BUILD_TIMESTAMP, 0) | ||
} | ||
func BuildNumber() int64 { | ||
return internal_BUILD_NUMBER | ||
} | ||
func Version() string { | ||
return internal_VERSION_STRING | ||
} | ||
|
||
func VersionInfo() string { | ||
return fmt.Sprintf("shortlink (%v, build %v, build date:%v)", Version(), BuildNumber(), BuildDate()) | ||
} | ||
|
||
func LogVersionInfo() { | ||
log.Printf(VersionInfo()) | ||
} |
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,149 @@ | ||
#!/bin/sh | ||
|
||
# Last edit 2018-08-27 | ||
|
||
set -o nounset | ||
set -o errexit | ||
|
||
# you can add the following lines to .git/hooks/pre-commit to auto bump build num: | ||
# | ||
# ./version_bump.sh | ||
# git add version.go | ||
|
||
VERSION_GO_FILENAME="version.go" | ||
|
||
usage(){ | ||
echo "Usage: $0 major|minor|patch|build" | ||
echo " $0 build (just update buildnum, default)" | ||
echo " $0 patch (1.0.PATCH)" | ||
echo " $0 minor (1.MINOR.0)" | ||
echo " $0 major (MAJOR.0.0)" | ||
} | ||
|
||
bump_build(){ | ||
CURRENT_BUILD_NUM=$(grep -o "internal_BUILD_NUMBER\\s*=\\s*[0-9]\\+" $VERSION_GO_FILENAME | grep -o "[0-9]\\+") | ||
NEW_NUM=$((CURRENT_BUILD_NUM+1)) | ||
echo "Bumping build number, from ${CURRENT_BUILD_NUM} to $NEW_NUM" | ||
|
||
sed -i.bak "s/internal_BUILD_NUMBER[[:space:]]*=[[:space:]]*[0-9]*/internal_BUILD_NUMBER\\ =\\ ${NEW_NUM}/g" $VERSION_GO_FILENAME | ||
|
||
|
||
NEW_TS=$(date +%s) | ||
echo "Bumping build timestamp new=$NEW_TS" | ||
|
||
sed -i.bak "s/internal_BUILD_TIMESTAMP[[:space:]]*=[[:space:]]*[0-9][0-9]*/internal_BUILD_TIMESTAMP\\ =\\ ${NEW_TS}/g" $VERSION_GO_FILENAME | ||
|
||
rm -f version.go.bak | ||
|
||
# cleanup | ||
go fmt version.go > /dev/null | ||
|
||
FINAL_VERSION_STRING=$(grep -o "internal_VERSION_STRING\\s*=\\s\"[vV]*[0-9]*\.[0-9]*\.[0-9]*\"\\+" $VERSION_GO_FILENAME | grep -o "[0-9]*\.[0-9]*\.[0-9]*") | ||
echo "v${FINAL_VERSION_STRING}" | ||
} | ||
|
||
bump_version_string(){ | ||
echo "Bumping ${POSITION} number, from ${XYZ_VERSION_STRING} to ${NEW_VERSION_STRING}" | ||
sed -i.bak "s/internal_VERSION_STRING[[:space:]]*=[[:space:]]*\"[vV]*[0-9]*\.[0-9]*\.[0-9]*\"/internal_VERSION_STRING\\ =\\ \"${NEW_VERSION_STRING}\"/g" $VERSION_GO_FILENAME | ||
|
||
bump_build | ||
} | ||
|
||
|
||
bump_patch(){ | ||
echo "patching" | ||
NEW_PATCH_NUM=$((PATCH_NUM+1)) | ||
NEW_VERSION_STRING=${MAJOR_NUM}.${MINOR_NUM}.${NEW_PATCH_NUM} | ||
bump_version_string | ||
} | ||
|
||
bump_minor(){ | ||
NEW_MINOR_NUM=$((MINOR_NUM+1)) | ||
NEW_PATCH_NUM="0" | ||
NEW_VERSION_STRING=${MAJOR_NUM}.${NEW_MINOR_NUM}.${NEW_PATCH_NUM} | ||
bump_version_string | ||
} | ||
|
||
bump_major(){ | ||
NEW_MAJOR_NUM=$((MAJOR_NUM+1)) | ||
NEW_MINOR_NUM="0" | ||
NEW_PATCH_NUM="0" | ||
NEW_VERSION_STRING=${NEW_MAJOR_NUM}.${NEW_MINOR_NUM}.${NEW_PATCH_NUM} | ||
bump_version_string | ||
} | ||
|
||
tag(){ | ||
FINAL_VERSION_STRING=$(grep -o "internal_VERSION_STRING\\s*=\\s\"[vV]*[0-9]*\.[0-9]*\.[0-9]*\"\\+" $VERSION_GO_FILENAME | grep -o "[0-9]*\.[0-9]*\.[0-9]*") | ||
git add version.go | ||
git commit -m "tagging version v$FINAL_VERSION_STRING" | ||
git tag v$FINAL_VERSION_STRING | ||
|
||
echo "use the following command to push tag to origin:" | ||
echo "git push && git push --tags" | ||
} | ||
|
||
|
||
|
||
if [ $# -eq 0 ] | ||
then | ||
bump_build | ||
exit 0 | ||
elif [ $# -gt 1 ] | ||
then | ||
echo "too many arguments supplied" | ||
usage | ||
exit 1 | ||
fi | ||
|
||
|
||
while [ "$1" != "" ]; do | ||
|
||
PARAM=`echo $1 | awk -F= '{print $1}'` | ||
VALUE=`echo $1 | awk -F= '{print $2}'` | ||
|
||
# should be of form x.y.z | ||
XYZ_VERSION_STRING=$(grep -o "internal_VERSION_STRING\\s*=\\s\"[vV]*[0-9]*\.[0-9]*\.[0-9]*\"\\+" $VERSION_GO_FILENAME | grep -o "[0-9]*\.[0-9]*\.[0-9]*") | ||
|
||
MAJOR_NUM=$(echo "$XYZ_VERSION_STRING" | cut -d '.' -f 1) | ||
MINOR_NUM=$(echo "$XYZ_VERSION_STRING" | cut -d '.' -f 2) | ||
PATCH_NUM=$(echo "$XYZ_VERSION_STRING" | cut -d '.' -f 3) | ||
|
||
POSITION=$1 | ||
|
||
case $PARAM in | ||
-h | --help) | ||
usage | ||
exit 0 | ||
;; | ||
build) | ||
bump_build | ||
exit 0 | ||
;; | ||
patch) | ||
bump_patch | ||
exit 0 | ||
;; | ||
minor) | ||
bump_minor | ||
exit 0 | ||
;; | ||
major) | ||
bump_major | ||
exit 0 | ||
;; | ||
tag) | ||
tag | ||
exit 0 | ||
;; | ||
*) | ||
echo "ERROR: unknown parameter \"$PARAM\"" | ||
usage | ||
exit 1 | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
|
||
|
||
|
Oops, something went wrong.