This is a creation in Article, where the information may have evolved or changed.
Package Mainimport ("bytes" "Flag" "FMT" "io" "Log" "NET" "OS" "Strings" "Time") Func main () {var srchost, agencyhost Stringflag. Stringvar (&srchost, "Srchost", "" "," Srchost ") flag. Stringvar (&agencyhost, "Agencyhost", "" "," Agencyhost ") flag. Parse () if srchost = = "" | | Agencyhost = = "" {fmt. fprintf (OS. Stderr, "Fatal Error:%s", "parameter is empty") OS. Exit (1)}//establish socket, listen port Netlisten, err: = Net. Listen ("TCP", Srchost) checkerror (ERR) defer netlisten.close () Log ("Waiting for Clients") for {conn, err: = Netlisten.accept ()//If there is no request, always wait if err! = NIL {Continue}if Conn! = Nil {LOG (conn. Remoteaddr (). String (), "TCP Connect Success") Go Handleconnection (conn, agencyhost)//go can implement asynchronous concurrent request}}}//processing connection func handleconnection ( Conn Net. Conn, agencyhost string) {time. Sleep (time.millisecond) Buffer: = RECEIVEDATA (conn) if Len (buffer) > 1 {arr: = strings. Split (string (buffer), "\ r \ n") If Len (arr) > 1 {arr[1] = "Host:" + agencyhostnewstr: = Strings. Join (arr, "\ r \ n") sendagencyhost ([]byte (NEWSTR), Agencyhost, conn)}}conn. Close()}func sendagencyhost (data []byte, host string, Baseconn net. Conn) {Conn, _: = Net. Dial ("TCP", host) Conn. Write (data) time. Sleep (time.millisecond) Bufferhead: = Receivedata (conn) time. Sleep (time.millisecond) Bufferbody: = Receivedata (conn) var buf bytes. Bufferbuf.write (Bufferhead) buf. Write (bufferbody) baseconn. Write (BUF. Bytes ()) Conn. The Close ()}//receives the data unified method Func Receivedata (conn net. Conn) []byte {var buf bytes. Bufferbuffer: = Make ([]byte, 8192) for {sizenew, err: = conn. Read (buffer) buf. Write (Buffer[:sizenew]) If err = = Io. EOF | | Sizenew < 8192 {Break}}return buf. Bytes ()}//printing information Unified method Func log (v. ... interface{}) {log. Println (v ...)} Execute error Handling method func CheckError (err error) {if err! = Nil {fmt. fprintf (OS. Stderr, "Fatal Error:%s", err. Error ()) OS. Exit (1)}}