Here's an example code snippet in Go that creates a HTTP server with a GET route:
main.go208 chars15 lines
In this example, we define a function that handles requests to the "/hello" route by writing "Hello, world!" as a response. We then use the ListenAndServe
function from the http
package to start the server on port 8080.
To run this code, save it in a file called main.go
, and run go run main.go
in your terminal. You can then visit http://localhost:8080/hello in your browser to see the response.
gistlibby LogSnag