mirror of
				https://github.com/linux-do/new-api.git
				synced 2025-11-04 13:23:42 +08:00 
			
		
		
		
	Rename to One API
This commit is contained in:
		
							
								
								
									
										2
									
								
								.github/workflows/docker-image-amd64.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/docker-image-amd64.yml
									
									
									
									
										vendored
									
									
								
							@@ -42,7 +42,7 @@ jobs:
 | 
			
		||||
        uses: docker/metadata-action@v4
 | 
			
		||||
        with:
 | 
			
		||||
          images: |
 | 
			
		||||
            justsong/gin-template
 | 
			
		||||
            justsong/one-api
 | 
			
		||||
            ghcr.io/${{ github.repository }}
 | 
			
		||||
 | 
			
		||||
      - name: Build and push Docker images
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								.github/workflows/docker-image-arm64.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/docker-image-arm64.yml
									
									
									
									
										vendored
									
									
								
							@@ -48,7 +48,7 @@ jobs:
 | 
			
		||||
        uses: docker/metadata-action@v4
 | 
			
		||||
        with:
 | 
			
		||||
          images: |
 | 
			
		||||
            justsong/gin-template
 | 
			
		||||
            justsong/one-api
 | 
			
		||||
            ghcr.io/${{ github.repository }}
 | 
			
		||||
 | 
			
		||||
      - name: Build and push Docker images
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								.github/workflows/linux-release.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								.github/workflows/linux-release.yml
									
									
									
									
										vendored
									
									
								
							@@ -30,20 +30,20 @@ jobs:
 | 
			
		||||
      - name: Build Backend (amd64)
 | 
			
		||||
        run: |
 | 
			
		||||
          go mod download
 | 
			
		||||
          go build -ldflags "-s -w -X 'gin-template/common.Version=$(git describe --tags)' -extldflags '-static'" -o gin-template
 | 
			
		||||
          go build -ldflags "-s -w -X 'one-api/common.Version=$(git describe --tags)' -extldflags '-static'" -o one-api
 | 
			
		||||
 | 
			
		||||
      - name: Build Backend (arm64)
 | 
			
		||||
        run: |
 | 
			
		||||
          sudo apt-get update
 | 
			
		||||
          sudo apt-get install gcc-aarch64-linux-gnu
 | 
			
		||||
          CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X 'gin-template/common.Version=$(git describe --tags)' -extldflags '-static'" -o gin-template-arm64
 | 
			
		||||
          CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X 'one-api/common.Version=$(git describe --tags)' -extldflags '-static'" -o one-api-arm64
 | 
			
		||||
 | 
			
		||||
      - name: Release
 | 
			
		||||
        uses: softprops/action-gh-release@v1
 | 
			
		||||
        if: startsWith(github.ref, 'refs/tags/')
 | 
			
		||||
        with:
 | 
			
		||||
          files: |
 | 
			
		||||
            gin-template
 | 
			
		||||
            gin-template-arm64
 | 
			
		||||
            one-api
 | 
			
		||||
            one-api-arm64
 | 
			
		||||
        env:
 | 
			
		||||
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 | 
			
		||||
							
								
								
									
										4
									
								
								.github/workflows/macos-release.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/macos-release.yml
									
									
									
									
										vendored
									
									
								
							@@ -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 'one-api/common.Version=$(git describe --tags)'" -o one-api-macos
 | 
			
		||||
      - name: Release
 | 
			
		||||
        uses: softprops/action-gh-release@v1
 | 
			
		||||
        if: startsWith(github.ref, 'refs/tags/')
 | 
			
		||||
        with:
 | 
			
		||||
          files: gin-template-macos
 | 
			
		||||
          files: one-api-macos
 | 
			
		||||
        env:
 | 
			
		||||
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								.github/workflows/windows-release.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/windows-release.yml
									
									
									
									
										vendored
									
									
								
							@@ -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 'one-api/common.Version=$(git describe --tags)'" -o one-api.exe
 | 
			
		||||
      - name: Release
 | 
			
		||||
        uses: softprops/action-gh-release@v1
 | 
			
		||||
        if: startsWith(github.ref, 'refs/tags/')
 | 
			
		||||
        with:
 | 
			
		||||
          files: gin-template.exe
 | 
			
		||||
          files: one-api.exe
 | 
			
		||||
        env:
 | 
			
		||||
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 | 
			
		||||
@@ -16,7 +16,7 @@ WORKDIR /build
 | 
			
		||||
COPY . .
 | 
			
		||||
