DEV Community 👩‍💻👨‍💻

Ega Prasetya
Ega Prasetya

Posted on

Golang Web - Routing Handle Func

In GoLang there are several ways you can do..

  • By using http.HandleFunc
  • Interface implemantations http.Handler in the struct, and then using in the function http.Handler()
  • Create multiplexer by using struct http.ServeMux
  • Etc.

But in the series, we just used http.HandleFunc, okay so lets do it.


as explained briefly in the previous chapter, the http.HandlerFunc function is used for route / endpoint registration and its handler.

  • First step, create main.go and import package net/http

Alt Text

  • Next, create function main() and add closure handlerIndex, and then used it closure as handler from new 2route registation, that is / and /index.

Alt Text

  • Still in function main(), add the new Route /data with handler is anonymous function.

Alt Text

  • Last step, run the server

Alt Text

  • So, Run & Test

Alt Text

Alt Text

Grats, hope your enjoy it.

Top comments (0)

Timeless DEV post...

How to write a kickass README

Arguably the single most important piece of documentation for any open source project is the README. A good README not only informs people what the project does and who it is for but also how they use and contribute to it.

If you write a README without sufficient explanation of what your project does or how people can use it then it pretty much defeats the purpose of being open source as other developers are less likely to engage with or contribute towards it.