# blog-service **Repository Path**: pdudo/blog-service ## Basic Information - **Project Name**: blog-service - **Description**: 哎呦喂,为啥要有简介啊 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2023-07-14 - **Last Updated**: 2023-07-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # blog-service ### 简介 `blog-service`是一个使用`Go Gin`框架编写的极其简洁且功能完备的博客后台系统。尽管其小巧玲珑,但凭借其简洁的设计和强大的功能,它足以满足各种基本的博客需求。 该系统不仅展示了如何使用Gin构建Web应用程序,还演示了如何实现基本的路由处理、数据库操作等。正如你所看到的,它虽然不是成品,且功能还非常单一,但是后续我们将为它打造有丰富的特性,例如用户身份验证、评论管理和文章分类等。 无论你是Go语言开发者,还是Web应用程序开发者,这个博客系统都是一个非常实用且易于学习的项目实例。 ### 体验 #### 编译二进制文件 ```bash # git clone https://gitee.com/dodayum/blog-service.git # cd blog-service # go build -o blog-service ``` #### 获取帮助 使用`blog-service -h`可以获取该服务器的帮助信息,例如: ```bash # ./blog-service -h Usage of ./blog-service: -c string 读取配置文件启动 (default "conf.yaml") -h 获取帮助 -v 打印版本号 # ``` #### 获取其版本号 使用`blog-service -v`可以打印其版本号,例如: ```bash # ./blog-service -v v0.0.1 2023-7-14 # ``` ### 配置启动blog-service #### 修改配置文件 `blog-service`可以读取`yaml`或者`json`文件配置,请在启动前修改配置,该配置案例如下: ```yaml # cat conf.yaml # 数据库配置 db: # mysql 配置 mysql: # mysql连接,格式为: 用户名:密码@(主机:端口) dns: "root:root@tcp(localhost:3306)/blog?charset=utf8mb4&parseTime=True&loc=Local" maxOpenConns: 128 maxIdleConns: 64 # 预留Mongodb地址,以后比用Mongodb mongodb: dns: "mongodb://localhost" # ginServer配置 blogServer: # http监听地址 bind: "0.0.0.0:9000" # ``` 目前`blog-service`仅支持`MySQL`作为后端,请修改其为正确的配置,若没有数据库,需要提前新建数据库(数据库默认为`blog`)。 #### 启动blog-service ```bash # ./blog-service -c conf.yaml 2023/07/14 03:23:50 read conf: {{{root:root@tcp(localhost:3306)/blog?charset=utf8mb4&parseTime=True&loc=Local 128 64} {mongodb://localhost}} {0.0.0.0:9001}} 2023/07/14 03:23:50 web server version: v0.0.1 2023-7-14 2023/07/14 03:23:50 the running PID is 91159 [GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached. [GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production. - using env: export GIN_MODE=release - using code: gin.SetMode(gin.ReleaseMode) ... 2023/07/14 03:23:50 /root/go/blog-service/modules/user/User.go:17 [1.308ms] [rows:-] SELECT column_name, column_default, is_nullable = 'YES', data_type, character_maximum_length, column_type, column_key, extra, column_comment, numeric_precision, numeric_scale , datetime_precision FROM information_schema.columns WHERE table_schema = 'blog' AND table_name = 'user' ORDER BY ORDINAL_POSITION [GIN-debug] GET /blog/queryList --> gin-gorm-project/service/blog_service.(*BlogService).QueryList-fm (3 handlers) [GIN-debug] GET /blog/buildManyDemoData --> gin-gorm-project/service/blog_service.(*BlogService).BuildManyDemoData-fm (3 handlers) [GIN-debug] POST /blog/queryByPage --> gin-gorm-project/service/blog_service.(*BlogService).QueryByPage-fm (3 handlers) [GIN-debug] POST /blog/save --> gin-gorm-project/service/blog_service.(*BlogService).Save-fm (3 handlers) [GIN-debug] GET /user/queryAll --> gin-gorm-project/service/user_service.(*UserService).QueryAll-fm (3 handlers) [GIN-debug] GET /user/queryByPage --> gin-gorm-project/service/user_service.(*UserService).QueryByPage-fm (3 handlers) [GIN-debug] POST /user/save --> gin-gorm-project/service/user_service.(*UserService).Save-fm (3 handlers) [GIN-debug] GET /user/buildDemoUser --> gin-gorm-project/service/user_service.(*UserService).BuildDemoUser-fm (3 handlers) [GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value. Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details. [GIN-debug] Listening and serving HTTP on 0.0.0.0:9000 ``` 在启动的过程中,会打印配置文件内容,和`blog-service`的`pid`。 ### 测试 #### 查看进程监听的端口信息 启动后,可以使用`ss`来获取`blog-service`监听的端口信息: ```bash # ss -tulnp | grep pid=91159 tcp LISTEN 0 1024 [::]:9000 [::]:* users:(("blog-service",pid=91159,fd=7)) # ``` #### 使用curl工具进行探测接口是否正常 可以使用`curl`工具进行测试,例如: ```bash # curl -s 127.0.0.1:9000/user/queryAll | jq { "data": [] } # ``` ### 前端(还在搭建) [前端地址](https://gitee.com/dodayum/blog-view)