bazel-contrib / rules_go

Go rules for Bazel
Apache License 2.0
1.38k stars 656 forks source link

How can I open static resources (html, js, json) to browser access? #4092

Closed liushuai05 closed 1 month ago

liushuai05 commented 1 month ago

How can I open static resources (html, js, json) to browser access? Here, I place the compiled files of vue in the public directory of the golang project. When I use go run . At runtime, I can access these resources, but not when I use bazel. Also, this project introduces go-swagger, which requires setting/docs/swagger.json to a static resource. I use Route().StaticFile("/swagger.json", "./ docs/swagger.json") After mapping, use go run . My swagger was fine, but when I used bazel, I couldn't request this json file,Of course, I referred to other issues such as #1212, but I didn't seem to see the corresponding solution clearly.

liushuai05 commented 1 month ago

It has been solved. The method is as follows: add data 已经解决了,方法如下在docs目录的BUILD文件,添加data即可,多文件则使用glob 类似 data = glob(["public/","storage/"]),(我采用的goravel框架):

load("@rules_go//go:def.bzl", "go_library")
go_library(
    name = "docs",
     data = ["swagger.json"],
    importpath = "goravel/docs",
    visibility = ["//visibility:public"],
    deps = ["@com_github_swaggo_swag//:swag"],
)