summer

package module
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2019 License: MIT Imports: 28 Imported by: 0

README

Summer panel

Simple control panel for Golang based on Gin framework and MongoDB

How To Install

go get -u gopkg.in/night-codes/summer.v2/...

Getting Started

  1. Create new project with demo-modules:
summerGen project --name myProject --title="My project" --db "project" --port=8080 --views="templates/main" --views-dot="templates/dot" --demo
  1. Create new module:
cd myProject/
summerGen module --name tasks --title="My tasks" --menu=MainMenu --add-sort --add-search --add-pages --add-tabs
  1. Start project
go build
./myProject
Result:

summer

or with another design theme: summer2

Examples

Coming soon...

People

Author and developer is Oleksiy Chechel

License

MIT License

Copyright (C) 2016-2017 Oleksiy Chechel (alex.mirrr@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Env

func Env(envName string, defaultValue string) (value string)

Env returns environment variable value (or default value if env.variable absent)

func H3hash

func H3hash(s string) string

H3hash create sha512 hash of string

func JSONBind

func JSONBind(c *gin.Context, ret interface{}) bool

JSONBind binds data from json request and validates them

func PackagePath

func PackagePath() string

PackagePath returns file path of Summer package location

func PostBind

func PostBind(c *gin.Context, ret interface{}) bool

PostBind binds data from post request and validates them

func Wait

func Wait()

Wait locks go-routine

Types

type GroupsList

type GroupsList struct {
	sync.Mutex
	// contains filtered or unexported fields
}

GroupsList data struct

func (*GroupsList) Add

func (g *GroupsList) Add(name string, actions ...string)

Add new group

func (*GroupsList) Get

func (g *GroupsList) Get(names ...string) (actions []string)

Get actions by group names

type LangQ added in v2.2.1

type LangQ struct {
	Lang string
	Q    float64
}
type Menu struct {
	Title  string
	Order  int
	Parent *Menu
	Link   string
	// contains filtered or unexported fields
}

Menu struct

func (m *Menu) Add(title string, order ...int) *Menu

Add submenu to current menu

type Module

type Module struct {
	*Panel
	Collection *mgo.Collection
	Settings   *ModuleSettings
}

Module struct

func (*Module) Ajax

func (m *Module) Ajax(c *gin.Context)

Ajax is default module's ajax method

func (*Module) GetSettings

func (m *Module) GetSettings() *ModuleSettings

GetSettings needs for correct settings getting from module struct

func (*Module) Page

func (m *Module) Page(c *gin.Context)

Page is default module's page rendering method

func (*Module) Websockets

func (m *Module) Websockets(c *gin.Context)

Websockets is default module's websockets method

type ModuleList

type ModuleList struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ModuleList struct

func (*ModuleList) Get

func (m *ModuleList) Get(name string) (module Simple, exists bool)

Get one module by name

func (*ModuleList) GetList

func (m *ModuleList) GetList() map[string]Simple

GetList returns modules list

type ModuleSettings

type ModuleSettings struct {
	Name             string // string identifier of module (must be unique)
	Title            string // visible module name
	Menu             *Menu  // parent menu (panel.MainMenu, panel.DropMenu etc.)
	MenuOrder        int
	MenuTitle        string
	PageRouteName    string // used to build page path: /{Path}/{module.PageRouteName}
	AjaxRouteName    string // used to build ajax path: /{Path}/ajax/{module.PageRouteName}/*method
	SocketsRouteName string // used to build websocket path: /{Path}/websocket/{module.PageRouteName}/*method
	CollectionName   string // MongoDB collection name
	TemplateName     string // template in views folder

	Icon            string // module icon in title
	GroupTo         Simple // add module like tab to another module
	GroupTitle      string // tab title
	Rights          Rights // access rights required to access this page
	DisableAuth     bool   // the page can be viewed for unauthorised visitors
	OriginTemplate  bool   // do not use Footer and Header wraps in template render
	RouterGroup     *gin.RouterGroup
	AjaxRouterGroup *gin.RouterGroup
	WsRouterGroup   *gin.RouterGroup
	// contains filtered or unexported fields
}

ModuleSettings struct

type NotifyStruct

type NotifyStruct struct {
	ID      uint64 `json:"id"  bson:"_id"`
	UserID  uint64 `json:"userId"  bson:"userId"`
	Title   string `json:"title" bson:"title" binding:"required,min=3"`
	Text    string `json:"text" bson:"text"`
	Created uint   `json:"-" bson:"created"`
	Updated uint   `json:"-" bson:"updated"`
	Deleted bool   `json:"-" bson:"deleted"`
	Demo    bool
}

NotifyStruct data struct

type Panel

type Panel struct {
	Settings
	// RootMenu is zerro-level menu
	RootMenu *Menu
	// MainMenu is main admin-panel menu
	MainMenu *Menu
	// DropMenu is top user dropdown menu
	DropMenu *Menu
	// Groups
	Groups *GroupsList
	// Modules
	Modules *ModuleList
	// Users
	Users *Users

	AI ai.AI
	// contains filtered or unexported fields
}

Panel struct

func Create

func Create(s Settings) *Panel

Create new panel

func (*Panel) AddModule

func (panel *Panel) AddModule(settings *ModuleSettings, s Simple) Simple

AddModule provide adding new module to Panel

func (*Panel) AddOpenPage

func (panel *Panel) AddOpenPage(name string, title string, menu *Menu, originTemplate ...bool) Simple

AddOpenPage provide adding simple page without authorization

func (*Panel) AddPage

func (panel *Panel) AddPage(name string, title string, menu *Menu, originTemplate ...bool) Simple

AddPage provide adding simple page module to Panel

func (*Panel) Run

func (panel *Panel) Run()

Run delayed application

type Rights

type Rights struct {
	Groups  []string `form:"groups" json:"groups" bson:"groups"`
	Actions []string `form:"actions" json:"actions" bson:"actions"`
}

Rights data struct

type Settings

type Settings struct {
	Port              uint
	Title             string
	DefaultPage       string
	AuthSalt          string
	AuthPrefix        string                 // prefix for cookies names
	AuthSkipIP        bool                   // disable using IP as salt for cookie hash generation
	Path              string                 // URL path of panel - "/" by default
	Views             string                 // file path of ./templates directory
	ViewsDoT          string                 // file path of doT.js templates directory
	Files             string                 // file path of ./files directory
	DBName            string                 // MongoDB database name
	UsersCollection   string                 // collection for panel's users
	NotifyCollection  string                 // collection for panel's notifications
	AICollection      string                 // collection for AUTO_INCREMENT
	Debug             bool                   // show `gin` debugging messages
	Vars              map[string]interface{} // variables, that can be used in templates {{var "variableName"}}
	TFuncMap          template.FuncMap       // `gin` template functions
	MakeEngineFn      func(*gin.Engine)      // Engine make callback
	MakeRouterGroupFn func(*gin.RouterGroup) // RouterGroup make callback
	FirstStart        func()                 // function called after first user creation
	DisableAuth       bool                   // if TRUE - without summer auth
	DisableFirstStart bool                   // if TRUE - without first user creating (FirstStart function don't called)
	JS                []string               // external JS resources
	CSS               []string               // external CSS resources
	RouterGroup       *gin.RouterGroup
	Engine            *gin.Engine
	HashDBFn          func(login, password, authSalt string) string
	HashCookieFn      func(login, password, authSalt, ip, userAgent string) string
	DelayStart        bool
}

Settings intended for data transmission into the Create method of package

type Simple

type Simple interface {
	Page(c *gin.Context)
	Ajax(c *gin.Context)
	Websockets(c *gin.Context)
	GetSettings() *ModuleSettings
	// contains filtered or unexported methods
}

Simple module interface

type Users

type Users struct {
	sync.Mutex

	*Panel
	// contains filtered or unexported fields
}

Users struct

func UsersFarm

func UsersFarm(DBName, UsersCollection, AuthSalt string, AICollection ...string) *Users

UsersFarm makes new Users instanse

func (*Users) Add

func (u *Users) Add(user UsersStruct) error

Add new user from struct

func (*Users) AddFrom

func (u *Users) AddFrom(data interface{}) (uint64, error)

AddFrom adds new user from struct

func (*Users) CacheLength

func (u *Users) CacheLength() int

CacheLength return len of users array

func (*Users) Clear

func (u *Users) Clear(id uint64, login string)

Clear user from users cache

func (*Users) Get

func (u *Users) Get(id uint64) (user *UsersStruct, exists bool)

Get returns user struct by id

func (*Users) GetByLogin

func (u *Users) GetByLogin(login string) (user *UsersStruct, exists bool)

GetByLogin returns user struct by login

func (*Users) GetByLoginTo

func (u *Users) GetByLoginTo(login string, user interface{}) (exists bool)

GetByLoginTo returns user data by login

func (*Users) GetDummyUser

func (u *Users) GetDummyUser() *UsersStruct

GetDummyUser returns empty user

func (*Users) GetFromContextTo

func (u *Users) GetFromContextTo(c *gin.Context, user interface{}) (exists bool)

GetFromContextTo returns user from context

func (*Users) GetTo

func (u *Users) GetTo(id uint64, user interface{}) (exists bool)

GetTo returns user data by login

func (*Users) Length

func (u *Users) Length() int

Length of users array

func (*Users) LoadUser

func (u *Users) LoadUser(id uint64)

LoadUser gets changes of user from mongoDB

func (*Users) Save

func (u *Users) Save(user *UsersStruct) error

Save exists user

func (*Users) SaveFrom

func (u *Users) SaveFrom(data interface{}) error

SaveFrom saves exists user from own struct

func (*Users) Validate

func (u *Users) Validate(user *UsersStruct) error

Validate user data

type UsersStruct

type UsersStruct struct {
	ID     uint64 `form:"id" json:"id" bson:"_id"`
	Login  string `form:"login" json:"login" bson:"login" valid:"required,min(3)"`
	Name   string `form:"name" json:"name" bson:"name" valid:"max(200)"`
	Notice string `form:"notice" json:"notice" bson:"notice" valid:"max(1000)"`

	// Is Root-user? Similar as Rights.Groups = ["root"]
	Root bool `form:"-" json:"-" bson:"root"`

	// Information field, if needs auth by email set Login == Email
	Email string `form:"email" json:"email" bson:"email" valid:"email"`

	// sha512 hash of password (but from form can be received string password value)
	Password string `form:"password" json:"-" bson:"password" valid:"min(5)"`

	// from form can be received string password value)
	Password2 string `form:"password2" json:"-" bson:"password2"`

	// Default user language (Information field)
	Lang string `form:"lang" json:"lang" bson:"lang" valid:"max(3)"`

	// Times of creating or editing (or loading from mongoDB)
	Created int64 `form:"-" json:"created" bson:"created"`
	Updated int64 `form:"-" json:"updated" bson:"updated"`
	Loaded  int64 `form:"-" json:"-" bson:"-"`

	// Fields for users auth limitation
	Disabled bool `form:"-" json:"disabled" bson:"disabled"`
	Deleted  bool `form:"-" json:"deleted" bson:"deleted"`

	// User access rights (summer.Rights)
	Rights Rights `json:"rights" bson:"rights"`

	// IP control fields (coming soon)
	LastIP   uint32 `form:"-" json:"lastIP" bson:"lastIP"`
	IP       uint32 `form:"-" json:"-" bson:"ip"`
	StringIP string `form:"-" json:"ip" bson:"-"`

	// custom data map
	Settings map[string]interface{} `form:"-" json:"settings" bson:"settings"`

	// user without authentication
	Demo bool `form:"-" json:"demo" bson:"-"`
}

UsersStruct data struct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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