杜松子酒路由器路径冲突

I want to make my app to serve below things.

  • a.com => serve /www to a browser so that the browser can seek /www/index.html)
  • a.com/js/mylib.js => serve /www/js/mylib.js to a browser
  • a.com/api/v1/disk => typical REST API which returns JSON
  • a.com/api/v1/memory => another API

I made a code like below:

package main

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

func main() {
    r := gin.Default()

    r.Static("/", "/www")

    apiv1 := r.Group("api/v1")
    {
        apiv1.GET("/disk", diskSpaceHandler)
        apiv1.GET("/memory", memoryHandler)
        apiv1.GET("/cpu", cpuHandler)
    }

    r.Run(":80")
}

When I run the code, it panics:

panic: path segment '/api/v1/disk' conflicts with existing wildcard '/*filepath' in path '/api/v1/disk'

I understand why it panics, but I have no idea how to fix.

Just two things comes up in my mind:

  1. Use NoRoute() function which will handle other than /api/v1 group path(don't know how exactly I implement that)
  2. Use middleware. There is static middlewhere https://github.com/gin-gonic/contrib but the code is not working on Windows(https://github.com/gin-gonic/contrib/issues/91)

Thank you in advance.