ironman

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

README

go-ironman

Golang

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Db *gorm.DB

Db 数据库操作

View Source
var DefaultJWTConfig = JWTConfig{
	Claims:        nil,
	SigningMethod: jwt.SigningMethodHS256.Name,
	ContextKey:    "user",
	SigningKey:    []byte("ironman"),
	TokenLookup:   "header:" + echo.HeaderAuthorization,
	AuthScheme:    "Bearer",
}

DefaultJWTConfig 默认JWT配置

View Source
var MongoSession *mgo.Session

MongoSession

View Source
var Redis *redis.Client

Redis 客户端

Functions

func Alloc

func Alloc(size int) []int64

Alloc is 分配大小

func ComparePasswordAndStr

func ComparePasswordAndStr(password, hash string) bool

ComparePasswordAndStr 比较密码

func CreateDB

func CreateDB(callback func(db *gorm.DB)) *gorm.DB

CreateDB 创建数据库链接

func DataSourceClose added in v0.0.3

func DataSourceClose()

func DataSourceConnect

func DataSourceConnect(callback func(db *gorm.DB))

DataSourceConnect 初始化数据库链接

func Free

func Free(mem []int64)

Free 釋放内存

func GenRandomString

func GenRandomString(len int) string

GenRandomString 生成随机字符串

func GeneratePassword

func GeneratePassword(password string) string

GeneratePassword 生成密码

func GenerateToken

func GenerateToken(claims jwt.Claims) (string, error)

GenerateToken 生成token

func GetToken added in v0.1.10

func GetToken(c echo.Context, name string, authScheme string) (string, error)

func JSON

func JSON(c echo.Context, result *Result) error

JSON 输出json

func JwtConfig

func JwtConfig(skiper middleware.Skipper) (jwtConfig middleware.JWTConfig)

JwtConfig 设置JWT 配置

func MD5

func MD5(text string) string

MD5 生成32位MD5

func Map2Struct

func Map2Struct(data map[string]interface{}, obj interface{}) error

Map2Struct map转Struct

func MongoDbConnect

func MongoDbConnect()

MongoDbConnect 连接Mongodb并获取Database

func RedisClose added in v0.0.8

func RedisClose()

func RedisConnect

func RedisConnect()

RedisConnect Redis连接

func RedisStats added in v0.0.8

func RedisStats()

func Server

func Server(e *echo.Echo)

Server 启动服务

func SetField

func SetField(obj interface{}, name string, value interface{}) error

SetField 用map的值替换结构的值

func Struct2Map

func Struct2Map(obj interface{}) map[string]interface{}

Struct2Map struct 转Map

func TypeConversion

func TypeConversion(value string, ntype string) (reflect.Value, error)

TypeConversion 类型转换

Types

type DbConfig

type DbConfig struct {
	Host            string
	Port            int16
	User            string
	Password        string
	DBName          string
	MaxIdleConns    int
	MaxOpenConns    int
	ConnMaxLifetime int
}

DbConfig 数据库配置

type Error

type Error struct {
	Code    int         `json:"code"`
	Key     string      `json:"error,omitempty"`
	Message interface{} `json:"message"`
}

Error 异常结构

func NewError

func NewError(code int, key string, msg interface{}) *Error

NewError 异常

func (*Error) Error

func (e *Error) Error() string

type JWTConfig

type JWTConfig struct {
	Claims        jwt.Claims
	SigningMethod string
	ContextKey    string
	SigningKey    []byte
	TokenLookup   string
	AuthScheme    string
	// contains filtered or unexported fields
}

JWTConfig JWT配置

type Map

type Map map[string]interface{}

Map 类型

type Optional

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

Optional 可选结构

func OptionalOf

func OptionalOf(val interface{}) *Optional

OptionalOf 构造Optional

func OptionalOfNil

func OptionalOfNil() *Optional

OptionalOfNil 设置nil Optinal

func ParserToken

func ParserToken(c echo.Context) *Optional

ParserToken 解析token

func ParserTokenUnverified added in v0.1.10

func ParserTokenUnverified(c echo.Context, name string, authScheme string) (*Optional, error)

func TokenOf added in v0.1.10

func TokenOf(auth string) (*Optional, error)

func (*Optional) Get

func (optinal *Optional) Get() interface{}

Get 获取Optinal值

func (*Optional) IsPresent

func (optinal *Optional) IsPresent() bool

IsPresent Optional值是否nil

type Result

type Result struct {
	Code int         `json:"code"`
	Data interface{} `json:"data,omitempty"`
}

Result 返回结果

func ResultOf

func ResultOf(code int, data interface{}) *Result

ResultOf 构造Result

type SyncPool

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

SyncPool is a sync.Pool base slab allocation memory pool

var DEFAULT_SYNC_POOL *SyncPool

DEFAULT_SYNC_POOL 默認對象池

func NewPool

func NewPool() *SyncPool

NewPool is 分配内存的时候,从池子里面找满足容量切最小的池子。比如申请长度是2的,就分配大小为5的那个池子。如果是11,就分配大小是20的那个池子里面的对象

func NewSyncPool

func NewSyncPool(minSize, maxSize, factor int) *SyncPool

NewSyncPool 申請

func (*SyncPool) Alloc

func (pool *SyncPool) Alloc(size int) []int64

Alloc 申請内存

func (*SyncPool) Free

func (pool *SyncPool) Free(mem []int64)

Free 釋放

type User

type User struct {
	ID         int    `json:"id" gorm:"primary_key"`
	Version    int    `json:"version,omitempty"gorm:"column:_version"`
	ParentID   int    `json:"parentId,omitempty" gorm:"column:parent_id"`
	NickName   string `json:"nick_name" gorm:"column:nick_name"`
	UserName   string `json:"userName,omitempty" gorm:"column:user_name"`
	RealName   string `json:"realName,omitempty" gorm:"column:real_name"`
	Password   string `json:"password,omitempty" gorm:"column:password"`
	Type       int8   `json:"type,omitempty"`
	Sex        int    `json:"sex,omitempty"`
	Avatar     string `json:"avatar,omitempty"`
	City       string `json:"city,omitempty"`
	Province   string `json:"province,omitempty"`
	Country    string `json:"country,omitempty"`
	Email      string `json:"email,omitempty"`
	Mobile     string `json:"mobile,omitempty"`
	Score      int    `json:"score"`
	RegTime    int64  `json:"regTime,omitempty"`
	UpgradedAt int64  `json:"upgradedAt,omitempty" gorm:"column:upgraded_at"`
	CreatedAt  int64  `json:"createdAt,omitempty" gorm:"column:created_at"`
	UpdatedAt  int64  `json:"updatedAt,omitempty" gorm:"column:updated_at"`
}

User 用户基础信息

type UserWechat

type UserWechat struct {
	ID        int    `json:"id" gorm:"primary_key"`
	UnionID   string `json:"unionId" gorm:"column:unionid"`
	OpenID    string `json:"openId" gorm:"column:openid"`
	CreatedAt int64  `json:"created_at" gorm:"column:created_at"`
	UpdatedAt int64  `json:"updated_at" gorm:"column:updated_at"`
}

UserWechat 用户微信信息

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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