Golang – Encode Json data

This recipe demonstrates how to use struct to encode to json data. The struct type and its attributes have to be exportable in order for json encoding. The json data uses the attributes of struct type as keys if there is no customize key name defined. package main import ( "encoding/json" "fmt" "log" ) // … Continue reading Golang – Encode Json data

Golang – Check if IPv4 is valid and resolve FQDN

This recipe demonstrates if string is a valid IPv4, and also to resolve a FQDN to IP address. This recipe uses os.Args to get the second argument as FQDN and call net.ResolveIPAddr() function to do a FQDN resolution to IP address. package main import ( "fmt" "log" "net" "os" ) func isIPv4Addr(ip string) bool { … Continue reading Golang – Check if IPv4 is valid and resolve FQDN

Golang – How to write ssh.HostKeyCallback

ssh.InsecureIgnoreHostKey is lazy and seems popular? I have seen many tutorials and some codes in github that ignore host key checking, this is not recommended as you need to ensure everytime you connect to the known ssh server is the actual server that serves your purpose, if host key checking is ignore then any server … Continue reading Golang – How to write ssh.HostKeyCallback