Skip to content

Commit

Permalink
Replace gin-template to wechat-server
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Nov 5, 2022
1 parent 22d13f1 commit 23bd08b
Show file tree
Hide file tree
Showing 32 changed files with 77 additions and 79 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/linux-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ jobs:
- name: Build Backend
run: |
go mod download
go build -ldflags "-s -w -X 'gin-template/common.Version=$(git describe --tags)'" -o gin-template
go build -ldflags "-s -w -X 'wechat-server/common.Version=$(git describe --tags)'" -o wechat-server
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: gin-template
files: wechat-server
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/macos-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ jobs:
- name: Build Backend
run: |
go mod download
go build -ldflags "-X 'gin-template/common.Version=$(git describe --tags)'" -o gin-template-macos
go build -ldflags "-X 'wechat-server/common.Version=$(git describe --tags)'" -o wechat-server-macos
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: gin-template-macos
files: wechat-server-macos
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/windows-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ jobs:
- name: Build Backend
run: |
go mod download
go build -ldflags "-s -w -X 'gin-template/common.Version=$(git describe --tags)'" -o gin-template.exe
go build -ldflags "-s -w -X 'wechat-server/common.Version=$(git describe --tags)'" -o wechat-server.exe
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: gin-template.exe
files: wechat-server.exe
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ WORKDIR /build
COPY . .
COPY --from=builder /build/build ./web/build
RUN go mod download
RUN go build -ldflags "-s -w" -o gin-template
RUN go build -ldflags "-s -w" -o wechat-server

FROM scratch

