Skip to content

Commit

Permalink
refactor: All refactored using Go
Browse files Browse the repository at this point in the history
  • Loading branch information
nianhua99 committed Apr 27, 2024
1 parent 5224aba commit b6a20d3
Show file tree
Hide file tree
Showing 279 changed files with 23,451 additions and 276 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ storage/*
*.log
deploy/docker-compose/conf
deploy/docker-compose/data
builds

45 changes: 45 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@echo off
setlocal

:: 编译 Linux ARM32
set GOOS=linux
set GOARCH=arm
set GOARM=7
set OUTPUT_DIR=.\builds\PandoraHelper-%1-%GOOS%-%GOARCH%
mkdir %OUTPUT_DIR%
go build -ldflags="-s -w" -o %OUTPUT_DIR%\PandoraHelper .\cmd\server\main.go
upx %OUTPUT_DIR%\PandoraHelper
copy .\config.json "%OUTPUT_DIR%"\

:: 编译 Linux ARM64
set GOOS=linux
set GOARCH=arm64
set OUTPUT_DIR=.\builds\PandoraHelper-%1-%GOOS%-%GOARCH%
go build -ldflags="-s -w" -o %OUTPUT_DIR%\PandoraHelper .\cmd\server\main.go
upx %OUTPUT_DIR%\PandoraHelper
COPY .\config.json "%OUTPUT_DIR%"\

:: 编译为Linux 64位
set GOOS=linux
set GOARCH=amd64
set OUTPUT_DIR=.\builds\PandoraHelper-%1-%GOOS%-%GOARCH%
go build -ldflags="-s -w" -o %OUTPUT_DIR%\PandoraHelper .\cmd\server\main.go
upx %OUTPUT_DIR%\PandoraHelper
COPY .\config.json "%OUTPUT_DIR%"\

:: 编译 Windows 64 位
set GOOS=windows
set GOARCH=amd64
set OUTPUT_DIR=.\builds\PandoraHelper-%1-%GOOS%-%GOARCH%
go build -ldflags="-s -w" -o %OUTPUT_DIR%\PandoraHelper.exe .\cmd\server\main.go
upx %OUTPUT_DIR%\PandoraHelper.exe
COPY .\config.json "%OUTPUT_DIR%"\

:: 编译为macOS 64位
set GOOS=darwin
set GOARCH=amd64
set OUTPUT_DIR=.\builds\PandoraHelper-%1-%GOOS%-%GOARCH%
go build -ldflags="-s -w" -o %OUTPUT_DIR%\PandoraHelper .\cmd\server\main.go
COPY .\config.json "%OUTPUT_DIR%"\

echo Compilation and compression complete.
26 changes: 0 additions & 26 deletions cmd/migration/main.go

This file was deleted.

38 changes: 0 additions & 38 deletions cmd/migration/wire/wire.go

This file was deleted.

37 changes: 0 additions & 37 deletions cmd/migration/wire/wire_gen.go

This file was deleted.

8 changes: 7 additions & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"errors"
"flag"
"fmt"

Expand All @@ -27,13 +28,18 @@ import (
// @externalDocs.description OpenAPI
// @externalDocs.url https://swagger.io/resources/open-api/
func main() {
var envConf = flag.String("conf", "config/local.yml", "config path, eg: -conf ./config/local.yml")
var envConf = flag.String("conf", "./config/", "config path, eg: -conf ./config/local.yml")
flag.Parse()
conf := config.NewConfig(*envConf)

logger := log.NewLog(conf)

app, cleanup, err := wire.NewWire(conf, logger)
pwd := conf.GetString("security.admin_password")
if pwd == "" || len(pwd) < 8 {
panic(errors.New("未设置密码或密码长度小于8"))
}

defer cleanup()
if err != nil {
panic(err)
Expand Down
9 changes: 7 additions & 2 deletions cmd/server/wire/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ var serviceSet = wire.NewSet(
server.NewTask,
)

var migrateSet = wire.NewSet(
server.NewMigrate,
)

var handlerSet = wire.NewSet(
handler.NewHandler,
handler.NewUserHandler,
Expand All @@ -52,9 +56,9 @@ var serverSet = wire.NewSet(
)

// build App
func newApp(httpServer *http.Server, job *server.Job, task *server.Task) *app.App {
func newApp(httpServer *http.Server, job *server.Job, task *server.Task, migrate *server.Migrate) *app.App {
return app.NewApp(
app.WithServer(httpServer, job, task),
app.WithServer(httpServer, job, task, migrate),
app.WithName("demo-server"),
)
}
Expand All @@ -65,6 +69,7 @@ func NewWire(*viper.Viper, *log.Logger) (*app.App, func(), error) {
serviceSet,
handlerSet,
serverSet,
migrateSet,
sid.NewSid,
jwt.NewJwt,
newApp,
Expand Down
9 changes: 6 additions & 3 deletions cmd/server/wire/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"security": {
"admin_password": ""
},
"http": {
"host": "127.0.0.1",
"port": 8080
},
"database": {
"driver": "sqlite",
"dsn": "./data.db"
},
"pandora": {
"domain": {
"chat": "https://chat.oaifree.com",
"token": "https://token.oaifree.com",
"new": "https://new.oaifree.com"
}
},
"log": {
"level": "info",
"output": "console",
"log_file_name": "./logs/server.log",
"max_backups": 30,
"max_age": 7,
"max_size": 1024,
"compress": true
}
}
29 changes: 0 additions & 29 deletions config/local.yml

This file was deleted.

37 changes: 0 additions & 37 deletions config/prod.yml

This file was deleted.

5 changes: 5 additions & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.github
.husky
.vscode/
dist/
node_modules/
19 changes: 19 additions & 0 deletions frontend/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
root = true

[*]
charset=utf-8
end_of_line=lf
insert_final_newline=true
indent_style=space
indent_size=2
max_line_length = 100

[*.{yml,yaml,json}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
2 changes: 2 additions & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_GLOB_APP_TITLE = Vite React TS Template
REACT_EDITOR=webstorm
2 changes: 2 additions & 0 deletions frontend/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_APP_BASE_API=/api
VITE_APP_HOMEPAGE=/home
2 changes: 2 additions & 0 deletions frontend/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_APP_BASE_API=/api
VITE_APP_HOMEPAGE=/home
22 changes: 22 additions & 0 deletions frontend/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
*.sh
node_modules
*.lock
**/*.svg
**/*.md
**/*.svg
**/*.ejs
**/*.html
**/*.png
**/*.toml
**/*.md
.vscode
.idea
dist
/public
/docs
.husky
.local
/bin
Dockerfile
pnpm-lock.yaml
tsconfig.node.json
Loading

0 comments on commit b6a20d3

Please sign in to comment.