gboot

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

README

gboot

api develop scaffold

example
package main

import (
	"github.com/gin-gonic/gin"
	"github.com/outakujo/gboot"
	"net/http"
)

func main() {
	gboot.Run(func(r gin.IRouter) {
		r.GET("/", func(c *gin.Context) {
			c.String(http.StatusOK, "%s", "hello world")
        })
	})
}

Documentation

Index

Constants

View Source
const (
	Abnormal = iota - 1
	Normal
	NotLogin
	LoginExpired
	LoginFail
	PageNumCanNotBeZero
	PageCountCanNotBeZero
	NotFound
)
View Source
const (
	DevMode       = "dev"
	ProMode       = "pro"
	TraceLog      = "trace"
	DebugLog      = "debug"
	InfoLog       = "info"
	WarnLog       = "warn"
	ErrorLog      = "error"
	FatalLog      = "fatal"
	PanicLog      = "panic"
	TextFormatter = "text"
	JSONFormatter = "json"
)

Variables

View Source
var Dbs = DbSet{}
View Source
var Logger = &centerLogger{}
View Source
var LoginExpiredResp = Resp{"errorCode": LoginExpired, "errorMsg": "login expired"}
View Source
var LoginFailResp = Resp{"errorCode": LoginFail, "errorMsg": "login fail"}
View Source
var NotLoginResp = Resp{"errorCode": NotLogin, "errorMsg": "not login"}
View Source
var PageCountCanNotBeZeroErr = errors.New("page count cannot be less than zero")
View Source
var PageCountCanNotBeZeroResp = Resp{"errorCode": PageCountCanNotBeZero, "errorMsg": "page count cannot be less than zero"}
View Source
var PageNotFoundResp = Resp{"errorCode": NotFound, "errorMsg": "not found"}
View Source
var PageNumCanNotBeZeroErr = errors.New("page number cannot be less than zero")
View Source
var PageNumCanNotBeZeroResp = Resp{"errorCode": PageNumCanNotBeZero, "errorMsg": "page number cannot be less than zero"}
View Source
var SessionMiss = errors.New("session miss")
View Source
var SystemErrorResp = Resp{"errorCode": Abnormal, "errorMsg": "system error"}
View Source
var TokenExpired = errors.New("token expired")
View Source
var TokenInvalid = errors.New("token invalid")
View Source
var TokenMalformed = errors.New("token error")
View Source
var TokenNotValidYet = errors.New("token not valid yet")

Functions

func ConcurrencyLimit

func ConcurrencyLimit(limit int, normal, fail gin.HandlerFunc) gin.HandlerFunc

func DbsIsEmpty

func DbsIsEmpty() bool

func GlobalMiddleware

func GlobalMiddleware(middle ...gin.HandlerFunc)

func Interceptor

func Interceptor(authentication Authentication, db *gorm.DB, fail gin.HandlerFunc) (enforcer *casbin.Enforcer, handle gin.HandlerFunc)

func InterceptorByEnforcer

func InterceptorByEnforcer(authentication Authentication, enforcer *casbin.Enforcer, fail gin.HandlerFunc) (handle gin.HandlerFunc)

func PageNumAndPageCountCheck

func PageNumAndPageCountCheck(pageNum, pageCount int64) error

func Run

func Run(api ApiFunc)

Types

type ApiFunc

type ApiFunc func(r gin.IRouter)

type Authentication

type Authentication func(c *gin.Context) Request

type DatabaseConfig

type DatabaseConfig struct {
	Alias        string
	Connect      string
	MaxIdleConns int `yaml:"maxIdleConns"`
	MaxOpenConns int `yaml:"maxOpenConns"`
	Dialect      string
}

type DbSet

type DbSet map[string]*gorm.DB

type DefaultClaims

type DefaultClaims struct {
	jwt.StandardClaims
	Id       int
	Nickname string
	Phone    string
	Name     string
	Salt     string
}

type DefaultToken

type DefaultToken struct {
	SigningKey []byte
}

func (*DefaultToken) Create

func (t *DefaultToken) Create(claims DefaultClaims) (string, error)

func (*DefaultToken) Parse

func (t *DefaultToken) Parse(tokenString string) (*DefaultClaims, error)

type OnlineSessionSet

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

func NewOnline

func NewOnline(sessions map[int]*Session) *OnlineSessionSet

func (*OnlineSessionSet) Add

func (on *OnlineSessionSet) Add(s Session)

func (*OnlineSessionSet) Counts

func (on *OnlineSessionSet) Counts() int

func (*OnlineSessionSet) Delete

func (on *OnlineSessionSet) Delete(id int) *Session

func (*OnlineSessionSet) Get

func (on *OnlineSessionSet) Get(id int) (s *Session, err error)

type PageParam

type PageParam struct {
	PageNum   int64
	PageCount int64
}

type PageResult

type PageResult struct {
	Pages  int64
	Counts int64
}

func MysqlPage

func MysqlPage(param PageParam, slice interface{}, db *gorm.DB, sql string, values ...interface{}) (pr PageResult, err error)

slice must be pointer type

func (PageResult) String

func (p PageResult) String() string

type Pro

type Pro map[string]interface{}

type Request

type Request struct {
	Sub string
	Obj string
	Act string
}

type Resp

type Resp map[string]interface{}

func ErrResp

func ErrResp(errCode int, errMsg string) Resp

func NormalResp

func NormalResp(data RespData) Resp

type RespData

type RespData map[string]interface{}

type Session

type Session struct {
	Id      int
	Expires time.Duration

	Pro Pro
	// contains filtered or unexported fields
}

type StaticRes

type StaticRes struct {
	Dir  string
	Path string
}

type YamlConfig

type YamlConfig struct {
	ContextName       string           `yaml:"contextName"`
	ServerName        string           `yaml:"serverName"`
	Statics           []StaticRes      `yaml:",flow"`
	Database          []DatabaseConfig `yaml:"database,flow"`
	Port              int
	RunMode           string   `yaml:"runMode"`
	DisableConsoleLog bool     `yaml:"disableConsoleLog"`
	ConsoleLogLevel   string   `yaml:"consoleLogLevel"`
	LogFileOutLevels  []string `yaml:"logFileOutLevels,flow"`
	EnableLogFileOut  bool     `yaml:"enableLogFileOut"`
	LogFormatType     string   `yaml:"logFormatType"`
	EnableHttps       bool     `yaml:"enableHttps"`
	CertFile          string   `yaml:"certFile"`
	KeyFile           string   `yaml:"keyFile"`
	HtmlTemplateDir   string   `yaml:"htmlTemplateDir"`
}
var Config YamlConfig

Jump to

Keyboard shortcuts

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