COPY --from=builder /build/build ./web/build
 | 
			
		||||
RUN go mod download
 | 
			
		||||
RUN go build -ldflags "-s -w -X 'gin-template/common.Version=$(cat VERSION)' -extldflags '-static'" -o gin-template
 | 
			
		||||
RUN go build -ldflags "-s -w -X 'one-api/common.Version=$(cat VERSION)' -extldflags '-static'" -o one-api
 | 
			
		||||
 | 
			
		||||
FROM alpine
 | 
			
		||||
 | 
			
		||||
@@ -25,7 +25,7 @@ RUN apk update \
 | 
			
		||||
    && apk add --no-cache ca-certificates tzdata \
 | 
			
		||||
    && update-ca-certificates 2>/dev/null || true
 | 
			
		||||
ENV PORT=3000
 | 
			
		||||
COPY --from=builder2 /build/gin-template /
 | 
			
		||||
COPY --from=builder2 /build/one-api /
 | 
			
		||||
EXPOSE 3000
 | 
			
		||||
WORKDIR /data
 | 
			
		||||
ENTRYPOINT ["/gin-template"]
 | 
			
		||||
ENTRYPOINT ["/one-api"]
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										40
									
								
								README.en.md
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								README.en.md
									
									
									
									
									
								
							@@ -3,7 +3,7 @@
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
<p align="center">
 | 
			
		||||
  <a href="https://github.com/songquanpeng/gin-template"><img src="https://raw.githubusercontent.com/songquanpeng/gin-template/main/web/public/logo.png" width="150" height="150" alt="gin-template logo"></a>
 | 
			
		||||
  <a href="https://github.com/songquanpeng/one-api"><img src="https://raw.githubusercontent.com/songquanpeng/one-api/main/web/public/logo.png" width="150" height="150" alt="one-api logo"></a>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
<div align="center">
 | 
			
		||||
@@ -15,28 +15,28 @@ _✨ Template for Gin & React projects ✨_
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<p align="center">
 | 
			
		||||
  <a href="https://raw.githubusercontent.com/songquanpeng/gin-template/main/LICENSE">
 | 
			
		||||
    <img src="https://img.shields.io/github/license/songquanpeng/gin-template?color=brightgreen" alt="license">
 | 
			
		||||
  <a href="https://raw.githubusercontent.com/songquanpeng/one-api/main/LICENSE">
 | 
			
		||||
    <img src="https://img.shields.io/github/license/songquanpeng/one-api?color=brightgreen" alt="license">
 | 
			
		||||
  </a>
 | 
			
		||||
  <a href="https://github.com/songquanpeng/gin-template/releases/latest">
 | 
			
		||||
    <img src="https://img.shields.io/github/v/release/songquanpeng/gin-template?color=brightgreen&include_prereleases" alt="release">
 | 
			
		||||
  <a href="https://github.com/songquanpeng/one-api/releases/latest">
 | 
			
		||||
    <img src="https://img.shields.io/github/v/release/songquanpeng/one-api?color=brightgreen&include_prereleases" alt="release">
 | 
			
		||||
  </a>
 | 
			
		||||
  <a href="https://github.com/songquanpeng/gin-template/releases/latest">
 | 
			
		||||
    <img src="https://img.shields.io/github/downloads/songquanpeng/gin-template/total?color=brightgreen&include_prereleases" alt="release">
 | 
			
		||||
  <a href="https://github.com/songquanpeng/one-api/releases/latest">
 | 
			
		||||
    <img src="https://img.shields.io/github/downloads/songquanpeng/one-api/total?color=brightgreen&include_prereleases" alt="release">
 | 
			
		||||
  </a>
 | 
			
		||||
  <a href="https://goreportcard.com/report/github.com/songquanpeng/go-file">
 | 
			
		||||
    <img src="https://goreportcard.com/badge/github.com/songquanpeng/gin-template" alt="GoReportCard">
 | 
			
		||||
    <img src="https://goreportcard.com/badge/github.com/songquanpeng/one-api" alt="GoReportCard">
 | 
			
		||||
  </a>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
