simple_admin

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: MIT Imports: 26 Imported by: 0

README

about simple_admin

First time , very thanks for iris framework and developer to helps~

Now talk something , this library just resolve a small and simple problem :

Xorm or gorm Why not provide a simple or small struct model visible dashboard

My trust 99% golang uses people need this

Wait long time not has , start with me , but i time and ability is small and limited !

So I'm just use i familiar technology :

  • iris
  • xorm
  • casbin -> rbac
  • react -> ant.design

Hope to help everyone !

use

Install

go get https://github.com/23233/simple_admin

Examples -> https://github.com/23233/simple_admin/tree/master/_examples


Ready -> Defined you struct

type TestModelA struct {
	Id   uint64 `xorm:"autoincr pk unique" json:"id"`
	Name string `xorm:"varchar(20)"`
}

type TestModelB struct {
	Id   uint64 `xorm:"autoincr pk unique" json:"id"`
	Desc string `xorm:"varchar(60)"`
}

Ready -> Defined you xorm engine


Engine, err = xorm.NewEngine("mysql", dbUrl)

Ready -> Defined iris application

app := iris.New()

Go -> Register simple_admin

modelList := []interface{}{new(TestModelA), new(TestModelB)}

_, err := simple_admin.New(simple_admin.Config{
    Engine:    engine,
    App:       app,
    ModelList: modelList,
    Name:      "app name",
    RunSync:   true, // this is xorm sync2
    Prefix:    "/admin", // path prefix like app.Prefix("/admin")
})

Go -> Run you app open browser http://127.0.0.1:8080/admin Yes god job

app.Listen(":8080")

warning

  • first, now don't support xorm deleted tag delete use Unscoped methods!
  • the best you do not use custom usermodel , admin isolation is good!

model custom tags (sp) now support

example: sp("key:value") sp("key(value)") sp("key('value')")
  • autogen -> mark columns is code auto generate not handle
sp("autogen")
  • lineTo -> if custom action , default value use this define for select row
sp("lineTo(Id)")
  • fk -> foreign key , support one to tone and many to one , if use multiple is many to one , just only support id columns , must be have id field !!!
sp("fk('ComplexModelC')") 
sp("fk('ComplexModelC') multiple")
  • tag -> front show whats ? now support custom tag , default show text , options: img
sp:"tag(img)"

todo features

  • [] more futures support: data filter , simple custom action ...
  • [] full test
  • [] gorm support
  • [] add websocket dashboard
  • add spider visit monitor options enable!
  • custom action
  • [] fine permission manage
  • [] beat more features

Documentation

Overview

Package simple_admin generated by go-bindata.// sources: simple_admin_templates/simple_admin.template simple_admin_templates/umi.css simple_admin_templates/umi.js

Index

Constants

This section is empty.

Variables

View Source
var (
	NowSpAdmin    *SpAdmin
	SvKey         = sv.GlobalContextKey
	DefaultPrefix = "/SP_PREFIX"
)
View Source
var CustomJwt = jwt.New(jwt.Config{
	ValidationKeyGetter: func(token *jwt.Token) (interface{}, error) {
		return MySecret, nil
	},
	Expiration:    true,
	SigningMethod: jwt.SigningMethodHS256,
})

自定义JWT 使用办法 中间层 handler.CustomJwt.Serve, handler.TokenToUserUidMiddleware,user handler

View Source
var MySecret = []byte("8657684ae02840ead423e0d781a7a0c5")

Functions

func AddRouterData

func AddRouterData(ctx iris.Context)

新增数据

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetFile added in v1.3.1

func AssetFile() http.FileSystem

AssetFile return a http.FileSystem instance that data backend by asset

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func ChangeUserPassword

func ChangeUserPassword(ctx iris.Context)

变更用户密码

func ChangeUserRoles

func ChangeUserRoles(ctx iris.Context)

变更用户群组

func Configuration

