Skip to content

Commit

Permalink
feat: 更换go embed和修复线程崩溃的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ystyle committed Aug 9, 2023
1 parent 93af810 commit 4e9793e
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 546 deletions.
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
FROM golang:alpine AS build-env
ENV GO111MODULE=on
FROM golang:1.18-alpine AS build-env
ENV GOPROXY=goproxy.cn,direct
ADD . /go/src/app
WORKDIR /go/src/app
RUN apk --update add git curl tzdata && \
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk --update add git curl tzdata && \
go build -v -o /go/src/app/kas main.go && \
export GO111MODULE=off && \
go get github.com/GeertJohan/go.rice && \
go get github.com/GeertJohan/go.rice/rice && \
find / -name "rice" && \
rice append --exec kas && \
curl https://archive.org/download/kindlegen2.9/kindlegen_linux_2.6_i386_v2_9.tar.gz | tar -zx

FROM alpine
COPY --from=build-env /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
COPY --from=build-env /go/src/app/kas /app/kas
COPY --from=build-env /go/src/app/kindlegen /bin/kindlegen
RUN apk --update add --no-cache curl
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk --update add --no-cache curl
WORKDIR /app
VOLUME ["/app/storage"]
HEALTHCHECK --interval=1m --timeout=10s \
Expand Down
11 changes: 9 additions & 2 deletions core/WsClient.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package core

