library

package module
v0.0.0-...-226d483 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

README

Lgin

a MVC library for gin framework

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RunMode      string
	HttpPort     int
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	ClientIp     string
)

Functions

func CacheMake

func CacheMake(root string, filename string, level int) string

make cache layer path

func DbClose

func DbClose(dbConfigs ...string)

close db

func DbInstance

func DbInstance(dbConfigs ...string) *gorm.DB

instance db client

func GetAllConfig

func GetAllConfig(source ...string) gin.H

factory get all config func

func GetConfig

func GetConfig(key string, source ...string) *ini.Key

factory get config func

func GetGlobal

func GetGlobal(key string) interface{}

get global config value

func GetSectionConfig

func GetSectionConfig(baseKey string, source ...string) gin.H

factory get section func

func HasConfig

func HasConfig(key string, source ...string) bool

factory has config func

func LogError

func LogError(content string) error

write error level log

func LogNotice

func LogNotice(content string) error

write notice level log

func LogRecord

func LogRecord(content gin.H, args ...string) error

write slice data log with json format

func LogWarning

func LogWarning(content string) error

write warning level log

func LogWrite

func LogWrite(content string, args ...string) error

write diy directory log

func RedisClose

func RedisClose(selectDb ...int)

close redis connect

func RedisKey

func RedisKey(key string, prefix string) string

make key with prefix

func SetGlobal

func SetGlobal(key string, value interface{}) bool

Set global config value

func SetGlobalOrExists

func SetGlobalOrExists(key string, value interface{}) bool

set global config value if not exists

Types

type ApiJsonData