func Configuration(ctx iris.Context)

获取配置信息

func EditRouterData

func EditRouterData(ctx iris.Context)

修改数据 -> 全量更新

func GenJwtToken

func GenJwtToken(userUid, userName string) string

生成token

func GetCurrentUser

func GetCurrentUser(ctx iris.Context)

获取当前用户

func GetMapValues

func GetMapValues(a map[string]string) []string

func GetRouterCustomAction added in v1.0.8

func GetRouterCustomAction(ctx iris.Context)

获取单个表的自定义操作

func GetRouterData

func GetRouterData(ctx iris.Context)

获取表数据

func GetRouterFields

func GetRouterFields(ctx iris.Context)

获取单个表的列信息

func GetRouterSingleData

func GetRouterSingleData(ctx iris.Context)

获取表单条数据

func GetRouters

func GetRouters(ctx iris.Context)

获取所有表名

func Index

func Index(ctx iris.Context)

首页

func IsNum

func IsNum(s string) bool

func Login

func Login(ctx iris.Context)

登录

func MsgLog

func MsgLog(msg string) error

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func PolicyRequireAdminMiddleware

func PolicyRequireAdminMiddleware(ctx iris.Context)

必须admin权限middleware

func PolicyValidMiddleware

func PolicyValidMiddleware(ctx iris.Context)

权限Middleware

func RandStringBytes

func RandStringBytes(n int) string

func Reg

func Reg(ctx iris.Context)

注册

func RemoveRouterData

func RemoveRouterData(ctx iris.Context)

删除数据 -> 可以批量

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func SearchRouterData added in v1.2.6

func SearchRouterData(ctx iris.Context)

搜索表数据

func SpiderVisitHistoryMiddleware added in v1.2.7

func SpiderVisitHistoryMiddleware(ctx iris.Context)

爬虫监听Middleware

func StringsContains

func StringsContains(a []string, x string) bool

func TokenToUserUidMiddleware

func TokenToUserUidMiddleware(ctx iris.Context)

登录token存储信息 记录到上下文中

Types

type Config

type Config struct {
	Name                       string            // 后台显示名称
	Engine                     *xorm.Engine      // xorm engine实例
	App                        *iris.Application // iris实例
	ModelList                  []interface{}     // 模型列表
	UserModel                  interface{}       // 用户模型
	RunSync                    bool              // 是否进行sync
	PageSize                   int               // 每页条数
	AbridgeName                string            // tag的解析名称
	Prefix                     string            // 前缀
	InitAdminUserName          string            // 初始管理员用户名 若存在则跳过
	InitAdminPassword          string            // 初始管理员密码
	UserModelSpecialUniqueName string            // 用户模型唯一名
	CustomAction               []CustomAction    // 自定义action列表
	EnableSpiderWait           bool              // 开启爬虫监听
	SpiderMatchList            []string          // 爬虫ua匹配列表
}

type ConfigResp added in v1.0.2

type ConfigResp struct {
	Name          string `json:"name"`
	Prefix        string `json:"prefix"`
	UserModelName string `json:"user_model_name"`
}

type CustomAction added in v1.0.8

type CustomAction struct {
	Name    string        `json:"name"`    // action display name
	Methods string        `json:"methods"` // request run methods
	Valid   interface{}   `json:"valid"`   // request valid struct
	Path    string        `json:"path"`    // request path
	Scope   []interface{} `json:"scope"`   // show where
	Func    func(ctx iris.Context)
}

自定义action

type CustomActionResp added in v1.0.8

type CustomActionResp struct {
	Name    string       `json:"name"`    // action display name
	Methods string       `json:"methods"` // request run methods
	Fields  []structInfo `json:"fields"`  // request valid struct
	Path    string       `json:"path"`    // request path
}

type DeleteReq added in v1.0.2

type DeleteReq struct {
	Ids string `json:"ids" form:"ids" comment:"标识符列表" validate:"required,min=1"`
}

