HTTP Server
Before going to http Server, Let’s understand what a server is.
Before going to http Server, Let’s understand what a server is.
Errors are treated as values in Go. The error type is a built-in interface. An error variable represents any value that can describe itself as a string.
type error interface {
Error() string
}
Functions often return an error value, and calling code should handle errors by testing whether the error equals nil.
i, err := strconv.Atoi("42")
if err != nil {
fmt.Printf("couldn't convert number: %v\n", err)
return
}
fmt.Println("Converted integer:", i)
Maps are Go’s built-in associative data type (sometimes called hashes or dicts in other languages). Maps are made up of key-value pairs and provide a way to store data without relying on indexing.
``` package main
A goroutine is a lightweight thread managed by the Go runtime. go f(x, y, z) starts a new goroutine running f(x, y, z) The evaluation of f, x, y, and z happens in the current goroutine and the execution of f happens in the new goroutine. Goroutines run in the same address space, so access to shared memory must be synchronized
One of the design goals of Go was fast compilation. But How is it achieved? Dave Cheney’s talk at Gocon, a fantastic Go conference held semi-annually in Tokyo, Japan, 2014 covers 5 things that makes Go fast.
var gocon int32 = 2014
This is an example of a value in Go. When compiled, gocon consumes exactly four bytes of memory. Let’s compare Go with some other languages:
https://github.com/golang/go/wiki/CodeReviewComments
This document gives tips for writing clear, idiomatic Go code.