Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
go embed
Browse files Browse the repository at this point in the history
  • Loading branch information
BaiMeow committed Jun 24, 2021
1 parent d3b37d4 commit 11fe16b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func main() {
}

func onGameStart() error {
log.Info("加入游戏.")
log.Info("加入游戏")
watch = make(chan bool)
go watchdog()
go listenMsg()
Expand Down
2 changes: 1 addition & 1 deletion web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h2>Msc自动钓鱼</h2>
const app = Vue.createApp(Main);
app.use(ElementPlus);
v = app.mount('#app')
var ws = new WebSocket("ws://localhost:8080/ws")
var ws = new WebSocket("ws://"+location.host+"/ws")
ws.onopen = function () {
var d = new Date();
v.logsData = [{
Expand Down
9 changes: 7 additions & 2 deletions web/web.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package web

import (
_ "embed"
"sync"
"time"

Expand All @@ -26,15 +27,19 @@ var upgrader = ws.Upgrader{

var data updateData

//go:embed templates\index.html
var index []byte

func init() {
data.logs = make(chan log, 1024)
}

func WebRun(sendMsg func(string) error, log *logrus.Logger) {
r := gin.Default()
r.LoadHTMLGlob("web/templates/*")
r.GET("/", func(c *gin.Context) {
c.HTML(200, "index.html", nil)
if _, err := c.Writer.Write(index); err != nil {
log.Warn(err)
}
})
r.GET("/ws", func(c *gin.Context) {
conn, err := upgrader.Upgrade(c.Writer, c.Request, nil)
Expand Down

0 comments on commit 11fe16b

Please sign in to comment.