type GetCurrentUserResp added in v1.0.2

type GetCurrentUserResp struct {
	Name   string   `json:"name"`
	Avatar string   `json:"avatar"`
	UserId string   `json:"userid"`
	Roles  []string `json:"roles"`
}

type GlobalResp added in v1.0.2

type GlobalResp struct {
	Code    uint16      `json:"code"`    // 状态码
	Message string      `json:"message"` // 消息
	Data    interface{} `json:"data"`
}

所有返回必须包裹一层resp

type PagResult

type PagResult struct {
	All      int64               `json:"all"`
	Page     int                 `json:"page"`
	PageSize int                 `json:"page_size"`
	Data     []map[string]string `json:"data"`
}

type Policy

type Policy struct {
	Path   string `json:"path"`
	Method string `json:"method"`
}

type SearchReq added in v1.2.6

type SearchReq struct {
	SearchText string `json:"search_text" form:"search_text" comment:"搜索内容" validate:"max=20" `
}

搜索

type SpAdmin

type SpAdmin struct {
	// contains filtered or unexported fields
}

func New

func New(c Config) (*SpAdmin, error)

func (*SpAdmin) Pagination

func (lib *SpAdmin) Pagination(routerName string, page int) (PagResult, error)

分页

func (*SpAdmin) Register

func (lib *SpAdmin) Register()

注册视图

func (*SpAdmin) Router

func (lib *SpAdmin) Router(router iris.Party)

在这里注册主路由

func (*SpAdmin) SingleData

func (lib *SpAdmin) SingleData(routerName string, id uint64) (map[string]interface{}, error)

单条数据获取

type SpiderHistory added in v1.2.7

type SpiderHistory struct {
	Id         uint64    `xorm:"autoincr pk unique" json:"id"`
	CreateTime time.Time `xorm:"created index" json:"create_time"`
	Ip         string    `xorm:"varchar(15)" json:"ip"`
	Ua         string    `xorm:"varchar(150)" json:"ua"`
	Page       string    `xorm:"varchar(150)" json:"page"` // 访问路径
}

模型爬虫监听模型

type TableFieldsResp added in v1.0.3

type TableFieldsResp struct {
	Fields   []structInfo `json:"fields"`
	Autoincr string       `json:"autoincr"`
	Updated  string       `json:"updated"`
	Deleted  string       `json:"deleted"`
	Version  string       `json:"version"`
}

type UserChangePasswordReq added in v1.0.2

type UserChangePasswordReq struct {
	Id       uint64 `json:"id" comment:"id" validate:"required"`
	UserName string `json:"user_name" comment:"用户名" validate:"required,max=20,min=3"`
	Password string `json:"password" comment:"密码" validate:"required,min=3,max=20"`
}

用户变更密码

type UserChangeRolesReq added in v1.0.2

type UserChangeRolesReq struct {
	Id   uint64 `json:"id" comment:"id" validate:"required"`
	Role string `json:"role" comment:"群组名" validate:"required"`
	Add  bool   `json:"add" comment:"添加"`
}

admin 变更用户群组

type UserLoginReq added in v1.0.2

type UserLoginReq struct {
	UserName string `json:"user_name" comment:"用户名" validate:"required,max=20,min=3"`
	Password string `json:"password" comment:"密码" validate:"required,min=3,max=20"`
}

用户登录

type UserLoginResp added in v1.0.2

type UserLoginResp struct {
	Token    string             `json:"token"`
	UserInfo GetCurrentUserResp `json:"user_info"`
}

type UserModel

type UserModel struct {
	Id       uint64 `xorm:"autoincr pk unique" json:"id"`
	UserName string `xorm:"varchar(60) notnull unique index" json:"username"`
	Password string `xorm:"varchar(100) notnull" json:"password"`
	Salt     string `xorm:"varchar(40) notnull" json:"salt"`
}

默认用户模型

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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