commit
58523f731d
@ -3,13 +3,15 @@ FROM golang:1.20.4-alpine3.18 AS builder
|
|||||||
COPY . /src
|
COPY . /src
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
|
#国内服务器可以取消以下注释
|
||||||
|
#RUN go env -w GO111MODULE=on && \
|
||||||
|
# go env -w GOPROXY=https://goproxy.cn,direct
|
||||||
|
|
||||||
RUN go build -ldflags "-s -w" -o ./bin/ .
|
RUN go build -ldflags "-s -w" -o ./bin/ .
|
||||||
|
|
||||||
FROM alpine
|
FROM alpine
|
||||||
|
|
||||||
COPY --from=builder /src/bin /app
|
COPY --from=builder /src/bin /app
|
||||||
COPY --from=builder /src/index.html /app/index.html
|
|
||||||
COPY --from=builder /src/static /app/static
|
|
||||||
COPY --from=builder /src/config.json /app/config.json
|
COPY --from=builder /src/config.json /app/config.json
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|||||||
@ -57,6 +57,12 @@ git clone https://github.com/srcrs/rss-reader
|
|||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
|
国内服务器将Dockerfile中取消下面注释使用 go mod 镜像
|
||||||
|
```dockerfile
|
||||||
|
#RUN go env -w GO111MODULE=on && \
|
||||||
|
# go env -w GOPROXY=https://goproxy.cn,direct
|
||||||
|
```
|
||||||
|
|
||||||
部署成功后,通过ip+端口号访问
|
部署成功后,通过ip+端口号访问
|
||||||
|
|
||||||
# nginx反代
|
# nginx反代
|
||||||
|
|||||||
20
main.go
20
main.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -25,6 +26,13 @@ var (
|
|||||||
rssUrls Config
|
rssUrls Config
|
||||||
upgrader = websocket.Upgrader{}
|
upgrader = websocket.Upgrader{}
|
||||||
connMu sync.Mutex // 定义互斥锁
|
connMu sync.Mutex // 定义互斥锁
|
||||||
|
|
||||||
|
//go:embed static
|
||||||
|
dirStatic embed.FS
|
||||||
|
//go:embed index.html
|
||||||
|
fileIndex embed.FS
|
||||||
|
|
||||||
|
htmlContent []byte
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -38,6 +46,11 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
// 读取 index.html 内容
|
||||||
|
htmlContent, err = fileIndex.ReadFile("index.html")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
initDB()
|
initDB()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,13 +71,14 @@ func main() {
|
|||||||
http.HandleFunc("/", serveHome)
|
http.HandleFunc("/", serveHome)
|
||||||
|
|
||||||
//加载静态文件
|
//加载静态文件
|
||||||
fs := http.FileServer(http.Dir("static"))
|
fs := http.FileServer(http.FS(dirStatic))
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
http.Handle("/static/", fs)
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveHome(w http.ResponseWriter, r *http.Request) {
|
func serveHome(w http.ResponseWriter, r *http.Request) {
|
||||||
http.ServeFile(w, r, "index.html")
|
w.Header().Add("Content-Type", "text/html; charset=utf-8")
|
||||||
|
w.Write(htmlContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func wsHandler(w http.ResponseWriter, r *http.Request) {
|
func wsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user