This is a creation in Article, where the information may have evolved or changed.
Package Mainimport ("FMT" "io" "Log" "Net/http" "OS")//Gets the file size of the interface type size interface {size () int64}//Gets the file information of the interface type Stat interface {Stat () (OS. FileInfo, error)}//Hello World, the Web Serverfunc helloserver (w http. Responsewriter, R *http. Request) {if "POST" = = R.method {file, _, Err: = R.formfile ("UserFile") if err! = Nil {http. Error (W, err. Error (), Return}if statinterface, OK: = file. (Stat); OK {FileInfo, _: = Statinterface.stat () fmt. fprintf (W, "Size of uploaded file:%d", fileinfo.size ())}if sizeinterface, OK: = file. (Size); OK {fmt. fprintf (w, "Upload file Size:%d", sizeinterface.size ())}return}//upload page W. Header (). ADD ("Content-type", "text/html") W.writeheader (HTML): = ' <form enctype= ' multipart/form-data ' action= '/hello ' method= "POST" > Send this file: <input name= "UserFile" type= "file"/> <input type= "Submit" value= "Send Fi" Le "/></form> ' io. WriteString (w, HTML)}func Main () {http. Handlefunc ("/hello", HelloServer) Err: = http. Listenandserve (": 12345", nil) if err! = Nil {log. Fatal("Listenandserve:", Err)}}