1 回答

TA貢獻1906條經驗 獲得超10個贊
選項1
p, err := static.ReadFile("static/sign.html")
if err != nil {
// TODO: Handle error as appropriate for the application.
}
w.Write(p)
選項 2
如果處理程序的路徑ServeSignPage與文件服務器中的靜態文件相同,則委托給文件服務器。
將文件服務器存儲在包級變量中。
var staticServer http.Handler
func init() {
fSys, err := fs.Sub(static, "static")
if err != nil {
panic(err)
}
staticServer = http.FileServer(http.FS(fSys)))
}
使用靜態服務器作為處理程序:
mux.Handle("/", staticServer)
委托給靜態服務器ServeSignPage:
func (h Handler) ServeSignPage(w http.ResponseWriter, r *http.Request) error {
publicKey := r.URL.Query().Get("publicKey")
err := h.Service.AuthorizeClientSigning(r.Context(), publicKey)
if err != nil {
return err
}
staticServer.ServeHTTP(w, r)
return nil
}
- 1 回答
- 0 關注
- 107 瀏覽
添加回答
舉報