Skip to content
Open
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: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ To implement a new feature, fix a bug, or improve documentation:
2. **Clone the Fork**

```sh
git clone https://github.com/go-advanced-admin/admin.git
git clone https://github.com/ovnicraft/go-advanced-admin.git
cd admin
```

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

A Highly Customizable Advanced Admin Panel for Go.

[![Go Report Card](https://goreportcard.com/badge/github.com/go-advanced-admin/admin)](https://goreportcard.com/report/github.com/go-advanced-admin/admin)
[![Go](https://github.com/go-advanced-admin/admin/actions/workflows/tests.yml/badge.svg)](https://github.com/go-advanced-admin/admin/actions/workflows/tests.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/ovnicraft/go-advanced-admin)](https://goreportcard.com/report/github.com/ovnicraft/go-advanced-admin)
[![Go](https://github.com/ovnicraft/go-advanced-admin/actions/workflows/tests.yml/badge.svg)](https://github.com/ovnicraft/go-advanced-admin/actions/workflows/tests.yml)
[![License: Apache-2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
[![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-blue?logo=go&logoColor=white)](https://pkg.go.dev/github.com/go-advanced-admin/admin?tab=doc)
[![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-blue?logo=go&logoColor=white)](https://pkg.go.dev/github.com/ovnicraft/go-advanced-admin?tab=doc)

Go Advanced Admin is a powerful and highly customizable admin panel for Go applications. It allows developers to
quickly create admin interfaces with minimal configuration, supporting multiple web frameworks and ORMs.
Expand All @@ -25,7 +25,7 @@ control.
Add the module to your project by running:

```sh
go get github.com/go-advanced-admin/admin
go get github.com/ovnicraft/go-advanced-admin
```

## Documentation
Expand All @@ -41,7 +41,7 @@ Here's a minimal example to get you started:
package main

import (
"github.com/go-advanced-admin/admin"
"github.com/ovnicraft/go-advanced-admin"
"github.com/go-advanced-admin/web-echo"
"github.com/go-advanced-admin/orm-gorm"
"github.com/labstack/echo/v4"
Expand Down
17 changes: 16 additions & 1 deletion admin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package admin

import "github.com/go-advanced-admin/admin/internal/adminpanel"
import "github.com/ovnicraft/go-advanced-admin/internal/adminpanel"

// Version of the go-advanced-admin library
const Version = "1.0.2"

// ORMIntegrator defines the interface for ORM integrations with the admin panel.
type ORMIntegrator = adminpanel.ORMIntegrator
Expand Down Expand Up @@ -34,3 +37,15 @@ var NewPanel = adminpanel.NewAdminPanel

// TemplateRenderer defines the interface for rendering templates in the admin panel.
type TemplateRenderer = adminpanel.TemplateRenderer

// JSONHandlerFunc represents a handler function for JSON responses.
type JSONHandlerFunc = adminpanel.JSONHandlerFunc

// JSONResponse represents a standard JSON response structure.
type JSONResponse = adminpanel.JSONResponse

// NewErrorResponse creates a new error response.
var NewErrorResponse = adminpanel.NewErrorResponse

// NewSuccessResponse creates a new success response.
var NewSuccessResponse = adminpanel.NewSuccessResponse
7 changes: 4 additions & 3 deletions example/go.mod → examples/echo/go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
module github.com/go-advanced-admin/admin/example
module github.com/ovnicraft/go-advanced-admin/example

go 1.23.1

replace github.com/go-advanced-admin/admin => ./../

require (
github.com/glebarez/sqlite v1.11.0
github.com/go-advanced-admin/admin v0.0.0
github.com/ovnicraft/go-advanced-admin v1.0.2
github.com/go-advanced-admin/orm-gorm v0.0.1
github.com/go-advanced-admin/web-echo v0.0.1
github.com/labstack/echo/v4 v4.12.0
gorm.io/gorm v1.25.12
)

replace github.com/ovnicraft/go-advanced-admin => ../..

require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/glebarez/go-sqlite v1.21.2 // indirect
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion example/main.go → examples/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"fmt"
"github.com/glebarez/sqlite"
"github.com/go-advanced-admin/admin"
"github.com/ovnicraft/go-advanced-admin"
"github.com/go-advanced-admin/orm-gorm"
"github.com/go-advanced-admin/web-echo"
"github.com/labstack/echo/v4"
Expand Down
Binary file added examples/gin/gin-admin-example
Binary file not shown.
47 changes: 47 additions & 0 deletions examples/gin/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module gin-admin-example

go 1.24.4

require (
github.com/gin-gonic/gin v1.10.1
github.com/ovnicraft/go-advanced-admin v1.0.3
github.com/ovnicraft/go-advanced-admin-gin v0.0.4
github.com/go-advanced-admin/orm-gorm v0.1.1
gorm.io/driver/sqlite v1.5.4
gorm.io/gorm v1.25.5
)

require (
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/ovnicraft/go-advanced-admin => ../..
103 changes: 103 additions & 0 deletions examples/gin/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ=
github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/ovnicraft/go-advanced-admin-gin v0.0.3 h1:rmQYoJyMCUD/Z2lX5C8c3O1HfkY/pdGEnmI00jvcuhA=
github.com/ovnicraft/go-advanced-admin-gin v0.0.3/go.mod h1:KSPoFpIgbSlZIw2Vaovb1k/nPw7qrNrKE93UxV4DI3c=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/sqlite v1.5.4 h1:IqXwXi8M/ZlPzH/947tn5uik3aYQslP9BVveoax0nV0=
gorm.io/driver/sqlite v1.5.4/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4=
gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls=
gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
137 changes: 137 additions & 0 deletions examples/gin/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package main

import (
"log"
"net/http"

"github.com/gin-gonic/gin"
admingorm "github.com/go-advanced-admin/orm-gorm"
"github.com/ovnicraft/go-advanced-admin"
admingin "github.com/ovnicraft/go-advanced-admin-gin"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)

// ormAdapter adapts the orm-gorm integrator to the latest ORMIntegrator interface.
type ormAdapter struct{ *admingorm.Integrator }

// DeleteByID maps to DeleteInstance for older integrator versions.
func (a ormAdapter) DeleteByID(model interface{}, id interface{}) error {
return a.DeleteInstance(model, id)
}

// GetAll maps to FetchInstances for older integrator versions.
func (a ormAdapter) GetAll(model interface{}) (interface{}, error) {
return a.FetchInstances(model)
}

// Persona represents a user persona with basic information
type Persona struct {
ID uint `json:"id" gorm:"primaryKey;column:ID"`
Name string `json:"name" gorm:"not null;column:Name"`
Email string `json:"email" gorm:"uniqueIndex;not null;column:Email"`
Age int `json:"age" gorm:"column:Age"`
IsActive bool `json:"is_active" gorm:"default:true;column:IsActive"`
}

func main() {
// Initialize Gin router
router := gin.Default()

// Initialize database (use fresh DB for this example)
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
if err != nil {
log.Fatal("Failed to connect to database:", err)
}

// Auto-migrate the schema
err = db.AutoMigrate(&Persona{})
if err != nil {
log.Fatal("Failed to migrate database:", err)
}

// Seed some sample data
seedData(db)

// Create ORM integrator (using GORM - you'll need to implement or use an existing one)
// ormIntegrator := gorm.NewGORMIntegrator(db) // This would need to be implemented

// Create web integrator (use root group; admin uses its own prefix)
webIntegrator := admingin.NewIntegrator(router.Group(""))

// Permission function - for demo, allow all actions
permissionFunc := func(req admin.PermissionRequest, ctx interface{}) (bool, error) {
return true, nil // Allow all actions for demo purposes
}

// ORM integrator for GORM
ormIntegrator := admingorm.NewIntegrator(db)

// Create admin panel
// Wrap ORM integrator to satisfy newer interface methods if needed.
panel, err := admin.NewPanel(ormAdapter{ormIntegrator}, webIntegrator, permissionFunc, nil)
if err != nil {
log.Fatal("Failed to create admin panel:", err)
}

// Register the Persona model
app, err := panel.RegisterApp("personas", "Persona Management", nil)
if err != nil {
log.Fatal("Failed to register app:", err)
}

if _, err := app.RegisterModel(&Persona{}, nil); err != nil {
log.Fatal("Failed to register model:", err)
}

log.Println("Gin integrator initialized:", webIntegrator != nil)
log.Println("Admin panel initialized:", panel != nil)

// No example-level asset workaround needed; integrator v0.0.4 serves assets

// Temporary routes for testing
router.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "Gin Admin Panel Example",
"version": admin.Version,
})
})

router.GET("/personas", func(c *gin.Context) {
var personas []Persona
db.Find(&personas)
c.JSON(http.StatusOK, personas)
})

// Log routes for visibility
for _, r := range router.Routes() {
log.Println(r.Method, r.Path)
}

log.Println("Server starting on :8080")
log.Println("Admin panel available at: http://localhost:8080/admin")
log.Fatal(router.Run(":8080"))
}

func seedData(db *gorm.DB) {
// Check if we already have data
var count int64
db.Model(&Persona{}).Count(&count)
if count > 0 {
return
}

// Create sample personas
personas := []Persona{
{Name: "John Doe", Email: "[email protected]", Age: 30, IsActive: true},
{Name: "Jane Smith", Email: "[email protected]", Age: 25, IsActive: true},
{Name: "Bob Johnson", Email: "[email protected]", Age: 35, IsActive: false},
{Name: "Alice Brown", Email: "[email protected]", Age: 28, IsActive: true},
}

for _, persona := range personas {
db.Create(&persona)
}

log.Println("Sample data seeded successfully")
}
4 changes: 4 additions & 0 deletions examples/gin/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package main

// Additional model definitions can go here if needed
// For now, the Persona model is defined in main.go
Loading