|
@ -0,0 +1,100 @@ |
|
|
|
|
|
package main |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
|
"git.ouxuan.net/3136352472/go-service-template/jsruntime" |
|
|
|
|
|
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskutils" |
|
|
|
|
|
"github.com/gin-gonic/gin" |
|
|
|
|
|
"io/ioutil" |
|
|
|
|
|
"log" |
|
|
|
|
|
"os" |
|
|
|
|
|
"path/filepath" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
|
|
|
|
|
|
|
|
os.Chdir("domino") |
|
|
|
|
|
|
|
|
|
|
|
r := gin.Default() |
|
|
|
|
|
|
|
|
|
|
|
mainFile := filepath.Join(hskutils.GetSelfFilePath(), "govue", "govue.js") |
|
|
|
|
|
useFileName := filepath.Join(hskutils.GetSelfFilePath(), "static", "use.js") |
|
|
|
|
|
render, err := jsruntime.NewJsRuntime(mainFile, useFileName, jsruntime.Relys{ |
|
|
|
|
|
jsruntime.Rely{ |
|
|
|
|
|
Variable: "domino", |
|
|
|
|
|
FileName: "./index.js", |
|
|
|
|
|
}, |
|
|
|
|
|
jsruntime.Rely{ |
|
|
|
|
|
Variable: "Vue", |
|
|
|
|
|
FileName: "./vue.js", |
|
|
|
|
|
}, |
|
|
|
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mainScript, err := ioutil.ReadFile(filepath.Join(hskutils.GetSelfFilePath(), "govue", "govue.js")) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(err.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
r.NoRoute(func(context *gin.Context) { |
|
|
|
|
|
path := filepath.Join(hskutils.GetSelfFilePath(), "static", context.Request.URL.Path) |
|
|
|
|
|
fi, err := os.Stat(path) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
context.Writer.Write([]byte("页面不存在")) |
|
|
|
|
|
return |
|
|
|
|
|
} else if fi.IsDir() { |
|
|
|
|
|
path = filepath.Join(path, "index.html") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
raw, err := ioutil.ReadFile(path) |
|
|
|
|
|
if !hskutils.PathExists(path) || err != nil { |
|
|
|
|
|
context.Writer.Write([]byte("页面不存在")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
if filepath.Ext(path) != ".html" { |
|
|
|
|
|
//log.Println("ext", filepath.Ext(path))
|
|
|
|
|
|
context.Writer.WriteHeader(200) |
|
|
|
|
|
context.Writer.Write(raw) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
htmlSrc := string(raw) |
|
|
|
|
|
|
|
|
|
|
|
registry.Lock() |
|
|
|
|
|
defer registry.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
useScript, err := ioutil.ReadFile(filepath.Join(hskutils.GetSelfFilePath(), "static", "use.js")) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(err.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
runtime.Set("GoVueUse", func(v interface{}) { |
|
|
|
|
|
runtime.Set("GoVueUseCall", v) |
|
|
|
|
|
}) |
|
|
|
|
|
_, err = runtime.RunString(string(useScript)) |
|
|
|
|
|
|
|
|
|
|
|
runtime.Set("HTML_SRC", htmlSrc) |
|
|
|
|
|
|
|
|
|
|
|
runtime.Set("HTML_OUT", func(data string) { |
|
|
|
|
|
context.Writer.WriteHeader(200) |
|
|
|
|
|
context.Writer.Write([]byte(data)) |
|
|
|
|
|
|
|
|
|
|
|
return |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
_, err = runtime.RunString(string(mainScript)) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
context.Writer.Write([]byte("")) |
|
|
|
|
|
|
|
|
|
|
|
return |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
r.Run("127.0.0.1:8080") |
|
|
|
|
|
|
|
|
|
|
|
} |