O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The net/http package contains a simple way of executing the redirect. The RedirectHandler could be utilized. The function consumes the URL where the request will be redirected and the status code which will be sent to client. The function itself sends results to the Handler, which could be used in the Handle method of ServeMux (the example uses the default one directly from the package).

The second approach is the use of the Redirect function, which does the redirect for you. The function consumes ResponseWriter, the request pointer and the same as RequestHandler, the URL and status code, which will be sent to the client.

The redirect could be also done with the help of manually setting the Location header and writing the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required