ENV PORT=3000
COPY --from=builder2 /build/gin-template /
COPY --from=builder2 /build/wechat-server /
EXPOSE 3000
ENTRYPOINT ["/gin-template"]
ENTRYPOINT ["/wechat-server"]
46 changes: 22 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
# Gin Template
> Template for Gin & React projects.
# 微信公众号服务器
> 用以微信公众号的后端,提供登录验证功能
## Features
+ [x] Built-in user management.
+ [x] [GitHub OAuth login](https://github.com/settings/applications/new).
+ [x] Email verification & password reset.
+ [x] Request rate limitation.
+ [x] Use GitHub Actions to build releases & Docker images.
+ [x] Mobile friendly UI.
## 功能
+ [ ] 登录验证
+ [ ] 自定义菜单
+ [ ] 自定义回复
+ [ ] Access Token 中控服务器

## Usage
1. Download built binaries from [GitHub Releases](https://github.com/songquanpeng/gin-template/releases/latest).
2. Run it:
1. `chmod u+x gin-template`
2. `./gin-template --port 3000`
3. The username for the initial account is `root` and the password is `123456`.
## 用法
1. [GitHub Releases](https://github.com/songquanpeng/wechat-server/releases/latest) 下载可执行文件.
2. 运行:
1. `chmod u+x wechat-server`
2. `./wechat-server --port 3000`
3. 初始账户用户名为 `root`,密码为 `123456`

## Basic Configurations
The system works out of the box.
## 配置
系统本身开箱即用。

There are several environment variables used to configure the system:
1. `REDIS_CONN_STRING`: if set, will use Redis as the store of rate limitation instead of memory.
+ Example: `REDIS_CONN_STRING=redis://default:redispw@localhost:49153`
2. `SESSION_SECRET`: if set, will fix session secret.
+ Example: `SESSION_SECRET=random_string`
3. `SQL_DSN`: if set, will use target SQL database instead of SQLite.
+ Example`SQL_DSN=root:123456@tcp(localhost:3306)/gofile`
有一些环境遍历可供配置:
1. `REDIS_CONN_STRING`: 设置之后,将启用 Redis
+ 例如:`REDIS_CONN_STRING=redis://default:redispw@localhost:49153`
2. `SESSION_SECRET`:设置之后,将使用给定会话密钥。
+ 例如:`SESSION_SECRET=random_string`
3. `SQL_DSN`: 设置之后,将使用目标数据库而非 SQLite
+ 例如:`SQL_DSN=root:123456@tcp(localhost:3306)/gofile`
6 changes: 3 additions & 3 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import (

var StartTime = time.Now().Unix() // unit: second
var Version = "v0.0.0"
var SystemName = "项目模板"
var SystemName = "微信服务器"
var ServerAddress = "http://localhost:3000"
var FooterHTML = ""

var SessionSecret = uuid.New().String()
var SQLitePath = ".gin-template.db"
var SQLitePath = ".wechat-server.db"

var OptionMap map[string]string
var OptionMapRWMutex sync.RWMutex

var ItemsPerPage = 10

var PasswordLoginEnabled = true
var RegisterEnabled = true
var RegisterEnabled = false
var EmailVerificationEnabled = false
var GitHubOAuthEnabled = false

Expand Down
4 changes: 2 additions & 2 deletions controller/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package controller
import (
"encoding/json"
"fmt"
"gin-template/common"
"gin-template/model"
"github.com/gin-gonic/gin"
"net/http"
"os"
"path/filepath"
"strings"
"time"
"wechat-server/common"
"wechat-server/model"
)

type FileDeleteRequest struct {
Expand Down
4 changes: 2 additions & 2 deletions controller/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package controller

import (
"fmt"
"gin-template/common"
"gin-template/model"
"github.com/gin-gonic/gin"
"net/http"
"wechat-server/common"
"wechat-server/model"
)

func GetStatus(c *gin.Context) {
Expand Down
4 changes: 2 additions & 2 deletions controller/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"bytes"
"encoding/json"
"fmt"
"gin-template/common"
"gin-template/model"
"github.com/gin-gonic/gin"
"net/http"
"time"
"wechat-server/common"
"wechat-server/model"
)

type GitHubOAuthResponse struct {
Expand Down
4 changes: 2 additions & 2 deletions controller/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package controller

import (
"encoding/json"
"gin-template/common"
"gin-template/model"
"github.com/gin-gonic/gin"
"net/http"
"wechat-server/common"
"wechat-server/model"
)

func GetOptions(c *gin.Context) {
Expand Down
4 changes: 2 additions & 2 deletions controller/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package controller

import (
"encoding/json"
"gin-template/common"
"gin-template/model"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"net/http"
"strconv"
"strings"
"wechat-server/common"
"wechat-server/model"
)

type LoginRequest struct {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module gin-template
module wechat-server

// +heroku goVersion go1.18
go 1.18
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package main

import (
"embed"
"gin-template/common"
"gin-template/middleware"
"gin-template/model"
"gin-template/router"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-contrib/sessions/redis"
"github.com/gin-gonic/gin"
"log"
"os"
"strconv"
"wechat-server/common"
"wechat-server/middleware"
"wechat-server/model"
"wechat-server/router"
)

//go:embed web/build
Expand Down
4 changes: 2 additions & 2 deletions middleware/auth.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package middleware

import (
"gin-template/common"
"gin-template/model"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"net/http"
"wechat-server/common"
"wechat-server/model"
)

func authHelper(c *gin.Context, minRole int) {
Expand Down
2 changes: 1 addition & 1 deletion middleware/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ func CORS() gin.HandlerFunc {
config.MaxAge = 12 * time.Hour
// if you want to allow all origins, comment the following two lines
config.AllowAllOrigins = false
config.AllowedOrigins = []string{"https://gin-template.vercel.app"}
//config.AllowedOrigins = []string{"https://wechat-server.vercel.app"}
return cors.New(config)
}
2 changes: 1 addition & 1 deletion middleware/rate-limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package middleware
import (
"context"
"fmt"
"gin-template/common"
"github.com/gin-gonic/gin"
"net/http"
"time"
"wechat-server/common"
)

var timeFormat = "2006-01-02T15:04:05.000Z"
Expand Down
2 changes: 1 addition & 1 deletion model/file.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package model

import (
"gin-template/common"
_ "gorm.io/driver/sqlite"
"gorm.io/gorm"
"os"
"path"
"strings"
"wechat-server/common"
)

type File struct {
Expand Down
2 changes: 1 addition & 1 deletion model/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package model

import (
"gin-template/common"
"gorm.io/driver/mysql"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"os"
"wechat-server/common"
)

var DB *gorm.DB
Expand Down
2 changes: 1 addition & 1 deletion model/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package model

import (
"errors"
"gin-template/common"
"strconv"
"strings"
"wechat-server/common"
)

type Option struct {
Expand Down
2 changes: 1 addition & 1 deletion model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package model

import (
"errors"
"gin-template/common"
"strings"
"wechat-server/common"
)

type User struct {
Expand Down
4 changes: 2 additions & 2 deletions router/api-router.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package router

import (
"gin-template/controller"
"gin-template/middleware"
"github.com/gin-gonic/gin"
"wechat-server/controller"
"wechat-server/middleware"
)

func SetApiRouter(router *gin.Engine) {
Expand Down
4 changes: 2 additions & 2 deletions router/web-router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package router

import (
"embed"
"gin-template/common"
"gin-template/middleware"
"github.com/gin-gonic/contrib/static"
"github.com/gin-gonic/gin"
"net/http"
"wechat-server/common"
"wechat-server/middleware"
)

func setWebRouter(router *gin.Engine, buildFS embed.FS, indexPage []byte) {
Expand Down
Binary file modified web/public/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
name="description"
content="Web site created using create-react-app"
/>
<title>项目模板</title>
<title>微信服务器</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
Binary file modified web/public/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions web/src/components/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const Footer = () => {
{footerHTML === '' ? (
<div className="custom-footer">
<a
href="https://github.com/songquanpeng/gin-template"
href="https://github.com/songquanpeng/wechat-server"
target="_blank"
>
项目模板 {process.env.REACT_APP_VERSION}{' '}
微信服务器 {process.env.REACT_APP_VERSION}{' '}
</a>
{' '}
<a href="https://github.com/songquanpeng" target="_blank">
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const Header = () => {
style={{ marginRight: '0.75em' }}
/>
<div style={{ fontSize: '20px' }}>
<b>项目模板</b>
<b>微信服务器</b>
</div>
</Menu.Item>
<Menu.Menu position="right">
Expand Down Expand Up @@ -154,7 +154,7 @@ const Header = () => {
<Menu.Item as={Link} to="/" className={'hide-on-mobile'}>
<img src="/logo.png" alt="logo" style={{ marginRight: '0.75em' }} />
<div style={{ fontSize: '20px' }}>
<b>项目模板</b>
<b>微信服务器</b>
</div>
</Menu.Item>
{renderButtons(false)}
Expand Down
Loading

0 comments on commit 23bd08b

Please sign in to comment.