<p align="center">
 | 
			
		||||
  <a href="https://github.com/songquanpeng/gin-template/releases">Download</a>
 | 
			
		||||
  <a href="https://github.com/songquanpeng/one-api/releases">Download</a>
 | 
			
		||||
  ·
 | 
			
		||||
  <a href="https://github.com/songquanpeng/gin-template/blob/main/README.en.md#deployment">Tutorial</a>
 | 
			
		||||
  <a href="https://github.com/songquanpeng/one-api/blob/main/README.en.md#deployment">Tutorial</a>
 | 
			
		||||
  ·
 | 
			
		||||
  <a href="https://github.com/songquanpeng/gin-template/issues">Feedback</a>
 | 
			
		||||
  <a href="https://github.com/songquanpeng/one-api/issues">Feedback</a>
 | 
			
		||||
  ·
 | 
			
		||||
  <a href="https://gin-template.vercel.app/">Demo</a>
 | 
			
		||||
  <a href="https://one-api.vercel.app/">Demo</a>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
## Features
 | 
			
		||||
@@ -54,23 +54,23 @@ _✨ Template for Gin & React projects ✨_
 | 
			
		||||
 | 
			
		||||
## Deployment
 | 
			
		||||
### Manual deployment
 | 
			
		||||
1. Download built binary from [GitHub Releases](https://github.com/songquanpeng/gin-template/releases/latest) or build from source:
 | 
			
		||||
1. Download built binary from [GitHub Releases](https://github.com/songquanpeng/one-api/releases/latest) or build from source:
 | 
			
		||||
   ```shell
 | 
			
		||||
   git clone https://github.com/songquanpeng/gin-template.git
 | 
			
		||||
   git clone https://github.com/songquanpeng/one-api.git
 | 
			
		||||
   go mod download
 | 
			
		||||
   go build -ldflags "-s -w" -o gin-template
 | 
			
		||||
   go build -ldflags "-s -w" -o one-api
 | 
			
		||||
   ````
 | 
			
		||||
2. Run it:
 | 
			
		||||
   ```shell
 | 
			
		||||
   chmod u+x gin-template
 | 
			
		||||
   ./gin-template --port 3000 --log-dir ./logs
 | 
			
		||||
   chmod u+x one-api
 | 
			
		||||
   ./one-api --port 3000 --log-dir ./logs
 | 
			
		||||
   ```
 | 
			
		||||
3. Visit [http://localhost:3000/](http://localhost:3000/) and login. The username for the initial account is `root` and the password is `123456`.
 | 
			
		||||
 | 
			
		||||
### Deploy with Docker
 | 
			
		||||
Execute: `docker run -d --restart always -p 3000:3000 -v /home/ubuntu/data/gin-template:/data -v /etc/ssl/certs:/etc/ssl/certs:ro justsong/gin-template`
 | 
			
		||||
Execute: `docker run -d --restart always -p 3000:3000 -v /home/ubuntu/data/one-api:/data -v /etc/ssl/certs:/etc/ssl/certs:ro justsong/one-api`
 | 
			
		||||
 | 
			
		||||
Data will be saved in `/home/ubuntu/data/gin-template`.
 | 
			
		||||
Data will be saved in `/home/ubuntu/data/one-api`.
 | 
			
		||||
 | 
			
		||||
## Configurations
 | 
			
		||||
The system works out of the box.
 | 
			
		||||
@@ -85,7 +85,7 @@ After the system starts, use `root` user to log in to the system and do further
 | 
			
		||||
2. `SESSION_SECRET`: when set, a fixed session key will be used so that the logged-in users' cookie remains valid across system reboots.
 | 
			
		||||
   + Example: `SESSION_SECRET=random_string`
 | 
			
		||||
3. `SQL_DSN`: when set, the target SQL database will be used instead of SQLite.
 | 
			
		||||
   + Example: `SQL_DSN=root:123456@tcp(localhost:3306)/gin-template`
 | 
			
		||||
   + Example: `SQL_DSN=root:123456@tcp(localhost:3306)/one-api`
 | 
			
		||||
 | 
			
		||||
### Command line Arguments
 | 
			
		||||
1. `--port <port_number>`: specify the port number, the default value is `3000`.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										44
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								README.md
									
									
									
									
									
								
							@@ -3,40 +3,40 @@
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
<p align="center">
 | 
			
		||||
  <a href="https://github.com/songquanpeng/gin-template"><img src="https://raw.githubusercontent.com/songquanpeng/gin-template/main/web/public/logo.png" width="150" height="150" alt="gin-template logo"></a>
 | 
			
		||||
  <a href="https://github.com/songquanpeng/one-api"><img src="https://raw.githubusercontent.com/songquanpeng/one-api/main/web/public/logo.png" width="150" height="150" alt="one-api logo"></a>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
<div align="center">
 | 
			
		||||
 | 
			
		||||
# Gin 项目模板
 | 
			
		||||
# Gin One API
 | 
			
		||||
 | 
			
		||||
_✨ 用于 Gin & React 项目的模板 ✨_
 | 
			
		||||
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<p align="center">
 | 
			
		||||
  <a href="https://raw.githubusercontent.com/songquanpeng/gin-template/main/LICENSE">
 | 
			
		||||
    <img src="https://img.shields.io/github/license/songquanpeng/gin-template?color=brightgreen" alt="license">
 | 
			
		||||
  <a href="https://raw.githubusercontent.com/songquanpeng/one-api/main/LICENSE">
 | 
			
		||||
    <img src="https://img.shields.io/github/license/songquanpeng/one-api?color=brightgreen" alt="license">
 | 
			
		||||
  </a>
 | 
			
		||||
  <a href="https://github.com/songquanpeng/gin-template/releases/latest">
 | 
			
		||||
    <img src="https://img.shields.io/github/v/release/songquanpeng/gin-template?color=brightgreen&include_prereleases" alt="release">
 | 
			
		||||
  <a href="https://github.com/songquanpeng/one-api/releases/latest">
 | 
			
		||||
    <img src="https://img.shields.io/github/v/release/songquanpeng/one-api?color=brightgreen&include_prereleases" alt="release">
 | 
			
		||||
  </a>
 | 
			
		||||
  <a href="https://github.com/songquanpeng/gin-template/releases/latest">
 | 
			
		||||
    <img src="https://img.shields.io/github/downloads/songquanpeng/gin-template/total?color=brightgreen&include_prereleases" alt="release">
 | 
			
		||||
  <a href="https://github.com/songquanpeng/one-api/releases/latest">
 | 
			
		||||
    <img src="https://img.shields.io/github/downloads/songquanpeng/one-api/total?color=brightgreen&include_prereleases" alt="release">
 | 
			
		||||
  </a>
 | 
			
		||||
  <a href="https://goreportcard.com/report/github.com/songquanpeng/gin-template">
 | 
			
		||||
    <img src="https://goreportcard.com/badge/github.com/songquanpeng/gin-template" alt="GoReportCard">
 | 
			
		||||
  <a href="https://goreportcard.com/report/github.com/songquanpeng/one-api">
 | 
			
		||||
    <img src="https://goreportcard.com/badge/github.com/songquanpeng/one-api" alt="GoReportCard">
 | 
			
		||||
  </a>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
<p align="center">
 | 
			
		||||
  <a href="https://github.com/songquanpeng/gin-template/releases">程序下载</a>
 | 
			
		||||
  <a href="https://github.com/songquanpeng/one-api/releases">程序下载</a>
 | 
			
		||||
  ·
 | 
			
		||||
  <a href="https://github.com/songquanpeng/gin-template#部署">部署教程</a>
 | 
			
		||||
  <a href="https://github.com/songquanpeng/one-api#部署">部署教程</a>
 | 
			
		||||
  ·
 | 
			
		||||
  <a href="https://github.com/songquanpeng/gin-template/issues">意见反馈</a>
 | 
			
		||||
  <a href="https://github.com/songquanpeng/one-api/issues">意见反馈</a>
 | 
			
		||||
  ·
 | 
			
		||||
  <a href="https://gin-template.vercel.app/">在线演示</a>
 | 
			
		||||
  <a href="https://one-api.vercel.app/">在线演示</a>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
## 功能
 | 
			
		||||
@@ -54,25 +54,25 @@ _✨ 用于 Gin & React 项目的模板 ✨_
 | 
			
		||||
 | 
			
		||||
## 部署
 | 
			
		||||
### 手动部署
 | 
			
		||||
1. 从 [GitHub Releases](https://github.com/songquanpeng/gin-template/releases/latest) 下载可执行文件或者从源码编译:
 | 
			
		||||
1. 从 [GitHub Releases](https://github.com/songquanpeng/one-api/releases/latest) 下载可执行文件或者从源码编译:
 | 
			
		||||
   ```shell
 | 
			
		||||
   git clone https://github.com/songquanpeng/gin-template.git
 | 
			
		||||
   git clone https://github.com/songquanpeng/one-api.git
 | 
			
		||||
   go mod download
 | 
			
		||||
   go build -ldflags "-s -w" -o gin-template
 | 
			
		||||
   go build -ldflags "-s -w" -o one-api
 | 
			
		||||
   ````
 | 
			
		||||
2. 运行:
 | 
			
		||||
   ```shell
 | 
			
		||||
   chmod u+x gin-template
 | 
			
		||||
   ./gin-template --port 3000 --log-dir ./logs
 | 
			
		||||
   chmod u+x one-api
 | 
			
		||||
   ./one-api --port 3000 --log-dir ./logs
 | 
			
		||||
   ```
 | 
			
		||||
3. 访问 [http://localhost:3000/](http://localhost:3000/) 并登录。初始账号用户名为 `root`,密码为 `123456`。
 | 
			
		||||
 | 
			
		||||
更加详细的部署教程[参见此处](https://iamazing.cn/page/how-to-deploy-a-website)。
 | 
			
		||||
 | 
			
		||||
### 基于 Docker 进行部署
 | 
			
		||||
执行:`docker run -d --restart always -p 3000:3000 -v /home/ubuntu/data/gin-template:/data -v /etc/ssl/certs:/etc/ssl/certs:ro justsong/gin-template`
 | 
			
		||||
执行:`docker run -d --restart always -p 3000:3000 -v /home/ubuntu/data/one-api:/data -v /etc/ssl/certs:/etc/ssl/certs:ro justsong/one-api`
 | 
			
		||||
 | 
			
		||||
数据将会保存在宿主机的 `/home/ubuntu/data/gin-template` 目录。
 | 
			
		||||
数据将会保存在宿主机的 `/home/ubuntu/data/one-api` 目录。
 | 
			
		||||
 | 
			
		||||
## 配置
 | 
			
		||||
系统本身开箱即用。
 | 
			
		||||
@@ -87,7 +87,7 @@ _✨ 用于 Gin & React 项目的模板 ✨_
 | 
			
		||||
2. `SESSION_SECRET`:设置之后将使用固定的会话密钥,这样系统重新启动后已登录用户的 cookie 将依旧有效。
 | 
			
		||||
   + 例子:`SESSION_SECRET=random_string`
 | 
			
		||||
3. `SQL_DSN`:设置之后将使用指定数据库而非 SQLite。
 | 
			
		||||
   + 例子:`SQL_DSN=root:123456@tcp(localhost:3306)/gin-template`
 | 
			
		||||
   + 例子:`SQL_DSN=root:123456@tcp(localhost:3306)/one-api`
 | 
			
		||||
 | 
			
		||||
### 命令行参数
 | 
			
		||||
1. `--port <port_number>`: 指定服务器监听的端口号,默认为 `3000`。
 | 
			
		||||
 
 | 
			
		||||
@@ -8,14 +8,14 @@ import (
 | 
			
		||||
 | 
			
		||||
var StartTime = time.Now().Unix() // unit: second
 | 
			
		||||
var Version = "v0.0.0"            // this hard coding will be replaced automatically when building, no need to manually change
 | 
			
		||||
var SystemName = "项目模板"
 | 
			
		||||
var SystemName = "One API"
 | 
			
		||||
var ServerAddress = "http://localhost:3000"
 | 
			
		||||
var Footer = ""
 | 
			
		||||
 | 
			
		||||
// Any options with "Secret", "Token" in its key won't be return by GetOptions
 | 
			
		||||
 | 
			
		||||
var SessionSecret = uuid.New().String()
 | 
			
		||||
var SQLitePath = "gin-template.db"
 | 
			
		||||
var SQLitePath = "one-api.db"
 | 
			
		||||
 | 
			
		||||
var OptionMap map[string]string
 | 
			
		||||
var OptionMapRWMutex sync.RWMutex
 | 
			
		||||
 
 | 
			
		||||
@@ -2,10 +2,10 @@ package controller
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"gin-template/common"
 | 
			
		||||
	"gin-template/model"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"one-api/common"
 | 
			
		||||
	"one-api/model"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
 
 | 
			
		||||
@@ -5,11 +5,11 @@ import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"gin-template/common"
 | 
			
		||||
	"gin-template/model"
 | 
			
		||||
	"github.com/gin-contrib/sessions"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"one-api/common"
 | 
			
		||||
	"one-api/model"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
@@ -3,10 +3,10 @@ package controller
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"gin-template/common"
 | 
			
		||||
	"gin-template/model"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"one-api/common"
 | 
			
		||||
	"one-api/model"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func GetStatus(c *gin.Context) {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,10 +2,10 @@ package controller
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"gin-template/common"
 | 
			
		||||
	"gin-template/model"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"one-api/common"
 | 
			
		||||
	"one-api/model"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,12 +2,12 @@ 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"
 | 
			
		||||
	"one-api/common"
 | 
			
		||||
	"one-api/model"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
@@ -4,10 +4,10 @@ import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"gin-template/common"
 | 
			
		||||
	"gin-template/model"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"one-api/common"
 | 
			
		||||
	"one-api/model"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
module gin-template
 | 
			
		||||
module one-api
 | 
			
		||||
 | 
			
		||||
// +heroku goVersion go1.18
 | 
			
		||||
go 1.18
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								main.go
									
									
									
									
									
								
							@@ -2,16 +2,16 @@ package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"embed"
 | 
			
		||||
	"gin-template/common"
 | 
			
		||||
	"gin-template/middleware"
 | 
			
		||||
	"gin-template/model"
 | 
			
		||||
	"gin-template/router"
 | 
			
		||||
	"github.com/gin-contrib/gzip"
 | 
			
		||||
	"github.com/gin-contrib/sessions"
 | 
			
		||||
	"github.com/gin-contrib/sessions/cookie"
 | 
			
		||||
	"github.com/gin-contrib/sessions/redis"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"log"
 | 
			
		||||
	"one-api/common"
 | 
			
		||||
	"one-api/middleware"
 | 
			
		||||
	"one-api/model"
 | 
			
		||||
	"one-api/router"
 | 
			
		||||
	"os"
 | 
			
		||||
	"strconv"
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
@@ -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"
 | 
			
		||||
	"one-api/common"
 | 
			
		||||
	"one-api/model"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func authHelper(c *gin.Context, minRole int) {
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,6 @@ import (
 | 
			
		||||
 | 
			
		||||
func CORS() gin.HandlerFunc {
 | 
			
		||||
	config := cors.DefaultConfig()
 | 
			
		||||
	config.AllowOrigins = []string{"https://gin-template.vercel.app", "http://localhost:3000/"}
 | 
			
		||||
	config.AllowOrigins = []string{"https://one-api.vercel.app", "http://localhost:3000/"}
 | 
			
		||||
	return cors.New(config)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,9 +3,9 @@ package middleware
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"gin-template/common"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"one-api/common"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,11 +2,11 @@ package middleware
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"gin-template/common"
 | 
			
		||||
	"github.com/gin-contrib/sessions"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"net/url"
 | 
			
		||||
	"one-api/common"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type turnstileCheckResponse struct {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,9 @@
 | 
			
		||||
package model
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"gin-template/common"
 | 
			
		||||
	_ "gorm.io/driver/sqlite"
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
	"one-api/common"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path"
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
package model
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"gin-template/common"
 | 
			
		||||
	"gorm.io/driver/mysql"
 | 
			
		||||
	"gorm.io/driver/sqlite"
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
	"one-api/common"
 | 
			
		||||
	"os"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
package model
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"gin-template/common"
 | 
			
		||||
	"one-api/common"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@ package model
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"gin-template/common"
 | 
			
		||||
	"one-api/common"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,9 @@
 | 
			
		||||
package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"gin-template/controller"
 | 
			
		||||
	"gin-template/middleware"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"one-api/controller"
 | 
			
		||||
	"one-api/middleware"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func SetApiRouter(router *gin.Engine) {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,12 +2,12 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"embed"
 | 
			
		||||
	"gin-template/common"
 | 
			
		||||
	"gin-template/controller"
 | 
			
		||||
	"gin-template/middleware"
 | 
			
		||||
	"github.com/gin-contrib/static"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"one-api/common"
 | 
			
		||||
	"one-api/controller"
 | 
			
		||||
	"one-api/middleware"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func setWebRouter(router *gin.Engine, buildFS embed.FS, indexPage []byte) {
 | 
			
		||||
 
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 4.2 KiB  | 
@@ -9,7 +9,7 @@
 | 
			
		||||
      name="description"
 | 
			
		||||
      content="Web site created using create-react-app"
 | 
			
		||||
    />
 | 
			
		||||
    <title>项目模板</title>
 | 
			
		||||
    <title>One API</title>
 | 
			
		||||
  </head>
 | 
			
		||||
  <body>
 | 
			
		||||
    <noscript>You need to enable JavaScript to run this app.</noscript>
 | 
			
		||||
 
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 7.9 KiB  | 
@@ -16,10 +16,10 @@ const Footer = () => {
 | 
			
		||||
        {Footer === '' ? (
 | 
			
		||||
          <div className="custom-footer">
 | 
			
		||||
            <a
 | 
			
		||||
              href="https://github.com/songquanpeng/gin-template"
 | 
			
		||||
              href="https://github.com/songquanpeng/one-api"
 | 
			
		||||
              target="_blank"
 | 
			
		||||
            >
 | 
			
		||||
              项目模板 {process.env.REACT_APP_VERSION}{' '}
 | 
			
		||||
              One API {process.env.REACT_APP_VERSION}{' '}
 | 
			
		||||
            </a>
 | 
			
		||||
            由{' '}
 | 
			
		||||
            <a href="https://github.com/songquanpeng" target="_blank">
 | 
			
		||||
 
 | 
			
		||||
@@ -105,7 +105,7 @@ const Header = () => {
 | 
			
		||||
                style={{ marginRight: '0.75em' }}
 | 
			
		||||
              />
 | 
			
		||||
              <div style={{ fontSize: '20px' }}>
 | 
			
		||||
                <b>项目模板</b>
 | 
			
		||||
                <b>One API</b>
 | 
			
		||||
              </div>
 | 
			
		||||
            </Menu.Item>
 | 
			
		||||
            <Menu.Menu position='right'>
 | 
			
		||||
@@ -159,7 +159,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>One API</b>
 | 
			
		||||
            </div>
 | 
			
		||||
          </Menu.Item>
 | 
			
		||||
          {renderButtons(false)}
 | 
			
		||||
 
 | 
			
		||||
@@ -90,7 +90,7 @@ const LoginForm = () => {
 | 
			
		||||
  return (
 | 
			
		||||
    <Grid textAlign="center" style={{ marginTop: '48px' }}>
 | 
			
		||||
      <Grid.Column style={{ maxWidth: 450 }}>
 | 
			
		||||
        <Header as="h2" color="teal" textAlign="center">
 | 
			
		||||
        <Header as="h2" color="" textAlign="center">
 | 
			
		||||
          <Image src="/logo.png" /> 用户登录
 | 
			
		||||
        </Header>
 | 
			
		||||
        <Form size="large">
 | 
			
		||||
@@ -114,7 +114,7 @@ const LoginForm = () => {
 | 
			
		||||
              value={password}
 | 
			
		||||
              onChange={handleChange}
 | 
			
		||||
            />
 | 
			
		||||
            <Button color="teal" fluid size="large" onClick={handleSubmit}>
 | 
			
		||||
            <Button color="" fluid size="large" onClick={handleSubmit}>
 | 
			
		||||
              登录
 | 
			
		||||
            </Button>
 | 
			
		||||
          </Segment>
 | 
			
		||||
@@ -179,7 +179,7 @@ const LoginForm = () => {
 | 
			
		||||
                  onChange={handleChange}
 | 
			
		||||
                />
 | 
			
		||||
                <Button
 | 
			
		||||
                  color="teal"
 | 
			
		||||
                  color=""
 | 
			
		||||
                  fluid
 | 
			
		||||
                  size="large"
 | 
			
		||||
                  onClick={onSubmitWeChatVerificationCode}
 | 
			
		||||
 
 | 
			
		||||
@@ -71,12 +71,12 @@ const OtherSetting = () => {
 | 
			
		||||
 | 
			
		||||
  const openGitHubRelease = () => {
 | 
			
		||||
    window.location =
 | 
			
		||||
      'https://github.com/songquanpeng/gin-template/releases/latest';
 | 
			
		||||
      'https://github.com/songquanpeng/one-api/releases/latest';
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  const checkUpdate = async () => {
 | 
			
		||||
    const res = await API.get(
 | 
			
		||||
      'https://api.github.com/repos/songquanpeng/gin-template/releases/latest'
 | 
			
		||||
      'https://api.github.com/repos/songquanpeng/one-api/releases/latest'
 | 
			
		||||
    );
 | 
			
		||||
    const { tag_name, body } = res.data;
 | 
			
		||||
    if (tag_name === process.env.REACT_APP_VERSION) {
 | 
			
		||||
 
 | 
			
		||||
@@ -43,7 +43,7 @@ const PasswordResetConfirm = () => {
 | 
			
		||||
  return (
 | 
			
		||||
    <Grid textAlign='center' style={{ marginTop: '48px' }}>
 | 
			
		||||
      <Grid.Column style={{ maxWidth: 450 }}>
 | 
			
		||||
        <Header as='h2' color='teal' textAlign='center'>
 | 
			
		||||
        <Header as='h2' color='' textAlign='center'>
 | 
			
		||||
          <Image src='/logo.png' /> 密码重置确认
 | 
			
		||||
        </Header>
 | 
			
		||||
        <Form size='large'>
 | 
			
		||||
@@ -58,7 +58,7 @@ const PasswordResetConfirm = () => {
 | 
			
		||||
              readOnly
 | 
			
		||||
            />
 | 
			
		||||
            <Button
 | 
			
		||||
              color='teal'
 | 
			
		||||
              color=''
 | 
			
		||||
              fluid
 | 
			
		||||
              size='large'
 | 
			
		||||
              onClick={handleSubmit}
 | 
			
		||||
 
 | 
			
		||||
@@ -53,7 +53,7 @@ const PasswordResetForm = () => {
 | 
			
		||||
  return (
 | 
			
		||||
    <Grid textAlign='center' style={{ marginTop: '48px' }}>
 | 
			
		||||
      <Grid.Column style={{ maxWidth: 450 }}>
 | 
			
		||||
        <Header as='h2' color='teal' textAlign='center'>
 | 
			
		||||
        <Header as='h2' color='' textAlign='center'>
 | 
			
		||||
          <Image src='/logo.png' /> 密码重置
 | 
			
		||||
        </Header>
 | 
			
		||||
        <Form size='large'>
 | 
			
		||||
@@ -78,7 +78,7 @@ const PasswordResetForm = () => {
 | 
			
		||||
              <></>
 | 
			
		||||
            )}
 | 
			
		||||
            <Button
 | 
			
		||||
              color='teal'
 | 
			
		||||
              color=''
 | 
			
		||||
              fluid
 | 
			
		||||
              size='large'
 | 
			
		||||
              onClick={handleSubmit}
 | 
			
		||||
 
 | 
			
		||||
@@ -138,7 +138,7 @@ const PersonalSetting = () => {
 | 
			
		||||
                value={inputs.wechat_verification_code}
 | 
			
		||||
                onChange={handleInputChange}
 | 
			
		||||
              />
 | 
			
		||||
              <Button color='teal' fluid size='large' onClick={bindWeChat}>
 | 
			
		||||
              <Button color='' fluid size='large' onClick={bindWeChat}>
 | 
			
		||||
                绑定
 | 
			
		||||
              </Button>
 | 
			
		||||
            </Form>
 | 
			
		||||
@@ -194,7 +194,7 @@ const PersonalSetting = () => {
 | 
			
		||||
                <></>
 | 
			
		||||
              )}
 | 
			
		||||
              <Button
 | 
			
		||||
                color='teal'
 | 
			
		||||
                color=''
 | 
			
		||||
                fluid
 | 
			
		||||
                size='large'
 | 
			
		||||
                onClick={bindEmail}
 | 
			
		||||
 
 | 
			
		||||
@@ -99,7 +99,7 @@ const RegisterForm = () => {
 | 
			
		||||
  return (
 | 
			
		||||
    <Grid textAlign='center' style={{ marginTop: '48px' }}>
 | 
			
		||||
      <Grid.Column style={{ maxWidth: 450 }}>
 | 
			
		||||
        <Header as='h2' color='teal' textAlign='center'>
 | 
			
		||||
        <Header as='h2' color='' textAlign='center'>
 | 
			
		||||
          <Image src='/logo.png' /> 新用户注册
 | 
			
		||||
        </Header>
 | 
			
		||||
        <Form size='large'>
 | 
			
		||||
@@ -169,7 +169,7 @@ const RegisterForm = () => {
 | 
			
		||||
              <></>
 | 
			
		||||
            )}
 | 
			
		||||
            <Button
 | 
			
		||||
              color='teal'
 | 
			
		||||
              color=''
 | 
			
		||||
              fluid
 | 
			
		||||
              size='large'
 | 
			
		||||
              onClick={handleSubmit}
 | 
			
		||||
 
 | 
			
		||||
@@ -31,8 +31,8 @@ const About = () => {
 | 
			
		||||
            <Header as='h3'>关于</Header>
 | 
			
		||||
            <p>可在设置页面设置关于内容,支持 HTML & Markdown</p>
 | 
			
		||||
            项目仓库地址:
 | 
			
		||||
            <a href="https://github.com/songquanpeng/gin-template">
 | 
			
		||||
              https://github.com/songquanpeng/gin-template
 | 
			
		||||
            <a href="https://github.com/songquanpeng/one-api">
 | 
			
		||||
              https://github.com/songquanpeng/one-api
 | 
			
		||||
            </a>
 | 
			
		||||
          </> : <>
 | 
			
		||||
            <div dangerouslySetInnerHTML={{ __html: about}}></div>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user