Description

I have a Go module that's in a private repository. This Go module has a function "SetupRouter" that takes in a *gin.Engine, and has html templates that it attempts to serve via it's own routes. The Go module loads the html templates fine when ran as a standalone program, but it crashes when I import the module into another Go app.

How to reproduce

Module file dir - go.mod - go.sum - web - views - pages - index.html

Module code to load html

package webview

import "github.com/gin-gonic/gin"

func SetupRouter(r *gin.Engine) {
  r.LoadHTMLGlob("web/views/**/*")
}

Main app

package main

import (
  "path/to/module/webview/"
  "import "github.com/gin-gonic/gin"
)

func main() {
  r := gin.New()
  webview.SetupRouter(r)
}

Expectations

The html files are loaded successfully.

Actual result

panic: html/template: pattern matches no files: `web/views/**/*`

Environment

  • go version: 1.22
  • gin version (or commit ref): v1.10.0
  • operating system: macos

Comment From: JimChenWYU

This error is from html/template

package webview

func SetupRouter(r *gin.Engine) {
  // the current path is `path/to/module` not root path
  r.LoadHTMLGlob("web/views/**/*")
}