How/Where to add a router to a Go app?

I’m brand new to using Go. I’ve been assigned the task to modify the Gogs UI for an internal project in my company:

I’d like to add a new page, via a new template, and then redirect to it under certain circumstances. In my particular case, the basic template I’m starting with is: /user/dashboard/dashboard.tmpl

Let’s say I wanted to add this one: /user/dashboard/dashboard2.tmpl

What do I need to do, in terms of routers, so that I can redirect to this page?

Note: If it’s impossible to have two destination pages within the same folder, then this would be fine too: /user/dashboard2/dashboard.tmpl

Either way works! But I’ve examined the Gogs codebase and read up everything I could about Go routers but cannot figure out how to make this work.


seems that you have problems with the templates not routers. from go you can load and render templates from the same folder. example:

package main

import (

var t *template.Template

func page1(w http.ResponseWriter, r *http.Request) {
	t.ExecuteTemplate(w, "page1.html", nil)

func page2(w http.ResponseWriter, r *http.Request) {
	t.ExecuteTemplate(w, "page2.html", nil)

func main() {
	t = template.New("templ")

	http.HandleFunc("/page1", page1)
	http.HandleFunc("/page2", page2)
	http.ListenAndServe(":8080", nil)

this example use http.HandleFunc. if your application use a framework you need to link your handlers with its routers.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.