This commit is contained in:
parent
8b0b1503c3
commit
d0396da439
14
conf/wide.go
14
conf/wide.go
|
@ -102,8 +102,6 @@ func Load(confPath, confData, confServer, confLogLevel string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initUsers() {
|
func initUsers() {
|
||||||
os.MkdirAll(Wide.Data+PathSeparator+"users", 0755)
|
|
||||||
|
|
||||||
f, err := os.Open(Wide.Data + PathSeparator + "users")
|
f, err := os.Open(Wide.Data + PathSeparator + "users")
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
|
@ -202,12 +200,20 @@ func initWide(confPath, confData, confServer, confLogLevel string) {
|
||||||
}
|
}
|
||||||
Wide.Data = strings.Replace(Wide.Data, "${home}", home, -1)
|
Wide.Data = strings.Replace(Wide.Data, "${home}", home, -1)
|
||||||
Wide.Data = filepath.Clean(Wide.Data)
|
Wide.Data = filepath.Clean(Wide.Data)
|
||||||
if !util.File.IsExist(Wide.Data) {
|
if err := os.MkdirAll(Wide.Data+"/playground/", 0755); nil != err {
|
||||||
if err := os.MkdirAll(Wide.Data, 0775); nil != err {
|
|
||||||
logger.Errorf("Create data directory [%s] error", err)
|
logger.Errorf("Create data directory [%s] error", err)
|
||||||
|
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
if err := os.MkdirAll(Wide.Data+"/users/", 0755); nil != err {
|
||||||
|
logger.Errorf("Create data directory [%s] error", err)
|
||||||
|
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
if err := os.MkdirAll(Wide.Data+"/workspaces/", 0755); nil != err {
|
||||||
|
logger.Errorf("Create data directory [%s] error", err)
|
||||||
|
|
||||||
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server
|
// Server
|
||||||
|
|
|
@ -85,7 +85,7 @@ func SaveHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data["fileName"] = fileName
|
data["fileName"] = fileName
|
||||||
|
|
||||||
// Step3. write file
|
// Step3. write file
|
||||||
filePath := filepath.Clean(conf.Wide.Data + "/playground" + fileName)
|
filePath := filepath.Clean(conf.Wide.Data + "/playground/" + fileName)
|
||||||
fout, err := os.Create(filePath)
|
fout, err := os.Create(filePath)
|
||||||
fout.WriteString(code)
|
fout.WriteString(code)
|
||||||
if err := fout.Close(); nil != err {
|
if err := fout.Close(); nil != err {
|
||||||
|
|
|
@ -59,7 +59,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if strings.HasSuffix(r.URL.Path, ".go") {
|
if strings.HasSuffix(r.URL.Path, ".go") {
|
||||||
fileNameArg := r.URL.Path[len("/playground/"):]
|
fileNameArg := r.URL.Path[len("/playground/"):]
|
||||||
filePath := filepath.Clean(conf.Wide.Data+ "/playground" + fileNameArg)
|
filePath := filepath.Clean(conf.Wide.Data+ "/playground/" + fileNameArg)
|
||||||
|
|
||||||
bytes, err := ioutil.ReadFile(filePath)
|
bytes, err := ioutil.ReadFile(filePath)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
@ -94,7 +94,6 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
logger.Debugf("User [%s] has [%d] sessions", uid, len(wideSessions))
|
logger.Debugf("User [%s] has [%d] sessions", uid, len(wideSessions))
|
||||||
|
|
||||||
t, err := template.ParseFiles("views/playground/index.html")
|
t, err := template.ParseFiles("views/playground/index.html")
|
||||||
|
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
|
|
@ -209,14 +209,7 @@ func addUser(userId, userName, userAvatar string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// helloWorld generates the 'Hello, 世界' source code.
|
// helloWorld generates the 'Hello, 世界' source code.
|
||||||
// 1. src/hello/main.go
|
|
||||||
// 2. src/web/main.go
|
|
||||||
func helloWorld(workspace string) {
|
func helloWorld(workspace string) {
|
||||||
consoleHello(workspace)
|
|
||||||
webHello(workspace)
|
|
||||||
}
|
|
||||||
|
|
||||||
func consoleHello(workspace string) {
|
|
||||||
dir := workspace + conf.PathSeparator + "src" + conf.PathSeparator + "hello"
|
dir := workspace + conf.PathSeparator + "src" + conf.PathSeparator + "hello"
|
||||||
if err := os.MkdirAll(dir, 0755); nil != err {
|
if err := os.MkdirAll(dir, 0755); nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
|
@ -232,59 +225,5 @@ func consoleHello(workspace string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fout.WriteString(conf.HelloWorld)
|
fout.WriteString(conf.HelloWorld)
|
||||||
|
|
||||||
fout.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
func webHello(workspace string) {
|
|
||||||
dir := workspace + conf.PathSeparator + "src" + conf.PathSeparator + "web"
|
|
||||||
if err := os.MkdirAll(dir, 0755); nil != err {
|
|
||||||
logger.Error(err)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fout, err := os.Create(dir + conf.PathSeparator + "main.go")
|
|
||||||
if nil != err {
|
|
||||||
logger.Error(err)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
code := `package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Write([]byte("Hello, 世界"))
|
|
||||||
})
|
|
||||||
|
|
||||||
port := getPort()
|
|
||||||
|
|
||||||
// you may need to change the address
|
|
||||||
fmt.Println("Open https://wide.b3log.org:" + port + " in your browser to see the result")
|
|
||||||
|
|
||||||
if err := http.ListenAndServe(":"+port, nil); nil != err {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getPort() string {
|
|
||||||
rand.Seed(time.Now().UnixNano())
|
|
||||||
|
|
||||||
return strconv.Itoa(7000 + rand.Intn(8000-7000))
|
|
||||||
}
|
|
||||||
|
|
||||||
`
|
|
||||||
|
|
||||||
fout.WriteString(code)
|
|
||||||
|
|
||||||
fout.Close()
|
fout.Close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,7 +218,7 @@ var playground = {
|
||||||
if (!hovered) {
|
if (!hovered) {
|
||||||
$(".menu .share-panel").hide();
|
$(".menu .share-panel").hide();
|
||||||
}
|
}
|
||||||
}, http.StatusInternalServerError;
|
}, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".menu .share-panel").hover(function () {
|
$(".menu .share-panel").hover(function () {
|
||||||
|
|
|
@ -559,7 +559,7 @@
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
var channelScheme = "https" === window.location.protocol ? "wss":"ws";
|
var channelScheme = "https" === window.location.protocol ? "wss":"ws";
|
||||||
var channel = channelScheme + "://" + window.location.hostname;
|
var channel = channelScheme + "://" + window.location.hostname + ":" + window.location.port;
|
||||||
var config = {
|
var config = {
|
||||||
"pathSeparator": '{{.pathSeparator}}',
|
"pathSeparator": '{{.pathSeparator}}',
|
||||||
"label": {{.i18n}},
|
"label": {{.i18n}},
|
||||||
|
|
|
@ -82,7 +82,7 @@
|
||||||
<div id="dialogShare" class="fn-none"></div>
|
<div id="dialogShare" class="fn-none"></div>
|
||||||
<script>
|
<script>
|
||||||
var channelScheme = "https" === window.location.protocol ? "wss":"ws";
|
var channelScheme = "https" === window.location.protocol ? "wss":"ws";
|
||||||
var channel = channelScheme + "://" + window.location.hostname;
|
var channel = channelScheme + "://" + window.location.hostname + ":" + window.location.port;
|
||||||
var config = {
|
var config = {
|
||||||
"channel": channel,
|
"channel": channel,
|
||||||
"wideSessionId": "{{.sid}}",
|
"wideSessionId": "{{.sid}}",
|
||||||
|
|
Loading…
Reference in New Issue