Private IP Address Ranges
RFC 1918 defines three IP address blocks reserved for private networks:
- Class A: 10.0.0.0 – 10.255.255.255
- Class B: 172.16.0.0 – 172.31.255.255
- Class C: 192.168.0.0 – 192.168.255.255
These addresses are not routable on the public internet and can be used internally without ISP registration.
Docker Networking Issues
After installing Docker, you might encounter connectivity problems. Docker automatically adds itself to system startup and may disrupt network connections due to proxy settings.
The error message "Remote computer or device does not accept connection" can be resolved by:
- Open Internet Options
- Navigate to Connections tab
- Click LAN Settings
- Uncheck all proxy server options
Docker Proxy Configuration
To configure Docker proxy settings:
- Open Docker client
- Click the settings gear icon
- Navigate to Resource > Proxies
- Enable Manual proxy configuration
- Set HTTP proxy (e.g., socks5://127.0.0.1:10808/)
Proxy configuration is necessary when accessing restricted resources like gcr.io.
Go Modules Error Resolution
When encountering "cannot find main module; see 'go help modules'" in VSCode:
This error occurs when GO111MODULE is set to 'on' but no go.mod file exists in the project directory.
Solutions:
- Create a go.mod file
- Set GO111MODULE to 'auto' via environment variables
- Restart the system
VSCode Go Debug Configuration
{
"version": "0.2.0",
"configurations": [
{
"name": "Go Debugger",
"type": "go",
"request": "launch",
"program": "${fileDirname}",
"env": {
"GOPATH": "c:/gowork/mygo",
"GOROOT": "c:/GO"
},
"args": [
"-config",
"config.json"
]
}
]
}
Go Language Fundamentals
fmtpackage provides formatting functions similar to C++ iostream- Every Go application contains a
mainpackage func main()is the entry point for execution- Comments use
//for single-line and/* ... */for blocks - Exported identifiers start with uppercase letters (public), unexported with lowercase (private)
- Go's automatic semicolon insertion rules eliminate debates about brace placement
- Variables declared with
:=inside functions,varfor package-level - Multiple return values:
func swap(a, b int) (int, int) - Structs use
typekeyword:type Book struct { Title string } - JSON serialization requires exported fields (uppercase)
- Slices are dynamic arrays with
len()andcap()functions rangekeyword iterates over collections, maps, and strings- Goroutines enable concurrency with the
gokeyword - Channels (
chan) facilitate communication between goroutines deferexecutes functions when their containing functon returns
Handling JSON with Socket.IO in Go
Using the gosocketio library:
c.On("success", func(f interface{}) {
m := f.(map[string]interface{})
for k, v := range m {
switch vv := v.(type) {
case string:
fmt.Println(k, "is string", vv)
case int:
fmt.Println(k, "is int", vv)
case []interface{}:
fmt.Println(k, "is an array:")
for i, u := range vv {
fmt.Println(i, u)
}
default:
fmt.Println(k, "is of unknown type")
}
}
})
Merging Map Slices in Go
When working with slices of maps:
var combinedData []map[string]interface{}
slice1 := []map[string]interface{}{{"one": 1, "two": 2}}
slice2 := []map[string]interface{}{{"three": 3, "four": 4}}
combinedData = append(combinedData, slice1...)
combinedData = append(combinedData, slice2...)
// Accessing data
for _, item := range combinedData {
for k, v := range item {
fmt.Printf("%s: %v\n", k, v)
}
}
Command Line Arguments and File Operations
var configFile string
func init() {
flag.StringVar(&configFile, "config", "config.json", "Path to configuration file")
flag.Parse()
}
func main() {
configData, err := ioutil.ReadFile(configFile)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(configData))
}