Skip to content

gone-io/goner

Repository files navigation

English  |  中文

license GoDoc Go Report Card codecov Build and Test Release

Goner

goner is the official component library for the Gone framework, providing a series of plug-and-play components to help developers quickly build high-quality Go applications.

Component List

Web Framework

  • gin - A web framework wrapper based on gin-gonic/gin, providing route management, middleware processing, HTTP injection, and other features
  • cmux - A multi-protocol multiplexer based on soheilhy/cmux, supporting multiple protocol services on the same port

Database

  • gorm - An ORM component based on GORM, supporting MySQL, PostgreSQL, SQLite, SQL Server, ClickHouse, and other databases
  • xorm - An ORM component based on XORM, providing simple and efficient database operations, supporting multiple databases

Cache and Messaging

  • redis - Redis client wrapper, providing caching, distributed locks, and other features

Microservices

Configuration Center

  • apollo - A configuration center component based on Apollo, providing dynamic configuration management
  • nacos - A configuration center component based on Nacos, providing dynamic configuration management
  • remote - A configuration component based on various remote configuration centers (such as etcd, consul, etc.), providing unified configuration management

Service Registry

  • nacos - A service registry component based on Nacos, providing service registration, discovery, and other features [In development...]

RPC

  • grpc - gRPC client and server wrapper, simplifying microservice development
  • urllib - HTTP client wrapper

AI Components

  • openai - OpenAI client wrapper, providing GPT and other AI capabilities integration
  • deepseek - Deepseek client wrapper, providing Chinese LLM integration

Utility Components

  • viper - Configuration management component, based on spf13/viper
  • zap - Logging component, based on uber-go/zap
  • tracer - Distributed tracing component
  • urllib - HTTP client wrapper
  • schedule - Scheduled task component
  • es - Elasticsearch client wrapper, providing full-text search functionality

Installation

go get github.com/gone-io/goner

Quick Start

Here's an example of creating a simple web application using the Gone framework and Goner component library:

  • 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"
)

// Define controller
type HelloController struct {
	gone.Flag
	gin.IRouter `gone:"*"`      // Inject router
	uR          *UserRepository `gone:"*"`
}

// Mount implements the gin.Controller interface
func (h *HelloController) Mount() gin.MountError {
	h.GET("/hello", h.hello) // Register route
	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
}

// Define data model and repository
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() {
	// Load components and start the application
	gone.
		Loads(
			goner.BaseLoad,
			goneGorm.Load, // Load Gorm core components
			mysql.Load,    // Load MySQL driver
			gin.Load,      // Load Gin components
		).
		Load(&HelloController{}). // Load controller
		Load(&UserRepository{}).  // Load repository
		Serve()
}
  • config/default.properties
gorm.mysql.dsn=root:123456@tcp(127.0.0.1:3306)/test?charset=utf8mb4&parseTime=True&loc=Local

Configuration Guide

For detailed configuration instructions for each component, please refer to the README.md file in each component directory.

Contribution Guidelines

Contributions of code or issues are welcome! Please follow these steps:

  1. Fork this repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details