type ApiJsonData struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"result"`
}

api response json data

func Callback

func Callback(code int, message string, data ...interface{}) *ApiJsonData

require api return format

type Cache

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

func (*Cache) Destroy

func (c *Cache) Destroy(name string) bool

destroy cache

func (*Cache) Get

func (c *Cache) Get(name string) (interface{}, error)

get cache

func (*Cache) Has

func (c *Cache) Has(name string) bool

check cache exists

func (*Cache) Set

func (c *Cache) Set(name string, value interface{}, expire ...int) error

set cache

type CacheInterface

type CacheInterface interface {
	Has(name string) bool
	Set(name string, value interface{}, expire ...int) error
	Get(name string) (interface{}, error)
	Destroy(name string) bool
}

func CacheInstance

func CacheInstance(isEncryption ...bool) CacheInterface

singleton mode

type Confer

type Confer interface {
	GetAll() gin.H
	GetSection(baseKey string) gin.H
	Get(key string) *ini.Key
	Has(key string) bool
}

config object func interface

func SourceConfig

func SourceConfig(source string) Confer

factory init config source

type Config

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

config object type struct

func (*Config) Get

func (c *Config) Get(key string) *ini.Key

get config

func (*Config) GetAll

func (c *Config) GetAll() gin.H

get all config

func (*Config) GetSection

func (c *Config) GetSection(baseKey string) gin.H

get all base config

func (*Config) Has

func (c *Config) Has(key string) bool

check config has exists

type ConfigsFactory

type ConfigsFactory struct {
}

func (*ConfigsFactory) Source

func (*ConfigsFactory) Source(file string) Confer

get config file source

type Controller

type Controller struct {
	Request      *Request
	TemplateData map[string]interface{}
}

func (*Controller) Assign

func (c *Controller) Assign(key interface{}, data ...interface{})

assign template var

func (*Controller) Error

func (c *Controller) Error(message string, params ...string)

error redirect

func (*Controller) Fetch

func (c *Controller) Fetch(name ...string)

fetch template and data

func (*Controller) Init

func (c *Controller) Init(child interface{}) gin.HandlerFunc

before init handle

func (*Controller) Initialize

func (*Controller) Initialize()

init controller

func (*Controller) Success

func (c *Controller) Success(message string, params ...string)

success redirect

type FactoryInterface

type FactoryInterface interface {
	Source(file string) Confer
}

factory init interface

type FactoryUploader

type FactoryUploader interface {
	SaveMultipart(form *multipart.Form) bool
	Save(file *multipart.FileHeader) bool
	GetError() string
}

func Upload

func Upload(driver string, opt *upload.Option) FactoryUploader

get upload client

type Log

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

func (*Log) InitFile

func (lo *Log) InitFile(filePath string) (*os.File, error)

auto create directory and open file stream

func (*Log) Write

func (lo *Log) Write(content string, args ...string) error

write error level logs

type Logger

type Logger interface {
	InitFile(filePath string) (*os.File, error)
	Write(content string, args ...string) error
}

func LogInstance

func LogInstance() Logger

singleton log

type Redis

type Redis struct {
	*redis.Client
}

func RedisInstance

func RedisInstance(selectDb ...int) *Redis

get singleton redis

type Request

type Request struct {
	*http.Request
	Cxt *gin.Context
	// contains filtered or unexported fields
}

func (*Request) Action

func (r *Request) Action() string

get current action name

func (*Request) BaseUrl

func (r *Request) BaseUrl() string

get base url

func (*Request) Controller

func (r *Request) Controller(name ...string) string

get current controller name

func (*Request) Domain

func (r *Request) Domain() string

get current domain

func (*Request) Get

func (r *Request) Get(key string, defaultValue ...string) string

get data

func (*Request) GetArray

func (r *Request) GetArray(key string) []string

get array

func (*Request) GetMap

func (r *Request) GetMap(key string) map[string]string

get request map

func (*Request) Input

func (r *Request) Input() []byte

input raw data

func (*Request) IsAjax

func (r *Request) IsAjax() bool

check request header is ajax

func (*Request) IsDelete

func (r *Request) IsDelete() bool

check request method is post

func (*Request) IsGet

func (r *Request) IsGet() bool

check request method is get

func (*Request) IsMobile

func (r *Request) IsMobile() bool

check client is mobile

func (*Request) IsOption

func (r *Request) IsOption() bool

check request method is post

func (*Request) IsPage

func (r *Request) IsPage() bool

func (*Request) IsPost

func (r *Request) IsPost() bool

check request method is post

func (*Request) IsPut

func (r *Request) IsPut() bool

check request method is post

func (*Request) IsQQ

func (r *Request) IsQQ() bool

check client is QQ

func (*Request) IsWeChat

func (r *Request) IsWeChat() bool

check client is WeChat

func (*Request) Lang

func (r *Request) Lang(name ...string) string

get current lang mode

func (*Request) Module

func (r *Request) Module(name ...string) string

get current module name

func (*Request) Param

func (r *Request) Param(key string, defaultValue ...string) string

get request param data

func (*Request) Port

func (r *Request) Port() string

get port

func (*Request) Post

func (r *Request) Post(key string, defaultValue ...string) string

post data

func (*Request) PostArray

func (r *Request) PostArray(key string) []string

post form data

func (*Request) PostJsonBind

func (r *Request) PostJsonBind(T interface{}) interface{}

post json into struct

func (*Request) PostJsonMap

func (r *Request) PostJsonMap() map[string]interface{}

post json into map

func (*Request) PostMap

func (r *Request) PostMap(key string) map[string]string

post form array data

func (*Request) Query

func (r *Request) Query() string

get query string

func (*Request) Scheme

func (r *Request) Scheme() string

get current scheme

func (*Request) Static

func (r *Request) Static(child interface{}, methodName string)

reflect call method

func (*Request) StaticWithReturn

func (r *Request) StaticWithReturn(child interface{}, method string, params ...interface{}) interface{}

reflect call method and return

func (*Request) Url

func (r *Request) Url() string

get current full url

type RequestFactory

type RequestFactory struct {
}

func (*RequestFactory) Instance

func (*RequestFactory) Instance(Cxt *gin.Context) Requester

instance request object

type Requester

type Requester interface {
	Scheme() string
	Domain() string
	Query() string
	Port() string
	BaseUrl() string
	Url() string
	Module(name ...string) string
	Controller(name ...string) string
	Action() string
	Lang(name ...string) string
	Get(key string, defaultValue ...string) string
	GetArray(key string) []string
	GetMap(key string) map[string]string
	Post(key string, defaultValue ...string) string
	PostArray(key string) []string
	Input() []byte
	PostMap(key string) map[string]string
	PostJsonMap() map[string]interface{}
	PostJsonBind(T interface{}) interface{}
	Param(key string, defaultValue ...string) string
	IsAjax() bool
	IsPage() bool
	IsGet() bool
	IsPost() bool
	IsPut() bool
	IsDelete() bool
	IsOption() bool
	IsMobile() bool
	IsWeChat() bool
	IsQQ() bool
	Static(child interface{}, methodName string)
	StaticWithReturn(child interface{}, methodName string, params ...interface{}) interface{}
}

type RequesterFactory

type RequesterFactory interface {
	Instance(Cxt *gin.Context) Requester
}

type UploadFactory

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

*

@auth CrastGin
@date 2020-10

func (*UploadFactory) GetError

func (u *UploadFactory) GetError() string

get upload error

func (*UploadFactory) Save

func (u *UploadFactory) Save(file *multipart.FileHeader) bool

upload file

func (*UploadFactory) SaveMultipart

func (u *UploadFactory) SaveMultipart(form *multipart.Form) bool

upload multipart files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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