golang webserver的文件系统"root"在哪里.它似乎不在可执行文件所在的目录中."root"我指的是我将用于的目录,比如img的src属性,没有任何路径.我不打算这样做,但如果我知道,它会帮助我理解结构
我最近开始学习Go.我有一个像网络应用程序的样本.我有:
/* tick-tock.go */
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
// Content for the main html page..
var page = `<html>
<head>
<script type="text/javascript"
src="http://localhost:8081/jquery.min.js">
</script>
<style>
div {
font-family: "Times New Roman", Georgia, Serif;
font-size: 1em;
width: 13.3em;
padding: 8px 8px;
border: 2px solid #2B1B17;
color: #2B1B17;
text-shadow: 1px 1px #E5E4E2;
background: #FFFFFF;
}
</style>
</head>
<body>
<h2 align=center>Go Timer </h2>
<div id="output" style="width: 30%; height: 63%; overflow-y: scroll; float:left;"></div>
<div id="v1" style="width: 50%; height: 30%; …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
r := mux.NewRouter()
r.Handle("/", http.FileServer(http.Dir("./frontend/build/")))
r.Handle("/static", http.FileServer(http.Dir("./frontend/build/static/")))
r.PathPrefix("/api").Handler(auth)
Run Code Online (Sandbox Code Playgroud)
/api应该是安全的。如果用户点击/,我希望他们查看目录index.html中的PROJECTDIR/frontend。
前端目录看起来像
frontend
/build
index.html
/static
/js
/css
/media
Run Code Online (Sandbox Code Playgroud)
index.html 加载 中的所有内容/static。无论我如何配置它,当我访问 时localhost:3000,我都可以得到 ,index.html但下面的所有内容/static都是 404。
我如何错误地配置这个?