goner

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2025 License: MIT Imports: 5 Imported by: 0

README

license GoDoc Go Report Card codecov Build and Test Release

Goner

gonerGone 框架的官方组件库,提供了一系列可即插即用的组件,帮助开发者快速构建高质量的 Go 应用程序。

组件列表

Web 框架
  • gin - 基于 gin-gonic/gin 的 Web 框架封装,提供路由管理、中间件处理、HTTP 注入等功能
  • cmux - 基于 soheilhy/cmux 的多协议复用器,支持在同一端口上运行多种协议服务
数据库
  • gorm - 基于 GORM 的 ORM 组件,支持 MySQL、PostgreSQL、SQLite、SQL Server 和 ClickHouse 等多种数据库
  • xorm - 基于 XORM 的 ORM 组件,提供简单高效的数据库操作,支持多种数据库
缓存与消息
  • redis - Redis 客户端封装,提供缓存、分布式锁等功能
微服务
配置中心
  • apollo - 基于 Apollo 的配置中心组件,提供动态配置管理功能
  • nacos - 基于 Nacos 的配置中心组件,提供动态配置管理功能【开发中...】
注册中心
  • nacos - 基于 Nacos 的注册中心组件,提供服务注册、发现等功能【开发中...】
RPC
  • grpc - gRPC 客户端和服务端封装,简化微服务开发
  • urllib - HTTP 客户端封装
工具组件

安装

go get github.com/gone-io/goner

快速开始

以下是一个使用 Gone 框架和 Goner 组件库创建简单 Web 应用的示例:

  • main.go
package main

import (
	"github.com/gone-io/gone/v2"
	"github.com/gone-io/goner"
	"github.com/gone-io/goner/gin"
	goneGorm "github.com/gone-io/goner/gorm"
	"github.com/gone-io/goner/gorm/mysql"
	"gorm.io/gorm"
)

// 定义控制器
type HelloController struct {
	gone.Flag
	gin.IRouter `gone:"*"`      // 注入路由器
	uR          *UserRepository `gone:"*"`
}

// Mount 实现 gin.Controller 接口
func (h *HelloController) Mount() gin.MountError {
	h.GET("/hello", h.hello) // 注册路由
	h.GET("/user/:id", h.getUser)
	return nil
}

func (h *HelloController) hello() (string, error) {
	return "Hello, Gone!", nil
}
func (h *HelloController) getUser(in struct {
	id uint `param:"id"`
}) (*User, error) {

	user, err := h.uR.GetByID(in.id)
	if err != nil {
		return nil, err
	}
	return user, nil
}

// 定义数据模型和仓库
type User struct {
	ID   uint `gorm:"primaryKey"`
	Name string
}

type UserRepository struct {
	gone.Flag
	*gorm.DB `gone:"*"`
}

func (r *UserRepository) GetByID(id uint) (*User, error) {
	var user User
	err := r.First(&user, id).Error
	return &user, err
}

func main() {
	// 加载组件并启动应用
	gone.
		Loads(
			goner.BaseLoad,
			goneGorm.Load, // 加载 Gorm 核心组件
			mysql.Load,    // 加载 MySQL 驱动
			gin.Load,      // 加载 Gin 组件
		).
		Load(&HelloController{}). // 加载控制器
		Load(&UserRepository{}).  // 加载仓库
		Serve()
}
  • config/default.properties
gorm.mysql.dsn=root:123456@tcp(127.0.0.1:3306)/test?charset=utf8mb4&parseTime=True&loc=Local

配置说明

各组件的详细配置说明请参考各组件目录下的 README.md 文件。

贡献指南

欢迎贡献代码或提出问题!请遵循以下步骤:

  1. Fork 本仓库
  2. 创建您的特性分支 (git checkout -b feature/amazing-feature)
  3. 提交您的更改 (git commit -m 'Add some amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 打开一个 Pull Request

许可证

本项目采用 MIT 许可证 - 详见 LICENSE 文件

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseLoad

func BaseLoad(loader gone.Loader) error

func GinLoad

func GinLoad(loader gone.Loader) error

Types

This section is empty.

Directories

Path Synopsis
balancer module
consul module
deepseek module
es module
etcd module
examples
openai module
g module
gin
interfaces module
svc
internal
mcp module
mongo module
mq
kafka module
mqtt module
rabbitmq module
rocket module
openai module
otel module
log module
log/grpc module
log/http module
meter module
meter/grpc module
meter/http module
tracer module
tracer/grpc module
tracer/http module
tracer module
gid module
gls module
viper module
remote module
mysql module
postgres module
sqlite module

Jump to

Keyboard shortcuts

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