1// 请求失败造成 panic2funcmain(){3resp,err:=http.Get("https://api.ipify.org?format=json")4defer resp.Body.Close()// resp 可能为 nil,不能读取 Body5iferr!=nil{6fmt.Println(err)7return8}910body,err:=ioutil.ReadAll(resp.Body)11checkError(err)1213fmt.Println(string(body))14}1516fu...
func FILE() string { _, file, _, _ := runtime.Caller(1) return file } // __LINE__ returns the line number at which the function was invoked func LINE() int { _, _, line, _ := runtime.Caller(1) return line } 在同一需求场景下,FILE和LINE分别调用了一次能耗较高的runtime.Call...
我们通过NewReader(string)构建一个Reader对象,随后就可以通过Read()读取Reader的内容,以下是其使用: packagemain import( "fmt" "strings" ) funcmain(){ s :="Today is monday, what a great start!" sr := strings.NewReader(s) // read cap_sr := sr.Len() data :=make([]byte, cap_sr) n,...
package mainimport("fmt""net""log""os")funcmain() {//建立socket,监听端口netListen, err :=net.Listen("tcp","localhost:1024")CheckError(err)defernetListen.Close()Log("Waiting for clients")for{ conn, err :=netListen.Accept()iferr!=nil{continue}Log(conn.RemoteAddr().String()," tcp c...
近期对nmap的操作系统识别功能造了个轮子,用golang实现了一遍,想未来能用于扫描器,资产发现/管理系统,网络空间引擎中。 造轮子也是一次深入理解它原理的过程,造完轮子后感觉到所有代码尽在我掌握之中,之后大规模扫描测试就可以 以最有效率,发最小包,绕过防火墙的方式进行集成,也能轻易的进行扩展。
map[string]interface{}{ "code": 233, "msg": "you is dog!", }) }) ...
netpollcheckerr 方法会检查当前 pollDesc 对应的 fd 是否是正常的, // 通常来说 netpollcheckerr(pd, mode) == 0 是成立的,所以这里会执行 gopark // 把当前 goroutine 给 park 住,直至对应的 fd 上发生可读/可写或者其他『期待的』I/O 事件为止, // 然后 unpark 返回,在 gopark 内部会把当前 go...
Let’s now expand ourTestHumanDate()function to cover some additional test cases. Specifically, we’re going to update it to also check that: If the input tohumanDate()is thezero time, then it returns the empty string"". The output from thehumanDate()function always uses the UTC time ...
Here is basic example of print command (fromexamples/print/directory): packagemainimport("fmt""github.com/akamensky/argparse""os")funcmain() {// Create new parser objectparser:=argparse.NewParser("print","Prints provided string to stdout")// Create string flags:=parser.String("s","string...
Weight Select a upstream according to the weight and number of connections of each upstreamprompt:The load balancing check interval can be set by --lb-retrytime in milliseconds. The load balancing connection timeout can be set by --lb-timeout in milliseconds. If the load balancing policy is...