summer

package module
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2016 License: MIT Imports: 23 Imported by: 0

README

Summer panel

Simple control panel for Golang based on Gin framework and MongoDB

How To Install

go get gopkg.in/night-codes/summer.v1

Getting Started

package main

import (
    "gopkg.in/night-codes/summer.v1"
)

var (
    panel = summer.Create(summer.Settings{
        Port:        8080,
        AuthSalt:    "myappSalt123",
        AuthPrefix:  "myapp-",
        DefaultPage: "news",
        Path:        "/panel",
        DBName:      "mypanel",
        Views:       "views",
        Files:       "files",
    })
)

func main() {
    summer.Wait()
}

Create section in Summer

/news.go

package main

import (
    "gopkg.in/gin-gonic/gin.v1"
    "gopkg.in/night-codes/summer.v1"
)

type (
    obj map[string]interface{}

    NewsModule struct {
        summer.Module
    }
)

var (
    subMenu = panel.MainMenu.Add("Submenu", 1)
    news = panel.AddModule(
        &summer.ModuleSettings{
            Name:         "news",
            Title:        "News",
            Menu:         subMenu, // or panel.MainMenu
            MenuOrder:    1,
            TemplateName: "news/index",
        },
        &NewsModule{},
    )
)

func (module *NewsModule) Page(c *gin.Context) {
    settings := module.Settings
    c.HTML(200, settings.TemplateName+".html", gin.H{
        "title": settings.Title,
        "user":  c.MustGet("user"), // must be for correct username in the header
        "data":  obj{"text": "This is backend", "check": "Check Me"},
    })
}

/views/news/index.html

<h1>{{.title}}:</h1>
<div class="right-panel">
    <button id="addItem"><span class="fa fa-plus"></span> Add news</button>
</div>
<div class="wow">
    <img src="https://goo.gl/lLmbVR" />
    <h3>{{.data.text}}</h3>
    <input type="checkbox" id="c" checked /> {{.data.check}}
</div>

Result: (On http://localhost:8080/panel/news/ ) Summer screenshot

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 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()

Types

type Func added in v1.2.6

type Func map[string]func(c *gin.Context)

Func is alias for map[string]func(c *gin.Context)

type GroupsList

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

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)
type Menu struct {
	Title  string
	Order  int
	Parent *Menu
	Link   string
}

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) Init added in v1.2.6

func (m *Module) Init(settings *ModuleSettings, panel *Panel)

Init is default module's initial method

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 ModuleSettings

type ModuleSettings struct {
	Name             string
	Menu             *Menu
	MenuTitle        string
	MenuOrder        int
	PageRouteName    string
	AjaxRouteName    string
	SocketsRouteName string
	Title            string
	CollectionName   string
	TemplateName     string
	Ajax             Func
	Websockets       WebFunc
	Icon             string
	GroupTo          Simple
	GroupTitle       string
	Rights           Rights
}

ModuleSettings 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
	// Users
	Users *users
}

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 panel module

type Rights

type Rights struct {
	Groups  []string
	Actions []string
}

type Settings

type Settings struct {
	Port              uint
	Title             string
	AuthSalt          string
	AuthPrefix        string
	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
	TMPs              string // file path of /tmp directory
	DBName            string // MongoDB database name
	DefaultPage       string
	Language          string
	UsersCollection   string
	Debug             bool
	Vars              map[string]interface{}
	TFuncMap          template.FuncMap
	FirstStart        func()
	RouterGroup       *gin.RouterGroup
	Engine            *gin.Engine
	DisableAuth       bool     // if TRUE - without summer auth
	DisableFirstStart bool     // if TRUE - without first user creating
	JS                []string // external JS resources
	CSS               []string // external CSS resources
}

Settings intended for data transmission into the Create method of package

type Simple

type Simple interface {
	Init(settings *ModuleSettings, panel *Panel)
	Page(c *gin.Context)
	Ajax(c *gin.Context)
	Websockets(c *gin.Context)
	GetSettings() *ModuleSettings
}

Simple module interface

type UsersStruct

type UsersStruct struct {
	ID       uint64                 `form:"id"  json:"id"  bson:"_id"`
	Root     bool                   `form:"-"  json:"root"  bson:"root"`
	Name     string                 `form:"name" json:"name" bson:"name" binding:"required,min=3"`
	Notice   string                 `form:"notice" json:"notice" bson:"notice"`
	Login    string                 `form:"login" json:"login" bson:"login" binding:"required`
	Password string                 `form:"password" json:"-" bson:"password"`
	Created  uint                   `form:"-" json:"-" bson:"created"`
	Updated  uint                   `form:"-" json:"-" bson:"updated"`
	Deleted  bool                   `form:"-" json:"-" bson:"deleted"`
	Rights   Rights                 `form:"-" json:"rights" bson:"rights"`
	Settings map[string]interface{} `form:"-" json:"settings" bson:"-"`
	Demo     bool
}

type WebFunc added in v1.2.6

type WebFunc map[string]func(c *gin.Context, ws *websocket.Conn)

WebFunc is alias for map[string]func(c *websocket.Conn)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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