To create a http server with a route that handles the HTTP OPTIONS method in Go, you can use the built-in http package:
main.go420 chars22 linesIn this example, we define a handler function handleOptions that sets the Allow header to the HTTP methods that are allowed on the /options route (GET, POST, and OPTIONS), and writes an HTTP status code of 200 (OK) to the response.
We then register this handler function using the http.HandleFunc function, and bind it to the /options route.
Finally, we start the HTTP server listening on port 8080 using the http.ListenAndServe function.
gistlibby LogSnag