This is a creation in Article, where the information may have evolved or changed.
Original address
Brief introduction
Recently due to the configuration of the Nginx server, there is a proxy forwarding (proxy_pass) function, the current server can receive requests forwarded to other servers to handle.
But in the configuration, I found that I can not confirm that my proxy_pass is in effect, the online off-the-shelf echo service does not meet my requirements, so I decided to write an echo server, with Golang.
Code
Here's the code, ECHO.
The specific code does not do a detailed introduction, that is, the use of the Golang HTTP library, provides a Web server and a websocket server, using Logrus as a log library, the original template as a template library.
Use
The tool is a command-line tool that can only be started on the command line
After startup, the tool prints the address of the current Web server on the command line and can be accessed using a browser
The tool has four modes, specified by the-m parameter:
-m echo
HTML echo mode, which is also the default mode for the software. His role is: when you request the Web server address provided by the tool, the server returns all the information from the request you just made to you via an HTML document, similar to the following:
-m terminal
command-line mode, in this mode, the tool will only display the request information in the terminal command line, access to the previous URL (such as http://0.0.0.0:8888) will not have any return results. The command line output is as follows:
-m file
File mode, the tool will only write the request information in the above terminal mode to the specified file, default to the file under the current directory logs/log.txt
, but you can also store the -f 自定义日志文件地址
location by customizing the log file.
-m ws
This is also my favorite mode, through the use of websocket technology, let us in the browser to observe the specified link in real-time access information.
When this mode is started, the address of the console output is accessed as usual, and then the browser jumps to a new address, similar to this: http://0.0.0.0:8888/4bf26e4f-7324-4942-a21c-706575cdb34d/client
In the page, there is a field named Target url , the URL is the specified service address, any client once requested the service address, his request information will be displayed on http://0.0.0.0:8888/4bf26e4f-7324-4942-a21c-706575cdb34d/client
this page (that is, before you jump to get the address), and is updated in real time.
Participation
There are currently a few modes, if you have any questions, you can issues on Github Echoo.