Git Product home page Git Product logo

easyblog's Introduction

easyblog

普通的,并不是很好用的博客项目,主要用于实践类似于clean-arch和ddd的项目结构。使用gin作为http框架实现RESTful API,使用ent作为orm框架。数据库使用mysql

如果你正在寻找一个好用的博客网站,我推荐使用Hugo

项目结构

├── api
├── cmd
├── configs
├── internal
│   ├── conf
│   ├── domain
│   ├── repo
│   ├── server
│   ├── service
│   └── usecase
├── pkg
└── test

  • apiapi的定义,gin相关的所有逻辑都在这一层实现,只做表单验证,调用internal/service中的接口实现相应逻辑
  • cmd:存放main.go
  • configs:存放配置文件
  • internal:存放应用代码
    • domain:领域模型建模,理应使用充血模型,但是博客网站实在是没什么逻辑,所以很空旷,只提供了repo接口和usecase接口
    • repo:持久化层。实现数据库与缓存的调用逻辑,实现domain层的repo接口。
    • usecase:用例层。只用来对上层提供repo层的使用用例。不应有复杂逻辑。
    • service:服务层。用于提供给网络服务调用的接口。做数据组装,调用usecase来访问repo
    • server:调用api层的注册方法,连接serviceapi层。并提供http server用于启动。
    • conf:应用内配置。可以在这里实现Check方法检测配置正确与否。
  • pkg:存放公用代码,在这里放了logconfig包,分别用于日志输出与配置文件读取。log库使用logrus实现,为了松耦合,提供接口供应用调用,但这部分我做的不够好。
  • test:存放测试相关文件,sql文件与docker-compose.yml

使用

git clone https://github.com/samb233/easyblog.git

编译,main.go文件位于cmd目录下

go build -o easyblog cmd/easyblog/main.go

运行

./easyblog

api

  • 获取文章列表

    GET http://localhost:9999/api/v1/articles?page=1

  • 获取文章

    GET http://localhost:9999/api/v1/articles/1

  • 新增文章

    POST http://localhost:9999/api/v1/articles,可用 form-datax-www-form-urlencoded ,其中titlerequired

  • 修改文章

    POST http://localhost:9999/api/v1/articles/1

  • 删除文章

    DELETE http://localhost:9999/api/v1/articles/1

easyblog's People

Contributors

samb233 avatar

Watchers

 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.