Giter Site home page Giter Site logo

fradeet / server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bangumi/server

0.0 0.0 0.0 3.72 MB

hopefully the the next-generation backend server of bgm.tv

License: GNU Affero General Public License v3.0

Dockerfile 0.04% Go 98.63% HTML 0.46% Lua 0.25% JavaScript 0.63%

server's Introduction

https://bgm.tv/ 新后端服务器。

GitHub go.mod Go version Codecov

Requirements

Optional Requirements:

  • nodejs: 用于生成 openapi 文件。

Init

git clone --recursive https://github.com/bangumi/server.git bangumi-server
cd bangumi-server
task

设置

可设置的环境变量

  • MYSQL_HOST 默认 127.0.0.1
  • MYSQL_PORT 默认 3306
  • MYSQL_DB 默认 bangumi
  • MYSQL_USER 默认 user
  • MYSQL_PASS 默认 password
  • REDIS_URI 默认 redis://127.0.0.1:6379/0
  • HTTP_PORT 默认 3000

搜索功能相关的环境变量

  • MEILISEARCH_URL meilisearch 地址,默认为空。不设置的话不会初始化搜索客户端。
  • MEILISEARCH_KEY meilisearch key。
  • KAFKA_BROKER kafka broker 地址,启动 ./internal/cmd/canal/main.go 需要 kafka。

你也可以把配置放在 .env 文件中,go-task 会自动加载 .env 文件中的环境变量。

example:

MYSQL_HOST="127.0.0.1"
MYSQL_PORT="3306"
MYSQL_USER="user"
MYSQL_PASS="password"
MYSQL_DB="bangumi"
REDIS_URI="redis://:[email protected]:6379/1"
MEILISEARCH_URL="http://127.0.0.1:7700/"

或者使用 yaml 格式的配置文件:

查看 config.example.yaml 或者 internal/config/config.go

开发

bangumi 相关项目整体说明 bangumi/dev-docs

Web 框架: fiber

ORM: GORMGORM Gen

在开发时请使用 go build tag dev 构建进行构建。

启动 HTTP server

go run --tags dev main.go --config config.yaml

启动 kafka consumer

go run --tags dev ./internal/cmd/canal/main.go --config config.yaml

后端环境

redis 和 mysql 都在此 docker-compose 内 https://github.com/bangumi/dev-env

如果你不使用 docker ,请自行启动 mysql 和 redis 并导入 bangumi/dev-env 仓库内的数据。

后端构架

flowchart LR
  Users --> Cloudflare --> Old

  subgraph Old[old server]
    nginx
    nginx --> |旧主站|php[old php server];
  end


  nginx ---> |转发api.bgm.tv/v0/的请求| Nginx(nginx on new server);
  Cloudflare --> |next.bgm.tv 直接解析到新服务器|Nginx;
flowchart TD
  Nginx(nginx on new server);

  Nginx -->|static new frontend files|FS[(file system)];

  Nginx -->|HTTP API Request|B;
  B --> |HTTP Search request|meilisearch;

  C --> |增量更新数据|meilisearch;

  B --> mysql
  B --> |缓存|redis
  C --> |清除失效缓存|redis
  C --> |清除失效数据|mysql
  kafka --> C;


  subgraph B
    direction BT
    B1[chii web];
    B2[chii web];
    ...
  end

  subgraph C[canal]
    C1[kafka consumer];
  end

  meilisearch[(new search engine)];

  subgraph Components[database]
    direction BT
    redis[(redis 缓存)]
    mysql[(mysql)]
    kafka[(kafka)]
    mysql --> |binlog|kafka;
  end

贡献指南

更多的细节介绍请查看贡献指南

提交 Pull Request

如果你的 PR 是新功能,最好先发个 issue 讨论一下要不要实现,避免 PR 提交之后新功能本身被否决的问题。

如果已经存在相关的 issue,可以先在 issue 内回复一下自己的意向,或者创建一个 Draft PR 关联对应的 issue,避免撞车问题。

测试

使用 mock 进行部分测试。

task test       # Run mocked unit tests, need nothing.
task test-db    # Run mocked tests, and tests require mysql and redis. alias for `TEST_MYSQL=1 TEST_REDIS=1 task test`
task test-http  # Run mocked tests, and tests require external HTTP resources, alias for `TEST_HTTP=1 task test`
task test-all   # Run all tests.

代码风格

task lint

配置文件

非 golang 文件 (yaml, json, markdown 等) 使用 prettier 进行格式化。 如果你没有 nodejs 环境,也可以直接提交 PR。GitHub Actions 会对文件进行检查并提出修改建议。

Go Mod

你不应当导入 github.com/bangumi/server/pkg 以外的任何路径。

具体可用的包见 pkg/readme.md

License

Copyright (C) 2021-2022 bangumi server contributors.

Source is licensed under the GNU AGPLv3 license that can be found in the LICENSE.txt file.

server's People

Contributors

aspectleft avatar everettsummer avatar fdkevin0 avatar jarvie8176 avatar michaelmai2000 avatar mikelei8291 avatar mogucloud avatar rankki avatar renovate[bot] avatar sociosarbis avatar trim21 avatar twt233 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.