mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-04 22:02:26 +08:00
Compare commits
45 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
433064de00 | ||
|
|
9d71ca8198 | ||
|
|
7c938bf024 | ||
|
|
65fcc69efa | ||
|
|
d06bab72a5 | ||
|
|
95900eec1a | ||
|
|
dfae78891d | ||
|
|
c515e33e2c | ||
|
|
5b12dd625b | ||
|
|
9b918caccd | ||
|
|
2be53379e1 | ||
|
|
944e27c58a | ||
|
|
92baf970bc | ||
|
|
64a754167a | ||
|
|
af2a20c34a | ||
|
|
f28d0e77e0 | ||
|
|
9a1b4db61a | ||
|
|
c9d04aded3 | ||
|
|
ee51f678cb | ||
|
|
434c1bf168 | ||
|
|
d2de603957 | ||
|
|
e7fdf6b1db | ||
|
|
305ae0ee70 | ||
|
|
a5749fdab6 | ||
|
|
391f19e2a9 | ||
|
|
2c6c5bb977 | ||
|
|
860a85e209 | ||
|
|
2a8d9b3bbd | ||
|
|
1509a68cda | ||
|
|
7f26503247 | ||
|
|
235145ed46 | ||
|
|
20e89d6a76 | ||
|
|
d86ab71ad9 | ||
|
|
4600ed5094 | ||
|
|
5fcadd1c81 | ||
|
|
42b106d582 | ||
|
|
bb06be36fe | ||
|
|
cb3fb2d2e7 | ||
|
|
779a23cb75 | ||
|
|
e2fa96cd62 | ||
|
|
db26fb51e5 | ||
|
|
994be5d508 | ||
|
|
a5c3d33565 | ||
|
|
1ffc58eccf | ||
|
|
b6ad4e8949 |
@@ -1,12 +1,12 @@
|
||||
# Ignore all files and dirs
|
||||
*
|
||||
|
||||
|
||||
# Unignore files or dirs
|
||||
!build
|
||||
!bin
|
||||
!conf
|
||||
!assets
|
||||
!website
|
||||
!CHANGELOG.md
|
||||
!LICENSE
|
||||
!README.md
|
||||
.github
|
||||
bin
|
||||
docs
|
||||
.gitignore
|
||||
db.sqlite
|
||||
docker-compose.yml
|
||||
eiblog.conf
|
||||
Makefile
|
||||
|
||||
54
.github/workflows/release.yml
vendored
54
.github/workflows/release.yml
vendored
@@ -9,35 +9,47 @@ jobs:
|
||||
package:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Golang env
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ^1.15
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Cache mod
|
||||
uses: actions/cache@v1
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Docker tag
|
||||
id: vars
|
||||
run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Docker login
|
||||
uses: docker/login-action@v1
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
- name: Build image
|
||||
env:
|
||||
GOPROXY: https://goproxy.io,direct
|
||||
run: scripts/run_build.sh deepzz0 ${{ steps.vars.outputs.tag }}
|
||||
|
||||
- name: Build and push eiblog
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
context: .
|
||||
file: ./build/package/eiblog.Dockerfile
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
push: true
|
||||
tags: |
|
||||
deepzz0/eiblog:${{ steps.vars.outputs.tag }}
|
||||
deepzz0/eiblog:latest
|
||||
|
||||
- name: Build and push backup
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
context: .
|
||||
file: ./build/package/backup.Dockerfile
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
push: true
|
||||
tags: |
|
||||
deepzz0/backup:${{ steps.vars.outputs.tag }}
|
||||
deepzz0/backup:latest
|
||||
|
||||
- name: Package tar
|
||||
env:
|
||||
|
||||
69
CHANGELOG.md
69
CHANGELOG.md
@@ -2,6 +2,75 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
### [2.2.11](https://github.com/eiblog/eiblog/compare/v2.2.10...v2.2.11) (2024-01-02)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **disqus:** fix returned posts list not have parent post ([9d71ca8](https://github.com/eiblog/eiblog/commit/9d71ca81988bfc614d13fcb02079f0dba9ef43cc))
|
||||
|
||||
### [2.2.10](https://github.com/eiblog/eiblog/compare/v2.2.9...v2.2.10) (2023-12-22)
|
||||
|
||||
### [2.2.9](https://github.com/eiblog/eiblog/compare/v2.2.8...v2.2.9) (2023-09-25)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* google analytics not work, supported ga4 measurement protocol ([9b918ca](https://github.com/eiblog/eiblog/commit/9b918caccd9fd7faff7d253693e075ccd0150c17))
|
||||
|
||||
### [2.2.8](https://github.com/eiblog/eiblog/compare/v2.2.7...v2.2.8) (2023-07-12)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **backup:** restore db and tests ([f28d0e7](https://github.com/eiblog/eiblog/commit/f28d0e77e06dd435dc13a1867f18a011e34b8f53))
|
||||
|
||||
### [2.2.7](https://github.com/eiblog/eiblog/compare/v2.2.6...v2.2.7) (2023-07-12)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **backup:** 数据恢复错误 ([ee51f67](https://github.com/eiblog/eiblog/commit/ee51f678cbf93332fedccf927704e78a6063289c))
|
||||
|
||||
### [2.2.6](https://github.com/eiblog/eiblog/compare/v2.2.5...v2.2.6) (2023-06-19)
|
||||
|
||||
### [2.2.5](https://github.com/eiblog/eiblog/compare/v2.2.4...v2.2.5) (2023-05-26)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **backup:** libresolv.so.2: No such file or directory ([2c6c5bb](https://github.com/eiblog/eiblog/commit/2c6c5bb97708683bed8c889a7a1076f1f88ee5a8))
|
||||
|
||||
### [2.2.4](https://github.com/eiblog/eiblog/compare/v2.2.3...v2.2.4) (2023-05-25)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **ci:** fix .dockerignore ([1509a68](https://github.com/eiblog/eiblog/commit/1509a68cda74ace6b4060b5015f20143303ca36f))
|
||||
|
||||
### [2.2.3](https://github.com/eiblog/eiblog/compare/v2.2.2...v2.2.3) (2023-05-25)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **ci:** script file name ([20e89d6](https://github.com/eiblog/eiblog/commit/20e89d6a76f01aee60b98f8ae43a2c65b4fb3904))
|
||||
|
||||
### [2.2.2](https://github.com/eiblog/eiblog/compare/v2.2.1...v2.2.2) (2023-05-25)
|
||||
|
||||
### [2.2.1](https://github.com/eiblog/eiblog/compare/v2.2.0...v2.2.1) (2023-05-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* try to fix backup symbol not found ([bb06be3](https://github.com/eiblog/eiblog/commit/bb06be36fe016e753ca56aa2321ce7e39bffe3e0))
|
||||
|
||||
## [2.2.0](https://github.com/eiblog/eiblog/compare/v2.1.18...v2.2.0) (2023-05-17)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **backup:** add restore flag ([779a23c](https://github.com/eiblog/eiblog/commit/779a23cb75ab5059826370d08b754569a4af4aea))
|
||||
|
||||
### [2.1.18](https://github.com/eiblog/eiblog/compare/v2.1.17...v2.1.18) (2023-01-05)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# EiBlog [](https://travis-ci.org/eiblog/eiblog) [](LICENSE.md) [](https://github.com/eiblog/eiblog/releases)
|
||||
# EiBlog [](LICENSE.md) [](https://github.com/eiblog/eiblog/releases)
|
||||
|
||||
> 博客项目结构参考模版:https://github.com/deepzz0/appdemo
|
||||
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
FROM golang:1.20 AS builder
|
||||
|
||||
WORKDIR /eiblog
|
||||
COPY . .
|
||||
RUN ./scripts/run_build.sh backup
|
||||
|
||||
|
||||
FROM alpine:latest
|
||||
LABEL maintainer="deepzz.qi@gmail.com"
|
||||
|
||||
RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories \
|
||||
&& apk add --update --no-cache tzdata ca-certificates mongodb-tools libc6-compat
|
||||
RUN apk add --update --no-cache tzdata ca-certificates \
|
||||
mongodb-tools libc6-compat gcompat
|
||||
COPY README.md /app/README.md
|
||||
COPY CHANGELOG.md /app/CHANGELOG.md
|
||||
COPY LICENSE /app/LICENSE
|
||||
|
||||
COPY bin/backend /app/backend
|
||||
COPY --from=builder /eiblog/bin/backend /app/backend
|
||||
COPY conf /app/conf
|
||||
|
||||
EXPOSE 9001
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
FROM golang:1.20 AS builder
|
||||
|
||||
WORKDIR /eiblog
|
||||
COPY . .
|
||||
RUN ./scripts/run_build.sh eiblog
|
||||
|
||||
|
||||
FROM alpine:latest
|
||||
LABEL maintainer="deepzz.qi@gmail.com"
|
||||
|
||||
RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories \
|
||||
&& apk add --update --no-cache tzdata
|
||||
RUN apk add --update --no-cache tzdata
|
||||
COPY README.md /app/README.md
|
||||
COPY CHANGELOG.md /app/CHANGELOG.md
|
||||
COPY LICENSE /app/LICENSE
|
||||
|
||||
COPY bin/backend /app/backend
|
||||
COPY --from=builder /eiblog/bin/backend /app/backend
|
||||
COPY conf /app/conf
|
||||
COPY website /app/website
|
||||
COPY assets /app/assets
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/eiblog/eiblog/pkg/config"
|
||||
@@ -12,20 +13,27 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var restore bool
|
||||
|
||||
func init() {
|
||||
flag.BoolVar(&restore, "restore", false, "restore data into mongodb")
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hi, it's App " + config.Conf.BackupApp.Name)
|
||||
flag.Parse()
|
||||
|
||||
endRun := make(chan error, 1)
|
||||
|
||||
runTimer(endRun)
|
||||
runCommand(restore, endRun)
|
||||
|
||||
runHTTPServer(endRun)
|
||||
fmt.Println(<-endRun)
|
||||
}
|
||||
|
||||
func runTimer(endRun chan error) {
|
||||
func runCommand(restore bool, endRun chan error) {
|
||||
go func() {
|
||||
endRun <- timer.Start()
|
||||
endRun <- timer.Start(restore)
|
||||
}()
|
||||
}
|
||||
|
||||
|
||||
11
conf/app.yml
11
conf/app.yml
@@ -2,7 +2,7 @@ appname: eiblog
|
||||
database:
|
||||
driver: sqlite
|
||||
source: ./db.sqlite
|
||||
eshost:
|
||||
eshost: # http://elasticsearch:9200
|
||||
eiblogapp:
|
||||
mode:
|
||||
name: cmd-eiblog
|
||||
@@ -28,11 +28,10 @@ eiblogapp:
|
||||
publickey: wdSgxRm9rdGAlLKFcFdToBe3GT4SibmV7Y8EjJQ0r4GWXeKtxpopMAeIeoI2dTEg
|
||||
accesstoken: 50023908f39f4607957e909b495326af
|
||||
google: # 谷歌分析
|
||||
url: https://www.google-analytics.com/collect
|
||||
tid: UA-xxxxxx-1
|
||||
v: "1"
|
||||
t: pageview
|
||||
adsense: <script data-ad-client="ca-pub-5384494508691406" async src=""></script>
|
||||
url: https://www.google-analytics.com/g/collect
|
||||
tid: G-xxxxxxxxxx
|
||||
v: "2"
|
||||
adsense: <script async src="https://pagead2.googlesyndication.com/xxx" crossorigin="anonymous"></script>
|
||||
qiniu: # 七牛OSS
|
||||
bucket: eiblog
|
||||
domain: st.deepzz.com
|
||||
|
||||
@@ -11,7 +11,7 @@ services:
|
||||
- ${PWD}/esdata:/usr/share/elasticsearch/data
|
||||
restart: always
|
||||
eiblog:
|
||||
iamge: deepzz0/eiblog:latest
|
||||
image: deepzz0/eiblog:latest
|
||||
volumes:
|
||||
- ${PWD}/conf:/app/conf
|
||||
extra_hosts:
|
||||
@@ -27,6 +27,7 @@ services:
|
||||
restart: always
|
||||
backup:
|
||||
image: deepzz0/backup:latest
|
||||
#command: ./backend --restore true
|
||||
volumes:
|
||||
- ${PWD}/conf:/app/conf
|
||||
links:
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||

|
||||
|
||||
### 图片懒加载
|
||||
博客系统提供图片懒加载功能(浏览到某个位置,图片才会加载),以此来提高页面加载速度。我们可根据需要是否使用。当然由此带来的坏处就是rss不能够正确加载图片。后续看是否解决这个问题或朋友提PR。
|
||||
博客系统提供图片懒加载功能(浏览到某个位置,图片才会加载),以此来提高页面加载速度。我们可根据需要是否使用。~~当然由此带来的坏处就是rss不能够正确加载图片。后续看是否解决这个问题或朋友提PR。~~,已解决。
|
||||
|
||||
首先看下图片的`markdown`标准写法:
|
||||
```
|
||||
|
||||
@@ -78,9 +78,6 @@ server {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
location ^~ /admin/ {
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
|
||||
# https://imququ.com/post/web-security-and-response-header.html#toc-1
|
||||
# 期望CT: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect-CT
|
||||
add_header Expect-CT "max-age=180";
|
||||
add_header Cache-Control no-cache;
|
||||
add_header X-Frame-Options SAMEORIGIN;
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
@@ -93,9 +90,6 @@ server {
|
||||
|
||||
location / {
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
|
||||
# https://imququ.com/post/web-security-and-response-header.html#toc-1
|
||||
# 期望CT: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect-CT
|
||||
add_header Expect-CT "max-age=180";
|
||||
add_header Cache-Control no-cache;
|
||||
# 内容安全策略: https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
|
||||
add_header Content-Security-Policy "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' blob: https:; img-src data: https:; media-src https:; style-src 'unsafe-inline' https:; child-src https:; connect-src 'self'; frame-src https://disqus.com";
|
||||
|
||||
28
go.mod
28
go.mod
@@ -4,23 +4,21 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/eiblog/blackfriday v0.0.0-20161010144836-c0ec111761ae
|
||||
github.com/gin-contrib/sessions v0.0.3
|
||||
github.com/gin-gonic/gin v1.7.4
|
||||
github.com/golang/protobuf v1.4.2
|
||||
github.com/lib/pq v1.10.1
|
||||
github.com/gin-contrib/sessions v0.0.5
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
github.com/lib/pq v1.10.9
|
||||
github.com/qiniu/go-sdk/v7 v7.11.0
|
||||
github.com/satori/go.uuid v1.2.0
|
||||
github.com/sirupsen/logrus v1.4.2
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14
|
||||
github.com/swaggo/gin-swagger v1.3.3
|
||||
github.com/swaggo/swag v1.7.4
|
||||
go.mongodb.org/mongo-driver v1.5.1
|
||||
google.golang.org/grpc v1.35.0
|
||||
google.golang.org/protobuf v1.25.0
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||
gorm.io/driver/clickhouse v0.1.0
|
||||
gorm.io/driver/mysql v1.0.6
|
||||
gorm.io/driver/postgres v1.0.8
|
||||
gorm.io/driver/sqlite v1.1.4
|
||||
gorm.io/driver/sqlserver v1.0.7
|
||||
gorm.io/gorm v1.21.9
|
||||
go.mongodb.org/mongo-driver v1.11.4
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
gorm.io/driver/clickhouse v0.6.0
|
||||
gorm.io/driver/mysql v1.5.2
|
||||
gorm.io/driver/postgres v1.5.4
|
||||
gorm.io/driver/sqlite v1.5.4
|
||||
gorm.io/driver/sqlserver v1.5.2
|
||||
gorm.io/gorm v1.25.5
|
||||
)
|
||||
|
||||
5
pkg/cache/store/mongodb.go
vendored
5
pkg/cache/store/mongodb.go
vendored
@@ -326,6 +326,11 @@ func (db *mongodb) LoadArticleList(ctx context.Context, search SearchArticles) (
|
||||
return articles, int(count), nil
|
||||
}
|
||||
|
||||
// DropDatabase drop eiblog database
|
||||
func (db *mongodb) DropDatabase(ctx context.Context) error {
|
||||
return db.Database(mongoDBName).Drop(ctx)
|
||||
}
|
||||
|
||||
// counter counter
|
||||
type counter struct {
|
||||
Name string
|
||||
|
||||
84
pkg/cache/store/mongodb_test.go
vendored
84
pkg/cache/store/mongodb_test.go
vendored
@@ -13,7 +13,7 @@ var (
|
||||
store Store
|
||||
acct *model.Account
|
||||
blogger *model.Blogger
|
||||
series *model.Series
|
||||
series *model.Serie
|
||||
article *model.Article
|
||||
)
|
||||
|
||||
@@ -25,12 +25,12 @@ func init() {
|
||||
}
|
||||
// account
|
||||
acct = &model.Account{
|
||||
Username: "deepzz",
|
||||
Password: "deepzz",
|
||||
Email: "deepzz@example.com",
|
||||
PhoneN: "12345678900",
|
||||
Address: "address",
|
||||
CreateTime: time.Now(),
|
||||
Username: "deepzz",
|
||||
Password: "deepzz",
|
||||
Email: "deepzz@example.com",
|
||||
PhoneN: "12345678900",
|
||||
Address: "address",
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
// blogger
|
||||
blogger = &model.Blogger{
|
||||
@@ -41,11 +41,11 @@ func init() {
|
||||
Copyright: "Copyright",
|
||||
}
|
||||
// series
|
||||
series = &model.Series{
|
||||
Slug: "slug",
|
||||
Name: "series name",
|
||||
Desc: "series desc",
|
||||
CreateTime: time.Now(),
|
||||
series = &model.Serie{
|
||||
Slug: "slug",
|
||||
Name: "series name",
|
||||
Desc: "series desc",
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
// article
|
||||
article = &model.Article{
|
||||
@@ -55,21 +55,20 @@ func init() {
|
||||
Count: 0,
|
||||
Content: "### count",
|
||||
SerieID: 0,
|
||||
Tags: "",
|
||||
Tags: nil,
|
||||
IsDraft: false,
|
||||
|
||||
UpdateTime: time.Now(),
|
||||
CreateTime: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadInsertAccount(t *testing.T) {
|
||||
acct2, err := store.LoadInsertAccount(context.Background(), acct)
|
||||
ok, err := store.LoadInsertAccount(context.Background(), acct)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(acct2)
|
||||
t.Log(acct == acct2)
|
||||
t.Log(ok)
|
||||
}
|
||||
|
||||
func TestUpdateAccount(t *testing.T) {
|
||||
@@ -86,12 +85,11 @@ func TestUpdateAccount(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadInsertBlogger(t *testing.T) {
|
||||
blogger2, err := store.LoadInsertBlogger(context.Background(), blogger)
|
||||
ok, err := store.LoadInsertBlogger(context.Background(), blogger)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(blogger2)
|
||||
t.Log(blogger == blogger2)
|
||||
t.Log(ok)
|
||||
}
|
||||
|
||||
func TestUpdateBlogger(t *testing.T) {
|
||||
@@ -104,21 +102,21 @@ func TestUpdateBlogger(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInsertSeries(t *testing.T) {
|
||||
err := store.InsertSeries(context.Background(), series)
|
||||
err := store.InsertSerie(context.Background(), series)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveSeries(t *testing.T) {
|
||||
err := store.RemoveSeries(context.Background(), 1)
|
||||
err := store.RemoveSerie(context.Background(), 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateSeries(t *testing.T) {
|
||||
err := store.UpdateSeries(context.Background(), 2, map[string]interface{}{
|
||||
err := store.UpdateSerie(context.Background(), 2, map[string]interface{}{
|
||||
"desc": "update desc",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -127,7 +125,7 @@ func TestUpdateSeries(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadAllSeries(t *testing.T) {
|
||||
series, err := store.LoadAllSeries(context.Background())
|
||||
series, err := store.LoadAllSerie(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -136,7 +134,7 @@ func TestLoadAllSeries(t *testing.T) {
|
||||
|
||||
func TestInsertArticle(t *testing.T) {
|
||||
article.ID = 12
|
||||
err := store.InsertArticle(context.Background(), article)
|
||||
err := store.InsertArticle(context.Background(), article, 10)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -150,14 +148,14 @@ func TestRemoveArticle(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteArticle(t *testing.T) {
|
||||
err := store.DeleteArticle(context.Background(), 12)
|
||||
err := store.RemoveArticle(context.Background(), 12)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCleanArticles(t *testing.T) {
|
||||
err := store.CleanArticles(context.Background())
|
||||
err := store.CleanArticles(context.Background(), time.Now())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -173,33 +171,13 @@ func TestUpdateArticle(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecoverArticle(t *testing.T) {
|
||||
err := store.RecoverArticle(context.Background(), 12)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadAllArticle(t *testing.T) {
|
||||
articles, err := store.LoadAllArticle(context.Background())
|
||||
_, total, err := store.LoadArticleList(context.Background(), SearchArticles{
|
||||
Page: 1,
|
||||
Limit: 1000,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Logf("load all articles: %d", len(articles))
|
||||
}
|
||||
|
||||
func TestLoadTrashArticles(t *testing.T) {
|
||||
articles, err := store.LoadTrashArticles(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Logf("load trash articles: %d", len(articles))
|
||||
}
|
||||
|
||||
func TestLoadDraftArticles(t *testing.T) {
|
||||
articles, err := store.LoadDraftArticles(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Logf("load draft articles: %d", len(articles))
|
||||
t.Logf("load all articles: %d", total)
|
||||
}
|
||||
|
||||
8
pkg/cache/store/rdbms.go
vendored
8
pkg/cache/store/rdbms.go
vendored
@@ -3,6 +3,7 @@ package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/eiblog/pkg/model"
|
||||
@@ -129,7 +130,7 @@ func (db *rdbms) InsertArticle(ctx context.Context, article *model.Article, star
|
||||
if id < startID {
|
||||
id = startID
|
||||
} else {
|
||||
id += 1
|
||||
id++
|
||||
}
|
||||
article.ID = id
|
||||
}
|
||||
@@ -190,6 +191,11 @@ func (db *rdbms) LoadArticleList(ctx context.Context, search SearchArticles) (mo
|
||||
return articles, int(count), err
|
||||
}
|
||||
|
||||
// DropDatabase drop eiblog database
|
||||
func (db *rdbms) DropDatabase(ctx context.Context) error {
|
||||
return errors.New("can not drop eiblog database in rdbms")
|
||||
}
|
||||
|
||||
// register store
|
||||
func init() {
|
||||
Register("mysql", &rdbms{})
|
||||
|
||||
3
pkg/cache/store/store.go
vendored
3
pkg/cache/store/store.go
vendored
@@ -64,6 +64,9 @@ type Store interface {
|
||||
LoadArticle(ctx context.Context, id int) (*model.Article, error)
|
||||
// LoadArticleList 查找文章列表
|
||||
LoadArticleList(ctx context.Context, search SearchArticles) (model.SortedArticles, int, error)
|
||||
|
||||
// 危险操作
|
||||
DropDatabase(ctx context.Context) error
|
||||
}
|
||||
|
||||
// Driver 存储驱动
|
||||
|
||||
@@ -69,7 +69,6 @@ type Google struct {
|
||||
URL string `yaml:"url"`
|
||||
Tid string `yaml:"tid"`
|
||||
V string `yaml:"v"`
|
||||
T string `yaml:"t"`
|
||||
AdSense string `yaml:"adsense"`
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
_ "github.com/eiblog/eiblog/pkg/core/backup/docs" // docs
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
swaggerFiles "github.com/swaggo/files"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
||||
)
|
||||
|
||||
// RegisterRoutes register routes
|
||||
|
||||
@@ -8,8 +8,10 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/eiblog/pkg/cache/store"
|
||||
"github.com/eiblog/eiblog/pkg/config"
|
||||
"github.com/eiblog/eiblog/pkg/internal"
|
||||
)
|
||||
@@ -23,7 +25,19 @@ func (s Storage) BackupData(now time.Time) error {
|
||||
case "mongodb":
|
||||
return backupFromMongoDB(now)
|
||||
default:
|
||||
return errors.New("unsupported database source backup to qiniu")
|
||||
return errors.New("unsupported source backup to qiniu: " +
|
||||
config.Conf.Database.Driver)
|
||||
}
|
||||
}
|
||||
|
||||
// RestoreData implements timer.Storage
|
||||
func (s Storage) RestoreData() error {
|
||||
switch config.Conf.Database.Driver {
|
||||
case "mongodb":
|
||||
return restoreToMongoDB()
|
||||
default:
|
||||
return errors.New("unsupported source restore from qiniu: " +
|
||||
config.Conf.Database.Driver)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,9 +75,10 @@ func backupFromMongoDB(now time.Time) error {
|
||||
return err
|
||||
}
|
||||
uploadParams := internal.UploadParams{
|
||||
Name: name,
|
||||
Size: s.Size(),
|
||||
Data: f,
|
||||
Name: filepath.Join("blog", name), // blog/eiblog-xx.tar.gz
|
||||
Size: s.Size(),
|
||||
Data: f,
|
||||
NoCompletePath: true,
|
||||
|
||||
Conf: config.Conf.BackupApp.Qiniu,
|
||||
}
|
||||
@@ -73,10 +88,58 @@ func backupFromMongoDB(now time.Time) error {
|
||||
}
|
||||
// after days delete
|
||||
deleteParams := internal.DeleteParams{
|
||||
Name: name,
|
||||
Days: config.Conf.BackupApp.Validity,
|
||||
Name: name,
|
||||
Days: config.Conf.BackupApp.Validity,
|
||||
NoCompletePath: true,
|
||||
|
||||
Conf: config.Conf.BackupApp.Qiniu,
|
||||
}
|
||||
return internal.QiniuDelete(deleteParams)
|
||||
}
|
||||
|
||||
func restoreToMongoDB() error {
|
||||
// backup file
|
||||
params := internal.ContentParams{
|
||||
Prefix: "blog/",
|
||||
|
||||
Conf: config.Conf.BackupApp.Qiniu,
|
||||
}
|
||||
raw, err := internal.QiniuContent(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := os.OpenFile("/tmp/eiblog.tar.gz", os.O_WRONLY|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, _ = f.Write(raw)
|
||||
defer f.Close()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*20)
|
||||
defer cancel()
|
||||
// drop database
|
||||
store, err := store.NewStore(config.Conf.Database.Driver,
|
||||
config.Conf.Database.Source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = store.DropDatabase(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// unarchive
|
||||
arg := fmt.Sprintf("tar xzf /tmp/eiblog.tar.gz -C /tmp")
|
||||
cmd := exec.CommandContext(ctx, "sh", "-c", arg)
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// restore
|
||||
u, err := url.Parse(config.Conf.Database.Source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
arg = fmt.Sprintf("mongorestore -h %s -d eiblog /tmp/eiblog", u.Host)
|
||||
cmd = exec.CommandContext(ctx, "sh", "-c", arg)
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
// Start to backup with ticker
|
||||
func Start() error {
|
||||
func Start(restore bool) (err error) {
|
||||
var storage Storage
|
||||
// backup instance
|
||||
switch config.Conf.BackupApp.BackupTo {
|
||||
@@ -24,13 +24,18 @@ func Start() error {
|
||||
return errors.New("timer: unknown backup to driver: " +
|
||||
config.Conf.BackupApp.BackupTo)
|
||||
}
|
||||
|
||||
if restore {
|
||||
err = storage.RestoreData()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Info("timer: RestoreData success")
|
||||
}
|
||||
// parse duration
|
||||
interval, err := ParseDuration(config.Conf.BackupApp.Interval)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t := time.NewTicker(interval)
|
||||
for now := range t.C {
|
||||
err = storage.BackupData(now)
|
||||
@@ -65,4 +70,5 @@ func ParseDuration(d string) (time.Duration, error) {
|
||||
// Storage backup backend
|
||||
type Storage interface {
|
||||
BackupData(now time.Time) error
|
||||
RestoreData() error
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
htemplate "html/template"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -203,7 +204,7 @@ func handleDisqusList(c *gin.Context) {
|
||||
if artc != nil {
|
||||
dcs.Data.Thread = artc.Thread
|
||||
}
|
||||
postsList, err := internal.PostsList(slug, cursor)
|
||||
postsList, err := internal.PostsList(artc, cursor)
|
||||
if err != nil {
|
||||
logrus.Error("hadnleDisqusList.PostsList: ", err)
|
||||
dcs.ErrNo = 0
|
||||
@@ -335,27 +336,34 @@ func handleDisqusCreate(c *gin.Context) {
|
||||
}
|
||||
|
||||
// handleBeaconPage 服务端推送谷歌统计
|
||||
// https://www.thyngster.com/ga4-measurement-protocol-cheatsheet/
|
||||
func handleBeaconPage(c *gin.Context) {
|
||||
ua := c.Request.UserAgent()
|
||||
|
||||
vals := c.Request.URL.Query()
|
||||
vals.Set("v", config.Conf.EiBlogApp.Google.V)
|
||||
vals.Set("tid", config.Conf.EiBlogApp.Google.Tid)
|
||||
vals.Set("t", config.Conf.EiBlogApp.Google.T)
|
||||
cookie, _ := c.Cookie("u")
|
||||
vals.Set("cid", cookie)
|
||||
|
||||
vals.Set("dl", c.Request.Referer())
|
||||
vals.Set("uip", c.ClientIP())
|
||||
vals.Set("dl", c.Request.Referer()) // document location
|
||||
vals.Set("en", "page_view") // event name
|
||||
vals.Set("sct", "1") // Session Count
|
||||
vals.Set("seg", "1") // Session Engagment
|
||||
vals.Set("_uip", c.ClientIP()) // user ip
|
||||
vals.Set("_p", fmt.Sprint(201226219+rand.Intn(499999999))) // random page load hash
|
||||
vals.Set("_ee", "1") // external event
|
||||
go func() {
|
||||
req, err := http.NewRequest("POST", config.Conf.EiBlogApp.Google.URL,
|
||||
strings.NewReader(vals.Encode()))
|
||||
url := config.Conf.EiBlogApp.Google.URL + "?" + vals.Encode()
|
||||
req, err := http.NewRequest("POST", url, nil)
|
||||
if err != nil {
|
||||
logrus.Error("HandleBeaconPage.NewRequest: ", err)
|
||||
return
|
||||
}
|
||||
req.Header.Set("User-Agent", ua)
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
req.Header.Set("Sec-Ch-Ua", c.GetHeader("Sec-Ch-Ua"))
|
||||
req.Header.Set("Sec-Ch-Ua-Platform", c.GetHeader("Sec-Ch-Ua-Platform"))
|
||||
req.Header.Set("Sec-Ch-Ua-Mobile", c.GetHeader("Sec-Ch-Ua-Mobile"))
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
logrus.Error("HandleBeaconPage.Do: ", err)
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
_ "github.com/eiblog/eiblog/pkg/core/eiblog/docs" // docs
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
swaggerFiles "github.com/swaggo/files"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
||||
)
|
||||
|
||||
// RegisterRoutes register routes
|
||||
|
||||
@@ -17,11 +17,13 @@ import (
|
||||
// disqus api
|
||||
const (
|
||||
apiPostsCount = "https://disqus.com/api/3.0/threads/set.json"
|
||||
apiPostsList = "https://disqus.com/api/3.0/threads/listPosts.json"
|
||||
apiPostsList = "https://disqus.com/api/3.0/threads/listPostsThreaded"
|
||||
apiPostCreate = "https://disqus.com/api/3.0/posts/create.json"
|
||||
apiPostApprove = "https://disqus.com/api/3.0/posts/approve.json"
|
||||
apiThreadCreate = "https://disqus.com/api/3.0/threads/create.json"
|
||||
apiThreadDetails = "https://disqus.com/api/3.0/threads/details.json"
|
||||
|
||||
disqusAPIKey = "E8Uh5l5fHZ6gD8U3KycjAIAk46f68Zw7C6eW8WSjZvCLXebZ7p0r1yrYDrLilk2F"
|
||||
)
|
||||
|
||||
func checkDisqusConfig() error {
|
||||
@@ -123,16 +125,17 @@ type postDetail struct {
|
||||
}
|
||||
|
||||
// PostsList 评论列表
|
||||
func PostsList(slug, cursor string) (*PostsListResp, error) {
|
||||
func PostsList(article *model.Article, cursor string) (*PostsListResp, error) {
|
||||
if err := checkDisqusConfig(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
vals := url.Values{}
|
||||
vals.Set("api_key", config.Conf.EiBlogApp.Disqus.PublicKey)
|
||||
vals.Set("api_key", disqusAPIKey)
|
||||
vals.Set("forum", config.Conf.EiBlogApp.Disqus.ShortName)
|
||||
vals.Set("thread:ident", "post-"+slug)
|
||||
vals.Set("thread", article.Thread)
|
||||
vals.Set("cursor", cursor)
|
||||
vals.Set("order", "popular")
|
||||
vals.Set("limit", "50")
|
||||
|
||||
resp, err := httpGet(apiPostsList + "?" + vals.Encode())
|
||||
@@ -181,7 +184,7 @@ func PostCreate(pc *PostComment) (*PostCreateResp, error) {
|
||||
return nil, err
|
||||
}
|
||||
vals := url.Values{}
|
||||
vals.Set("api_key", "E8Uh5l5fHZ6gD8U3KycjAIAk46f68Zw7C6eW8WSjZvCLXebZ7p0r1yrYDrLilk2F")
|
||||
vals.Set("api_key", disqusAPIKey)
|
||||
vals.Set("message", pc.Message)
|
||||
vals.Set("parent", pc.Parent)
|
||||
vals.Set("thread", pc.Thread)
|
||||
|
||||
@@ -5,7 +5,9 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/eiblog/pkg/config"
|
||||
|
||||
@@ -15,9 +17,10 @@ import (
|
||||
|
||||
// UploadParams upload params
|
||||
type UploadParams struct {
|
||||
Name string
|
||||
Size int64
|
||||
Data io.Reader
|
||||
Name string
|
||||
Size int64
|
||||
Data io.Reader
|
||||
NoCompletePath bool
|
||||
|
||||
Conf config.Qiniu
|
||||
}
|
||||
@@ -28,7 +31,10 @@ func QiniuUpload(params UploadParams) (string, error) {
|
||||
params.Conf.SecretKey == "" {
|
||||
return "", errors.New("qiniu config error")
|
||||
}
|
||||
key := completeQiniuKey(params.Name)
|
||||
key := params.Name
|
||||
if !params.NoCompletePath {
|
||||
key = filepath.Base(params.Name)
|
||||
}
|
||||
|
||||
mac := qbox.NewMac(params.Conf.AccessKey,
|
||||
params.Conf.SecretKey)
|
||||
@@ -65,15 +71,19 @@ func QiniuUpload(params UploadParams) (string, error) {
|
||||
|
||||
// DeleteParams delete params
|
||||
type DeleteParams struct {
|
||||
Name string
|
||||
Days int
|
||||
Name string
|
||||
Days int
|
||||
NoCompletePath bool
|
||||
|
||||
Conf config.Qiniu
|
||||
}
|
||||
|
||||
// QiniuDelete 删除文件
|
||||
func QiniuDelete(params DeleteParams) error {
|
||||
key := completeQiniuKey(params.Name)
|
||||
key := params.Name
|
||||
if !params.NoCompletePath {
|
||||
key = completeQiniuKey(params.Name)
|
||||
}
|
||||
|
||||
mac := qbox.NewMac(params.Conf.AccessKey,
|
||||
params.Conf.SecretKey)
|
||||
@@ -95,6 +105,47 @@ func QiniuDelete(params DeleteParams) error {
|
||||
return bucketManager.Delete(params.Conf.Bucket, key)
|
||||
}
|
||||
|
||||
// ContentParams list params
|
||||
type ContentParams struct {
|
||||
Prefix string
|
||||
|
||||
Conf config.Qiniu
|
||||
}
|
||||
|
||||
// QiniuContent 获取文件列表
|
||||
func QiniuContent(params ContentParams) ([]byte, error) {
|
||||
mac := qbox.NewMac(params.Conf.AccessKey,
|
||||
params.Conf.SecretKey)
|
||||
// region
|
||||
region, err := storage.GetRegion(params.Conf.AccessKey, params.Conf.Bucket)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cfg := &storage.Config{
|
||||
UseHTTPS: true,
|
||||
Region: region,
|
||||
}
|
||||
// manager
|
||||
bucketManager := storage.NewBucketManager(mac, cfg)
|
||||
// list file
|
||||
files, _, _, _, err := bucketManager.ListFiles(params.Conf.Bucket, params.Prefix, "", "", 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(files) == 0 {
|
||||
return nil, errors.New("no file")
|
||||
}
|
||||
deadline := time.Now().Add(time.Second * 60).Unix()
|
||||
url := storage.MakePrivateURLv2(mac, "https://"+params.Conf.Domain, files[0].Key, deadline)
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
return io.ReadAll(resp.Body)
|
||||
}
|
||||
|
||||
// completeQiniuKey 修复路径
|
||||
func completeQiniuKey(name string) string {
|
||||
ext := filepath.Ext(name)
|
||||
|
||||
@@ -46,3 +46,18 @@ func TestQiniuUpload(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestQiniuContent(t *testing.T) {
|
||||
params := ContentParams{
|
||||
Conf: config.Qiniu{
|
||||
AccessKey: os.Getenv("QINIU_ACCESSKEY"),
|
||||
SecretKey: os.Getenv("QINIU_SECRETKEY"),
|
||||
Bucket: os.Getenv("QINIU_BUCKET"),
|
||||
Domain: "bu.st.deepzz.com",
|
||||
},
|
||||
}
|
||||
_, err := QiniuContent(params)
|
||||
if err != nil {
|
||||
t.Errorf("QiniuList error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
.PHONY: protoc
|
||||
|
||||
protoc:
|
||||
@${PWD}/protoc.sh
|
||||
@@ -1,226 +0,0 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.25.0
|
||||
// protoc v3.13.0
|
||||
// source: cmd-demo/demo.proto
|
||||
|
||||
package cmd_demo
|
||||
|
||||
import (
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// This is a compile-time assertion that a sufficiently up-to-date version
|
||||
// of the legacy proto package is being used.
|
||||
const _ = proto.ProtoPackageIsVersion4
|
||||
|
||||
type UserInfoReq struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserId int64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
|
||||
}
|
||||
|
||||
func (x *UserInfoReq) Reset() {
|
||||
*x = UserInfoReq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_cmd_demo_demo_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *UserInfoReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*UserInfoReq) ProtoMessage() {}
|
||||
|
||||
func (x *UserInfoReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_cmd_demo_demo_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use UserInfoReq.ProtoReflect.Descriptor instead.
|
||||
func (*UserInfoReq) Descriptor() ([]byte, []int) {
|
||||
return file_cmd_demo_demo_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *UserInfoReq) GetUserId() int64 {
|
||||
if x != nil {
|
||||
return x.UserId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type UserInfoResp struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserId int64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
|
||||
Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
|
||||
}
|
||||
|
||||
func (x *UserInfoResp) Reset() {
|
||||
*x = UserInfoResp{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_cmd_demo_demo_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *UserInfoResp) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*UserInfoResp) ProtoMessage() {}
|
||||
|
||||
func (x *UserInfoResp) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_cmd_demo_demo_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use UserInfoResp.ProtoReflect.Descriptor instead.
|
||||
func (*UserInfoResp) Descriptor() ([]byte, []int) {
|
||||
return file_cmd_demo_demo_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *UserInfoResp) GetUserId() int64 {
|
||||
if x != nil {
|
||||
return x.UserId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *UserInfoResp) GetUsername() string {
|
||||
if x != nil {
|
||||
return x.Username
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var File_cmd_demo_demo_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_cmd_demo_demo_proto_rawDesc = []byte{
|
||||
0x0a, 0x13, 0x63, 0x6d, 0x64, 0x2d, 0x64, 0x65, 0x6d, 0x6f, 0x2f, 0x64, 0x65, 0x6d, 0x6f, 0x2e,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x64, 0x65, 0x6d, 0x6f, 0x22, 0x26, 0x0a, 0x0b, 0x55,
|
||||
0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73,
|
||||
0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x75, 0x73, 0x65,
|
||||
0x72, 0x49, 0x64, 0x22, 0x43, 0x0a, 0x0c, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52,
|
||||
0x65, 0x73, 0x70, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08,
|
||||
0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
|
||||
0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x32, 0x3b, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72,
|
||||
0x12, 0x33, 0x0a, 0x08, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x11, 0x2e, 0x64,
|
||||
0x65, 0x6d, 0x6f, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x1a,
|
||||
0x12, 0x2e, 0x64, 0x65, 0x6d, 0x6f, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52,
|
||||
0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x19, 0x5a, 0x17, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63,
|
||||
0x6d, 0x64, 0x2d, 0x64, 0x65, 0x6d, 0x6f, 0x3b, 0x63, 0x6d, 0x64, 0x5f, 0x64, 0x65, 0x6d, 0x6f,
|
||||
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_cmd_demo_demo_proto_rawDescOnce sync.Once
|
||||
file_cmd_demo_demo_proto_rawDescData = file_cmd_demo_demo_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_cmd_demo_demo_proto_rawDescGZIP() []byte {
|
||||
file_cmd_demo_demo_proto_rawDescOnce.Do(func() {
|
||||
file_cmd_demo_demo_proto_rawDescData = protoimpl.X.CompressGZIP(file_cmd_demo_demo_proto_rawDescData)
|
||||
})
|
||||
return file_cmd_demo_demo_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_cmd_demo_demo_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
||||
var file_cmd_demo_demo_proto_goTypes = []interface{}{
|
||||
(*UserInfoReq)(nil), // 0: demo.UserInfoReq
|
||||
(*UserInfoResp)(nil), // 1: demo.UserInfoResp
|
||||
}
|
||||
var file_cmd_demo_demo_proto_depIdxs = []int32{
|
||||
0, // 0: demo.User.UserInfo:input_type -> demo.UserInfoReq
|
||||
1, // 1: demo.User.UserInfo:output_type -> demo.UserInfoResp
|
||||
1, // [1:2] is the sub-list for method output_type
|
||||
0, // [0:1] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_cmd_demo_demo_proto_init() }
|
||||
func file_cmd_demo_demo_proto_init() {
|
||||
if File_cmd_demo_demo_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_cmd_demo_demo_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*UserInfoReq); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_cmd_demo_demo_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*UserInfoResp); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_cmd_demo_demo_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 2,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_cmd_demo_demo_proto_goTypes,
|
||||
DependencyIndexes: file_cmd_demo_demo_proto_depIdxs,
|
||||
MessageInfos: file_cmd_demo_demo_proto_msgTypes,
|
||||
}.Build()
|
||||
File_cmd_demo_demo_proto = out.File
|
||||
file_cmd_demo_demo_proto_rawDesc = nil
|
||||
file_cmd_demo_demo_proto_goTypes = nil
|
||||
file_cmd_demo_demo_proto_depIdxs = nil
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option go_package = "proto/cmd-demo;cmd_demo";
|
||||
|
||||
package demo;
|
||||
|
||||
message UserInfoReq {
|
||||
int64 user_id = 1;
|
||||
}
|
||||
|
||||
message UserInfoResp {
|
||||
int64 user_id = 1;
|
||||
string username = 2;
|
||||
}
|
||||
|
||||
// User service
|
||||
service User {
|
||||
rpc UserInfo(UserInfoReq) returns (UserInfoResp) {}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
|
||||
package cmd_demo
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
// UserClient is the client API for User service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type UserClient interface {
|
||||
UserInfo(ctx context.Context, in *UserInfoReq, opts ...grpc.CallOption) (*UserInfoResp, error)
|
||||
}
|
||||
|
||||
type userClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewUserClient(cc grpc.ClientConnInterface) UserClient {
|
||||
return &userClient{cc}
|
||||
}
|
||||
|
||||
func (c *userClient) UserInfo(ctx context.Context, in *UserInfoReq, opts ...grpc.CallOption) (*UserInfoResp, error) {
|
||||
out := new(UserInfoResp)
|
||||
err := c.cc.Invoke(ctx, "/demo.User/UserInfo", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// UserServer is the server API for User service.
|
||||
// All implementations must embed UnimplementedUserServer
|
||||
// for forward compatibility
|
||||
type UserServer interface {
|
||||
UserInfo(context.Context, *UserInfoReq) (*UserInfoResp, error)
|
||||
mustEmbedUnimplementedUserServer()
|
||||
}
|
||||
|
||||
// UnimplementedUserServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedUserServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedUserServer) UserInfo(context.Context, *UserInfoReq) (*UserInfoResp, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method UserInfo not implemented")
|
||||
}
|
||||
func (UnimplementedUserServer) mustEmbedUnimplementedUserServer() {}
|
||||
|
||||
// UnsafeUserServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to UserServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeUserServer interface {
|
||||
mustEmbedUnimplementedUserServer()
|
||||
}
|
||||
|
||||
func RegisterUserServer(s grpc.ServiceRegistrar, srv UserServer) {
|
||||
s.RegisterService(&_User_serviceDesc, srv)
|
||||
}
|
||||
|
||||
func _User_UserInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UserInfoReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserServer).UserInfo(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/demo.User/UserInfo",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserServer).UserInfo(ctx, req.(*UserInfoReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var _User_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "demo.User",
|
||||
HandlerType: (*UserServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "UserInfo",
|
||||
Handler: _User_UserInfo_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "cmd-demo/demo.proto",
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
set -e
|
||||
|
||||
for file in */*.proto; do
|
||||
if test -f $file; then
|
||||
protoc --go_out=. --go_opt=paths=source_relative \
|
||||
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
|
||||
$file;
|
||||
fi
|
||||
done
|
||||
@@ -1,33 +1,3 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
_registry="$1"
|
||||
_tag="$2"
|
||||
_platform="linux/amd64,linux/arm64,linux/386"
|
||||
|
||||
if [ -z "$_registry" ] || [ -z "$_tag" ]; then
|
||||
echo "Please specify image repository and tag."
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
# create and use builder
|
||||
docker buildx inspect builder >/dev/null 2>&1
|
||||
if [ "$?" != "0" ]; then
|
||||
docker buildx create --use --name builder
|
||||
fi
|
||||
|
||||
# prepare dir ./bin
|
||||
mkdir -p ./bin
|
||||
# build demo app
|
||||
for file in pkg/core/*; do
|
||||
app="$(basename $file)";
|
||||
go build -tags prod -ldflags '-extldflags "-static"' -o bin/backend "./cmd/$app"
|
||||
# docker image
|
||||
docker buildx build --platform "$_platform" \
|
||||
-f "build/package/$app.Dockerfile" \
|
||||
-t "$_registry/$app:latest" \
|
||||
-t "$_registry/$app:$_tag" \
|
||||
--push .
|
||||
done
|
||||
|
||||
# clean dir ./bin
|
||||
rm -rf ./bin
|
||||
go build -tags prod -ldflags '-extldflags "-static"' -o bin/backend "./cmd/$1"
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{{define "ana_js"}}
|
||||
!function(e,n,o){var t=e.screen,a=encodeURIComponent,r=["dt="+a(n.title),"dr="+a(n.referrer),"ul="+(o.language||o.browserLanguage),"sd="+t.colorDepth+"-bit","sr="+t.width+"x"+t.height,"_="+ +new Date],i="?"+r.join("&");e.__beacon_img=new Image,e.__beacon_img.src="/beacon.html"+i}(window,document,navigator,location);
|
||||
{{end}}
|
||||
!function(e,n,o){var t=e.screen,a=encodeURIComponent,r=["dt="+a(n.title),"dr="+a(n.referrer),"ul="+(o.language||o.browserLanguage).toLowerCase(),"sd="+t.colorDepth+"-bit","sr="+t.width+"x"+t.height,"_="+ +new Date],i="?"+r.join("&");e.__beacon_img=new Image,e.__beacon_img.src="/beacon.html"+i}(window,document,navigator,location);
|
||||
{{end}}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
|
||||
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
|
||||
<ShortName>{{.BTitle}}</ShortName>
|
||||
<Description>{{.SubTitle}}</Description>
|
||||
<Url type="text/html" template="https://{{.Host}}/search.html?q={searchTerms}" />
|
||||
<InputEncoding>UTF-8</InputEncoding>
|
||||
<Url type="text/html" method="get" template="https://{{.Host}}/search.html?q={searchTerms}" />
|
||||
<moz:SearchForm>https://{{.Host}}/search.html</moz:SearchForm>
|
||||
</OpenSearchDescription>
|
||||
|
||||
Reference in New Issue
Block a user