import (
"context"
"encoding/json"
"github.com/gorilla/websocket"
"github.com/labstack/gommon/log"
Expand All @@ -15,14 +16,19 @@ const (

type WsClient struct {
WsConn *websocket.Conn
ctx context.Context
cancel context.CancelFunc
HttpRequest *http.Request
wsManager *WsManager
WsSend chan Message
Caches map[string]interface{}
}

func NewWsClient(wsConn *websocket.Conn, resp *http.Request) *WsClient {
func NewWsClient(ctx context.Context, wsConn *websocket.Conn, resp *http.Request) *WsClient {
ctx1, cancel := context.WithTimeout(ctx, readTimeOut)
return &WsClient{
ctx: ctx1,
cancel: cancel,
WsConn: wsConn,
HttpRequest: resp,
WsSend: make(chan Message, 10),
Expand All @@ -37,7 +43,6 @@ func (client *WsClient) GetWSKey() string {
func (client *WsClient) ReadMsg(fn func(c *WsClient, message Message)) {
defer func() {
client.wsManager.Unregister <- client
client.WsConn.Close()
}()
client.WsConn.SetReadDeadline(time.Now().Add(readTimeOut))
client.WsConn.SetPongHandler(func(string) error {
Expand Down Expand Up @@ -82,6 +87,8 @@ func (client *WsClient) WriteMsg() {
}
msg.Time = time.Now()
client.WsConn.WriteJSON(msg)
case <-client.ctx.Done():
return
case <-ticker.C:
client.WsConn.SetWriteDeadline(time.Now().Add(writeTimeOut))
if err := client.WsConn.WriteMessage(websocket.PingMessage, nil); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions core/WsManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/labstack/gommon/log"
"github.com/ystyle/kas/util"
"github.com/ystyle/kas/util/env"
"golang.org/x/net/context"
)

type Service func(client *WsClient, message Message)
Expand All @@ -15,6 +16,7 @@ type WsManager struct {
services map[string]Service
Register chan *WsClient
Unregister chan *WsClient
ctx context.Context
}

var wm = &WsManager{
Expand Down Expand Up @@ -43,6 +45,7 @@ func (m *WsManager) Run() {
process(client)
case client := <-m.Unregister:
if _, ok := m.clients[client]; ok {
client.cancel()
delete(m.clients, client)
close(client.WsSend)
}
Expand Down
16 changes: 9 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,34 @@ module github.com/ystyle/kas
go 1.18

require (
github.com/GeertJohan/go.rice v1.0.2
github.com/PuerkitoBio/goquery v1.8.0
github.com/asdine/storm/v3 v3.2.1
github.com/bmaupin/go-epub v0.11.0
github.com/bmaupin/go-epub v1.1.0
github.com/gorilla/websocket v1.5.0
github.com/labstack/echo/v4 v4.7.2
github.com/labstack/echo/v4 v4.9.0
github.com/labstack/gommon v0.3.1
github.com/satori/go.uuid v1.2.0
golang.org/x/net v0.0.0-20220517181318-183a9ca12b87
golang.org/x/text v0.3.7
github.com/ystyle/google-analytics v0.0.0-20210425064301-a7f754dd0649
github.com/ystyle/kaf-cli v1.3.5
golang.org/x/net v0.7.0
golang.org/x/text v0.7.0
)

require (
github.com/766b/mobi v0.0.0-20200528201125-c87aa9e3c890 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/daaku/go.zipexe v1.0.0 // indirect
github.com/gabriel-vasile/mimetype v1.3.1 // indirect
github.com/gofrs/uuid v3.1.0+incompatible // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/leotaku/mobi v0.0.0-20220405163106-82e29bde7964 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
github.com/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50 // indirect
go.etcd.io/bbolt v1.3.4 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
)

Expand Down
36 changes: 18 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
github.com/766b/mobi v0.0.0-20200528201125-c87aa9e3c890 h1:5EBpQM2h7OdIRR1jw1IypiKzbYo/8Hx5/iRxgqPSKFI=
github.com/766b/mobi v0.0.0-20200528201125-c87aa9e3c890/go.mod h1:ut/OVrYa64AAfis3e0GO4uEb8mwXSJoqAqnIMQd24HQ=
github.com/DataDog/zstd v1.4.1 h1:3oxKN3wbHibqx897utPC2LTQU4J+IHWWJO+glkAkpFM=
github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.2 h1:PtRw+Tg3oa3HYwiDBZyvOJ8LdIyf6lAovJJtr7YOAYk=
github.com/GeertJohan/go.rice v1.0.2/go.mod h1:af5vUNlDNkCjOZeSGFgIJxDje9qdjsO6hshx0gTmZt4=
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
github.com/Sereal/Sereal v0.0.0-20190618215532-0b8ac451a863 h1:BRrxwOZBolJN4gIwvZMJY1tzqBvQgpaZiQRuIDD40jM=
github.com/Sereal/Sereal v0.0.0-20190618215532-0b8ac451a863/go.mod h1:D0JMgToj/WdxCgd30Kc1UcA9E+WdZoJqeVOuYW7iTBM=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
github.com/asdine/storm/v3 v3.2.1 h1:I5AqhkPK6nBZ/qJXySdI7ot5BlXSZ7qvDY1zAn5ZJac=
github.com/asdine/storm/v3 v3.2.1/go.mod h1:LEpXwGt4pIqrE/XcTvCnZHT5MgZCV6Ub9q7yQzOFWr0=
github.com/bmaupin/go-epub v0.11.0 h1:yb9Mr/G7vWIhD/SdFQm13LF8NrvYo0u0XBiGWVQMuCc=
github.com/bmaupin/go-epub v0.11.0/go.mod h1:mBan+0WgVv5JbPNw1xfnfQoTRN9iPMKBshZwPOL0SY0=
github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
github.com/bmaupin/go-epub v1.1.0 h1:XJyvvjchtUlbZ2P7eaEeB8EFw2NgVY5ycREFpmd6MKM=
github.com/bmaupin/go-epub v1.1.0/go.mod h1:mBan+0WgVv5JbPNw1xfnfQoTRN9iPMKBshZwPOL0SY0=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -25,32 +21,29 @@ github.com/gofrs/uuid v3.1.0+incompatible h1:q2rtkjaKT4YEr6E1kamy0Ha4RtepWlQBedy
github.com/gofrs/uuid v3.1.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang/net v0.0.0-20220517181318-183a9ca12b87 h1:pgC/B7YWMYjrJjm+ChOBWExXKvW6NOiMySa3sjRg0Xk=
github.com/golang/net v0.0.0-20220517181318-183a9ca12b87/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/text v0.3.7 h1:hWROwze5r6fsVDfAiA9gq0PTUwL9PtladweUyeKBges=
github.com/golang/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/labstack/echo/v4 v4.7.2 h1:Kv2/p8OaQ+M6Ex4eGimg9b9e6icoxA42JSlOR3msKtI=
github.com/labstack/echo/v4 v4.7.2/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
github.com/labstack/echo/v4 v4.9.0 h1:wPOF1CE6gvt/kmbMR4dGzWvHMPT+sAEUJOwOTtvITVY=
github.com/labstack/echo/v4 v4.9.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o=
github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/leotaku/mobi v0.0.0-20220405163106-82e29bde7964 h1:h7CxQNRMxzHmVvDV1TPudN9XUF0YxYnh966lQ3kqEoo=
github.com/leotaku/mobi v0.0.0-20220405163106-82e29bde7964/go.mod h1:aPjSURhp6tj0b/dLHyjzeygcitkmvO2/SO368XiPtrs=
github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
Expand All @@ -61,13 +54,16 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50 h1:uxE3GYdXIOfhMv3unJKETJEhw78gvzuQqRX/rVirc2A=
github.com/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50/go.mod h1:FHafX5vmDzyP+1CQATJn7WFKc9CvnvxyvZy6I1MrG/U=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/ystyle/google-analytics v0.0.0-20210425064301-a7f754dd0649 h1:2uiow2Fw91jCIiYwMKvPF/lUMMdtVjgVpwqTcbC0fPU=
github.com/ystyle/google-analytics v0.0.0-20210425064301-a7f754dd0649/go.mod h1:j2L81Z+juG+93VLJWQL25LeFnI2LygARlF/YbdAo2vg=
github.com/ystyle/kaf-cli v1.3.5 h1:207cy4L9CekEpI/d4En67P6BwrADs9CCTz7B8XHfFKg=
github.com/ystyle/kaf-cli v1.3.5/go.mod h1:4Ij/jfvjNhI9r2lAdnTVXlGM5pkEF52Ze+kwo7rX3ss=
go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg=
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand All @@ -77,19 +73,23 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR
golang.org/x/net v0.0.0-20191105084925-a882066a44e0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
23 changes: 12 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main

import (
"context"
"embed"
"fmt"
"github.com/GeertJohan/go.rice"
"github.com/gorilla/websocket"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
Expand All @@ -13,7 +14,6 @@ import (
"github.com/ystyle/kas/util/config"
"github.com/ystyle/kas/util/file"
"github.com/ystyle/kas/util/hcomic"
"github.com/ystyle/kas/util/site"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -41,6 +41,9 @@ func init() {
file.CheckDir(config.StoreDir)
}

//go:embed public
var fs embed.FS

func main() {
log.EnableColor()
if os.Getenv("MODE") == "DEBUG" {
Expand All @@ -56,8 +59,6 @@ func main() {
wm.RegisterService("text:preview", services.TextPreView)
wm.RegisterService("text:convert", services.TextConvert)
wm.RegisterService("text:download", services.TextDownload)
// aricle
wm.RegisterService("article:submit", services.ArticleSubmit)
// ping
wm.RegisterService("ping", services.Ping)
// 注册设备
Expand All @@ -69,12 +70,12 @@ func main() {
e.Use(middleware.RequestID())
e.Use(middleware.Gzip())

box := rice.MustFindBox("public")
assetHandler := http.FileServer(box.HTTPBox())
site.Init(box)

e.GET("/*", echo.WrapHandler(assetHandler))
e.GET("/asset/*", echo.WrapHandler(assetHandler))
assetHandler := http.FileServer(http.FS(fs))
contentRewrite := middleware.Rewrite(map[string]string{
"/*": "/public/$1",
})
e.GET("/*", echo.WrapHandler(assetHandler), contentRewrite)
e.GET("/asset/*", echo.WrapHandler(assetHandler), contentRewrite)
e.Static("/download", "storage")
e.GET("/ws", WS)
e.GET("/ws#", WS)
Expand All @@ -96,7 +97,7 @@ func WS(c echo.Context) error {
return err
}
wm := core.GetWsManager()
wm.Register <- core.NewWsClient(ws, c.Request())
wm.Register <- core.NewWsClient(context.Background(), ws, c.Request())
return nil
}

Expand Down
40 changes: 0 additions & 40 deletions model/article.go

This file was deleted.

Loading

0 comments on commit 4e9793e

Please sign in to comment.