aura

module
v0.0.0-...-b41474d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2025 License: MIT

README

miniblog 项目

项目介绍

小而美的 Go 实战项目,入门但不简单。

miniblog(微博客) 是一个 Go 语言入门项目,用来完成用户注册、博客创建等业务功能。miniblog 入门但不简单:

  • 入门: 适用于刚学习完 Go 基础语法,零项目开发经验的 Go 开发者;
  • 不简单: 本项目来自于一线企业的大型线上项目,项目本身是一个企业级的项目,学习完之后,完全可以用来作为企业级项目的开发脚手架。

miniblog 实现了以下 2 类功能:

  • 用户管理: 支持用户注册、用户登录、获取用户列表、获取用户详情、更新用户信息、修改用户密码等操作;
  • 博客管理: 支持创建博客、获取博客列表、获取博客详情、更新博客内容、删除博客等操作。

功能特点

  • 软件架构:采用简洁架构设计,确保项目结构清晰、易维护;
  • 高频 Go 包:使用了 Go 项目开发中常用的包,如 gorm、casbin、govalidator、jwt-go、gin、cobra、viper、pflag、zap、pprof、grpc、protobuf、uuid、grpc-gateway 等;
  • 目录结构:遵循 project-layout 规范,采用标准化的目录结构;
  • 认证与授权:实现了基于 JWT 的认证和基于 Casbin 的授权功能;
  • 日志与错误处理:设计了独立的日志包和错误码管理机制;
  • 构建与管理:使用高质量的 Makefile 对项目进行管理;
  • 代码质量:通过 golangci-lint 工具对代码进行静态检查,确保代码质量;
  • 测试覆盖:包含单元测试、性能测试、模糊测试和示例测试等多种测试案例;
  • 丰富的 Web 功能:支持请求 ID、优雅关停、中间件、跨域处理、异常恢复等功能;
  • 多种服务器类型:实现了 gRPC 服务器、HTTP 服务器和 HTTP 反向代理服务器;
  • 多种数据交换格式:支持 JSON 和 Protobuf 数据格式的交换;
  • 开发规范:遵循多种开发规范,包括代码规范、版本规范、接口规范、日志规范、错误规范以及提交规范等;
  • API 设计:接口设计遵循 RESTful API 规范,并提供 OpenAPI 3.0 和 Swagger 2.0 格式的 API 文档;
  • 部署难度低:实战项目可以快速部署。

快速开始

要求 Go 版本 >= 1.23.4。安装命令如下:

$ git clone https://github.com/ashwinyue/aura.git # 克隆项目
$ cd miniblog
$ go work init . # 初始化 Go 工作区
$ go work use .
$ make build BINS=mb-apiserver # 编译源码
$ _output/platforms/linux/amd64/mb-apiserver
$ curl http://127.0.0.1:5555/healthz # 调用健康检查接口,测试是否安装成功(HTTPS 协议)
{"timestamp":"2024-12-26 23:50:29"}
$ go run examples/client/health/main.go # 测试健康检查接口(gRPC 协议)
$ go run examples/client/user/main.go # 测试用户相关接口(gRPC 协议)
$ go run examples/client/post/main.go # 测试博客相关接口(gRPC 协议)

mb-apiserver 支持内存数据库和 MySQL 数据库,默认使用内存数据库启动。如果你想切换为 MySQL 数据库请按以下方式准备一个 MySQL 数据库:

  • 您可以根据 安装和配置 MariaDB 数据库 文档中的指引,安装并初始化一个 miniblog 数据库;
  • 如果您有自己的数据库,请使用 configs/miniblog.sql 中的 SQL 初始化 miniblog 依赖的数据库及表,并更新 configs/mb-apiserver.yaml 文件中 mysql 配置项中的 hostusernamepassworddatabase

并修改 configs/mb-apiserver.yaml 文件中的 enable-memory-storefalse

Documentation

用户手册开发手册

Feedback

如果您有任何反馈,请通过 colin404@foxmail.com 与我联系。

License

MIT

Directories

Path Synopsis
cmd
gen-gorm-model command
mb-apiserver command
mb-apiserver/app/options
nolint: err113
nolint: err113
examples
client/health command
client/post command
client/user command
errorsx command
gin command
gin/middleware command
logpattern command
validation/gin command
internal
apiserver/biz
Package biz is the place where you can implements more complex business logic.
Package biz is the place where you can implements more complex business logic.
apiserver/store
nolint: dupl
nolint: dupl
pkg/contextx
Package contextx 提供了对上下文(context)的扩展功能,允许在 context 中存储和提取用户相关的信息,如用户ID、用户名和访问令牌。
Package contextx 提供了对上下文(context)的扩展功能,允许在 context 中存储和提取用户相关的信息,如用户ID、用户名和访问令牌。
pkg/known
Package known 定义了一些供整个项目使用的常量.
Package known 定义了一些供整个项目使用的常量.
pkg
api/apiserver/v1
Package v1 is a reverse proxy.
Package v1 is a reverse proxy.
app
cli/genericclioptions
Package genericclioptions contains flags which can be added to you command, bound, completed, and produce useful helper functions.
Package genericclioptions contains flags which can be added to you command, bound, completed, and produce useful helper functions.
db
Package db provide useful functions to create mysql instance.
Package db provide useful functions to create mysql instance.
distlock
Package distlock provides an interface for distributed locking mechanisms.
Package distlock provides an interface for distributed locking mechanisms.
id
log
Package log is a log package used by onex project.
Package log is a log package used by onex project.
options
Package options is the public flags and options used by a generic api server.
Package options is the public flags and options used by a generic api server.
ptr
rid
store/where
Package where is used to handle GORM's Where query conditions.
Package where is used to handle GORM's Where query conditions.
util/lint
Package lint tests Go code for policy and style violations, as well as detecting suspicious constructs that are typically bugs.
Package lint tests Go code for policy and style violations, as well as detecting suspicious constructs that are typically bugs.
util/lint/hash
Package hash defines an Analyzer that detects correct use of hash.Hash.
Package hash defines an Analyzer that detects correct use of hash.Hash.
util/lint/pass
Package pass useful functionality for implementing passes.
Package pass useful functionality for implementing passes.
util/version
Package version provides utilities for version number comparisons
Package version provides utilities for version number comparisons
third_party

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL