Giter Club home page Giter Club logo

freedom's Introduction

Freedom DDD Framework

License Go Report CardGoDoc GitHub release

Freedom 是一个基于六边形架构的框架,可以支撑充血的领域模型范式。

Overview

  • 集成 Iris
  • HTTP/H2C Server & Client
  • 集成普罗米修斯
  • AOP Worker & 无侵入 Context
  • 可扩展组件 Infrastructure
  • 依赖注入 & 依赖倒置 & 开闭原则
  • DDD & 六边形架构
  • 领域事件 & 消息队列组件
  • CQS & 聚合根
  • CRUD & PO Generate
  • 一级缓存 & 二级缓存 & 防击穿

安装

$ go install github.com/8treenet/freedom/freedom@latest
$ freedom version

脚手架创建项目

$ freedom new-project [project-name]
$ cd [project-name]
$ go mod tidy
$ go run server/main.go

脚手架生成增删查改和持久化对象

# freedom new-po -h 查看更多
$ cd [project-name]

# 数据库数据源方式
$ freedom new-po --dsn "root:123123@tcp(127.0.0.1:3306)/freedom?charset=utf8"

# JSON 数据源方式
$ freedom new-po --json ./domain/po/schema.json

Example

freedom's People

Contributors

8treenet avatar ammend avatar didiwyl avatar fuyuhin avatar hutu1st avatar miraclecoco avatar ohva avatar ylwangs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

freedom's Issues

[DOC] Contributing conventions

Contributing conventions

Code style

Comment

Limit all lines to around 80 characters.

Example:

  1. Good.

    Example:

    // Hello, Li. I've released a new version of the project, would you like to make
    // code view for it?

    It is exactly 80 characters in the first line.

  2. Good.

    Example:

     // Let's have a good dinner this Friday, Li? I heard a new restaurant is open from
     // my friend.

    It is 82 characters in the first line, but it is acceptable.

    It is NOT REQUIRED that you MUST limit each line <= 80 characters.

    For example, you've been typed 74 characters until "is", and your next word is "open". If it is required each line
    must <= 80 characters, you may not discover that it has been exceeded 80 characters before "open" has typed,
    therefore you must back to the start position of "open" and insert a newline to content the rule. So, it will lead to
    a bad experience in coding if it required each line MUST <= 80 characters.

  3. Bad.

    // I didn't know what I want to say, emmmm... Write some words here to make up. Aha, 
    // it has been finished.

    It is 84 characters in the first line (includes punctuations), but it is not acceptable.

    Why is it? After the word "make up" you've typed, you would directly know from the editor that it is 78 characters
    you've typed in this line. Whatever the next word is, you should realize you MUST insert a newline here, because of
    no words that consist of 1 character only. Even if you want to type a letter in the next position, you should also
    insert a newline for tidy. So, remember, whatever the next word is, if what you've typed is closed to 80 characters,
    insert a newline here, just for tidy.

关于跨域解决的疑问

	app := freedom.NewApplication()
	app.Iris().Use(func(ctx iris.Context) {
		ctx.Header("Access-Control-Allow-Origin", "*")
		ctx.Header("Access-Control-Allow-Credentials", "true")
		ctx.Header("Access-Control-Allow-Headers", "*")
		ctx.Header("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT, DELETE")

		if ctx.Method() == "OPTIONS" {
			ctx.StatusCode(http.StatusOK)
			return
		}
		ctx.Next()
	})
	app.Iris().AllowMethods(iris.MethodOptions)

这样做好像没有解决

关于领域划分的疑问

疑问:
1、示例中把多个领域的代码放到了一个domain下,为什么不拆分成多个domain呢?
例如 domain/user domain/order domain/goods,每个domain只暴露service给controller调用
2、放在一个domain下当拆分成微服务时候是不是很麻烦呢?
3、聚合服务该怎么分层呢?比如下单操作同时依赖用户服务、商品服务、库存服务和订单服务等,这个服务要单独拆出来吗?还是直接写在订单服务里面?这样是不是就依赖了其他服务了?还是说调用其他服务的api方式来解决呢?

望解惑,谢谢。

如何实践依赖注入?

理解了依赖倒置,但是不知道怎么进行DI。作者可以指明一下freedom中的做法吗?目前没找到框架是怎么进行依赖注入的

我自己做的项目现在通过依赖倒置完成了repo接口和repo实现,但是不知道怎么做DI,卡在这里了。希望解答下,感谢

项目里的数据库事务对象共用问题

Worker().Store().Set("freedom_local_transaction_db", t.db),把事务对象都用一个key:freedom_local_transaction_db 存的话,并发请求时,获取的都是同一个,难道不会有问题吗?还是我的理解有问题,可以解答一下吗

关于数据库事务问题

// FetchDB .
func (repo *Repository) FetchDB(db interface{}) error {
	resultDB := globalApp.Database.db

	transactionData := repo.worker.Store().Get(TransactionKey)
	if transactionData != nil {
		resultDB = transactionData
	}
	if resultDB == nil {
		return errors.New("DB not found, please install")
	}
	if !fetchValue(db, resultDB) {
		return errors.New("DB not found, please install")
	}
	// db = globalApp.Database.db.New()
	// db.SetLogger(repo.Worker.Logger())
	return nil
}

这里拿到的事务,在并发请求情况下是否也会拿取到其他请求的事务?

关于资源库的设计

资源库和领域服务一一对应,通过聚合和聚合根来整合,从使用的角度上来说,资源库对于关系型数据库的联表查询都被拆成了单个查询了,这样是不是不大适用于关系型数据库呢?还是有什么其他考量

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.