Skip to content

An enhanced version of the Gin framework, integrating IOC, MVC and other concepts. Only do enhancements, do not make changes, to help you better Go Web development.

License

Notifications You must be signed in to change notification settings

archine/gin-plus

Repository files navigation

     

Gin-Plus

一个基于 Gin 框架的增强库,提供更便捷的 Web 开发体验。详细文档请访问 Gin-Plus 文档

特性

  • 🚀 灵活启动 - 支持多种运行模式
  • 🧩 依赖注入 - 自动管理对象依赖关系
  • 🔧 配置管理 - 自动配置加载和注入
  • 📋 MVC模式 - 规范化的路由和控制器定义
  • 📝 统一日志 - 内置日志管理系统

安装

go get github.com/archine/gin-plus/[email protected]

快速开始

1、定义Service

package service

import (
	"github.com/archine/gin-plus/v4/component/ioc/bean"
)

type TestService struct {
	bean.Bean
	Age int `value:"${user.age:18}"`
}

func (t *TestService) GetAge() int {
	return t.Age
}

2、定义Controller

package controller

import (
	"fmt"
	"gin-plus-demo-v4/service"
	"github.com/archine/gin-plus/v4/component/ioc"
	"github.com/archine/gin-plus/v4/resp"
	"github.com/gin-gonic/gin"
)

func init() {
	ioc.RegisterBeanDef(&TestController{})
}

type TestController struct {
	testService *service.TestService `autowire:""`
}

func (t *TestController) SetRoutes(rootGroup *gin.RouterGroup) {
	rootGroup.GET("/test/hello", t.sayHello)
}

func (t *TestController) sayHello(ctx *gin.Context) {
	resp.Json(ctx, t.testService.GetAge())
}

3、启动应用

package main

import (
	_ "gin-plus-demo-v4/controller"
	ginplus "github.com/archine/gin-plus/v4"
)

func main() {
	ginplus.Default().Run(ginplus.ServerMode)
}

About

An enhanced version of the Gin framework, integrating IOC, MVC and other concepts. Only do enhancements, do not make changes, to help you better Go Web development.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages