Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release for v1.2.x #41

Merged
merged 9 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Install SQLite
run: sudo apt-get update && sudo apt-get install -y sqlite3 libsqlite3-dev
- name: Gather dependencies
run: go mod download
- name: Run coverage
Expand Down
33 changes: 14 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="left">
English&nbsp |&nbsp <a href="https://github.com/gone-io/gone/blob/main/README_CN.md">中文</a>
English&nbsp |&nbsp <a href="README_CN.md">中文</a>
</p>

[![license](https://img.shields.io/badge/license-GPL%20V3-blue)](LICENSE)
Expand All @@ -10,7 +10,7 @@
[![Release](https://img.shields.io/github/release/gone-io/gone.svg?style=flat-square)](https://github.com/gone-io/gone/releases)
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)

<img src="docs/assert/logo.png" width = "150" alt="logo" align=center />
<img src="docs/assert/logo.png" width = "100" alt="logo" align=center />


- [Gone](#gone)
Expand All @@ -30,25 +30,15 @@
# Gone
## What Is Gone?

Gone is a lightweight golang dependency injection framework; a series of Goners components are built in for rapid development of micro services.

<img src="docs/assert/plan.png" width = "400" alt="plan"/>
Gone is a lightweight dependency injection framework for Golang, designed to integrate with a variety of third-party components, enabling rapid development of cloud-native microservices.

## Features
- Define the Goner interface to abstract dependencies.
- Dependency Injection:
- Inject Goners.
- Inject function arguments.
- Modular, detachable design.
- Startup process control.
- Testing support.
- Built-in components:
- goner/config, supports dependency injection of configuration parameters.
- goner/tracer, adds TraceId to call chains, supports link tracing.
- goner/logrus, goner/zap, supports log recording.
- goner/gin, integrates with the gin framework to provide HTTP request parameter dependency injection.
- goner/viper, used to parse various configuration files.
- ...
- Dependency injection: Supports automatic injection of struct fields and function parameters.
- **[Gonectr](https://github.com/gone-io/gonectr)**: Generates projects, auxiliary code, compiles, and starts the project.
- Unit testing solution: Mock testing based on interfaces.
- Multiple pluggable components: Supports cloud-native and microservices architectures.

<img src="docs/assert/architecture.png" width = "600" alt="architecture"/>

## Quick Start
1. Install [gonectr](https://github.com/gone-io/gonectr) and [mockgen](https://github.com/uber-go/mock/tree/main)
Expand Down Expand Up @@ -241,6 +231,11 @@ In Gone, components are abstracted as Goners, whose properties can inject other
If you have a bug report or feature request, you can [open an issue](https://github.com/gone-io/gone/issues/new), and [pull requests](https://github.com/gone-io/gone/pulls) are also welcome.

## Changelog
### v1.2.1
- Introduced **gone.Provider**, a factory function for injecting external components (such as structs, struct pointers, functions, and interfaces) that are not **Goner** into Goners filed which tag by `gone`.
- Fixed an issue where `gone.NewProviderPriest` failed to create a Priest for **gone.Provider** instances that generate interface types.
- Added test cases for `goner/gorm` and completed other missing test cases; updated documentation accordingly.

### v1.2.0
- Introduced a new `gone.GonerOption`, enabling type-based injection by delegating the task of constructing injected type instances to a **Goner** that implements `Suck(conf string, v reflect.Value, field reflect.StructField) error`.
- Added a helper function for implementing **Goner Provider**: `func NewProviderPriest[T any, P any](fn func(tagConf string, param P) (T, error)) Priest`.
Expand Down
30 changes: 13 additions & 17 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[![Release](https://img.shields.io/github/release/gone-io/gone.svg?style=flat-square)](https://github.com/gone-io/gone/releases)
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)

<img src="docs/assert/logo.png" width = "150" alt="logo" />
<img src="docs/assert/logo.png" width = "100" alt="logo" />

- [Gone](#gone)
- [Gone 是什么?](#gone-是什么)
Expand All @@ -27,25 +27,16 @@

# Gone
## Gone 是什么?
Gone 是一个轻量级的golang依赖注入框架;内置了一系列Goners组件用于快速开发微服务。

<img src="docs/assert/plan.png" width = "400" alt="plan"/>
Gone 是一个轻量级的golang依赖注入框架,并且适配了一些列第三方组件用于快速开始编写一个云原生的微服务。

## 特性
- 定义Goner接口,对依赖进行抽象
- 依赖注入
- 注入Goners
- 注入函数参数
- 模块化,可拆卸设计
- 启动流程控制
- 测试支持
- 内置组件
- goner/config,支持配置参数的依赖注入
- goner/tracer,给调用链路增加TraceId,支持链路追踪
- goner/logrus、goner/zap,支持日志记录
- goner/gin,集成gin框架,提供HTTP请求参数的依赖注入
- goner/viper,用于解析多种配置文件
- ...
- 依赖注入,支持对结构体属性和函数参数自动注入
- **[Gonectr](https://github.com/gone-io/gonectr)**,生成项目、生成辅助代码、编译和启动项目
- 单元测试方案,基于接口的mock测试
- 多种组件,可插拔,支持云原生、微服务

<img src="docs/assert/architecture.png" width = "600" alt="architecture"/>

## 快速开始
1. 安装 [gonectr](https://github.com/gone-io/gonectr) 和 [mockgen](https://github.com/uber-go/mock/tree/main)
Expand Down Expand Up @@ -233,6 +224,11 @@ curl -X POST 'http://localhost:8080/hello' \
## 📚[完整文档](https://goner.fun/zh/)

## 更新记录
### v1.2.1
- 定义 **gone.Provider**,一个工厂函数用于将 不是 **Goner** 的外部组件(结构体、结构体指针、函数、接口)注入到 属性需要注入的Goner;
- 修复 `gone.NewProviderPriest` 无法为 生成接口类型的**gone.Provider**生成Priest;
- 为`goner/gorm`编写测试代码,补齐其他测试代码;文档更新。

### v1.2.0
- 提供一种新的 `gone.GonerOption`,可以将按类型注入,将构造注入类型实例的任务代理给一个实现了`Suck(conf string, v reflect.Value, field reflect.StructField) error`的**Goner**;
- 提供了一个用于实现**Goner Provider**的辅助函数:`func NewProviderPriest[T any, P any](fn func(tagConf string, param P) (T, error)) Priest` ;
Expand Down
Binary file added docs/assert/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions goner/gorm/clickhouse/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ type dial struct {

driverName string `gone:"config,gorm.clickhouse.driver-name"`
dsn string `gone:"config,gorm.clickhouse.dsn"`
disableDatetimePrecision bool `gone:"gorm.clickhouse.disable-datetime-precision,default=false"`
dontSupportRenameColumn bool `gone:"gorm.clickhouse.dont-support-rename-column,default=false"`
dontSupportColumnPrecision bool `gone:"gorm.clickhouse.dont-support-column-precision,default=false"`
dontSupportEmptyDefaultValue bool `gone:"gorm.clickhouse.dont-support-empty-default-value,default=false"`
skipInitializeWithVersion bool `gone:"gorm.clickhouse.skip-initialize-with-version,default=false"`
defaultGranularity int `gone:"gorm.clickhouse.default-granularity,default="`
defaultCompression string `gone:"gorm.clickhouse.default-compression,default="`
defaultIndexType string `gone:"gorm.clickhouse.default-indexType,default="`
defaultTableEngineOpts string `gone:"gorm.clickhouse.default-table-engine-opts,default="`
disableDatetimePrecision bool `gone:"config,gorm.clickhouse.disable-datetime-precision,default=false"`
dontSupportRenameColumn bool `gone:"config,gorm.clickhouse.dont-support-rename-column,default=false"`
dontSupportColumnPrecision bool `gone:"config,gorm.clickhouse.dont-support-column-precision,default=false"`
dontSupportEmptyDefaultValue bool `gone:"config,gorm.clickhouse.dont-support-empty-default-value,default=false"`
skipInitializeWithVersion bool `gone:"config,gorm.clickhouse.skip-initialize-with-version,default=false"`
defaultGranularity int `gone:"config,gorm.clickhouse.default-granularity,default="`
defaultCompression string `gone:"config,gorm.clickhouse.default-compression,default="`
defaultIndexType string `gone:"config,gorm.clickhouse.default-indexType,default="`
defaultTableEngineOpts string `gone:"config,gorm.clickhouse.default-table-engine-opts,default="`
}

func (d *dial) Apply(*gorm.Config) error {
Expand Down
24 changes: 24 additions & 0 deletions goner/gorm/clickhouse/conn_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package postgres

import (
"github.com/gone-io/gone"
"github.com/gone-io/gone/goner/config"
goneGorm "github.com/gone-io/gone/goner/gorm"
"github.com/stretchr/testify/assert"
"gorm.io/gorm"
"testing"
)

func TestPriest(t *testing.T) {
gone.RunTest(func(in struct {
dial gorm.Dialector `gone:"*"`
}) {
assert.NotNil(t, in.dial)
err := in.dial.(goneGorm.Applier).Apply(nil)
assert.Nil(t, err)

}, func(cemetery gone.Cemetery) error {
_ = config.Priest(cemetery)
return Priest(cemetery)
})
}
156 changes: 156 additions & 0 deletions goner/gorm/dialector_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading