simple

package
v0.0.0-...-c96783f Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2019 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FMT_DATE_TIME = "2006-01-02 15:04:05"

	FMT_DATE = "2006-01-02"

	FMT_TIME = "15:04:05"

	FMT_DATE_TIME_CN = "2006年01月02日 15时04分05秒"

	FMT_DATE_CN = "2006年01月02日"

	FMT_TIME_CN = "15时04分05秒"
)
View Source
const CODE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
View Source
const CodeLength = 62

Variables

View Source
var CodeMap = map[string]int64{"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "a": 10,
	"b": 11, "c": 12, "d": 13, "e": 14, "f": 15, "g": 16, "h": 17, "i": 18, "j": 19, "k": 20, "l": 21, "m": 22,
	"n": 23, "o": 24, "p": 25, "q": 26, "r": 27, "s": 28, "t": 29, "u": 30, "v": 31, "w": 32, "x": 33, "y": 34,
	"z": 35, "A": 36, "B": 37, "C": 38, "D": 39, "E": 40, "F": 41, "G": 42, "H": 43, "I": 44, "J": 45, "K": 46,
	"L": 47, "M": 48, "N": 49, "O": 50, "P": 51, "Q": 52, "R": 53, "S": 54, "T": 55, "U": 56, "V": 57, "W": 58,
	"X": 59, "Y": 60, "Z": 61}
View Source
var (
	ErrorNotLogin = NewError(1, "请先登录")
)

Functions

func AbsoluteURL

func AbsoluteURL(u string, baseURL, URL string) (string, error)

AbsoluteURL u : /1/2/3 ... baseURL : www.baidu.com Url : www.baidu.com/a/b/c

func AppendLine

func AppendLine(path string, content string) error

func CloseDB

func CloseDB()

关闭连接

func Contains

func Contains(search interface{}, target interface{}) bool

func ContainsIgnoreCase

func ContainsIgnoreCase(search string, target []string) bool

func Decode62

func Decode62(str string) int64

*

  • 解码字符串为整数

func Encode62

func Encode62(number int64) string

*

  • 编码 整数 为 base62 字符串

func EncodePassword

func EncodePassword(rawPassword string) string

func FormValue

func FormValue(ctx iris.Context, name string) string

func FormValueBool

func FormValueBool(ctx iris.Context, name string) (bool, error)

func FormValueDefault

func FormValueDefault(ctx iris.Context, name, def string) string

func FormValueInt

func FormValueInt(ctx iris.Context, name string) (int, error)

func FormValueInt64

func FormValueInt64(ctx iris.Context, name string) (int64, error)

func FormValueInt64Array

func FormValueInt64Array(ctx iris.Context, name string) []int64

func FormValueInt64Default

func FormValueInt64Default(ctx iris.Context, name string, def int64) int64

func FormValueIntDefault

func FormValueIntDefault(ctx iris.Context, name string, def int) int

func FormValueRequired

func FormValueRequired(ctx iris.Context, name string) (string, error)

func FormValueStringArray

func FormValueStringArray(ctx iris.Context, name string) []string

func FormatJson

func FormatJson(obj interface{}) (str string, err error)

func Generate

func Generate(baseDir, pkgName string, models ...GenerateStruct)

func GetDB

func GetDB() *gorm.DB

获取数据库链接

func GetDay

func GetDay(time time.Time) int

return yyyyMMdd

func GetHtmlText

func GetHtmlText(html string) string

获取html文本

func GetSummary

func GetSummary(s string, length int) string

获取summary

func IsEmpty

func IsEmpty(a interface{}) bool

func MD5

func MD5(str string) string

func MD5Bytes

func MD5Bytes(data []byte) string

func MapToStruct

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

func NowTimestamp

func NowTimestamp() int64

毫秒时间戳

func NowUnix

func NowUnix() int64

秒时间戳

func OpenDB

func OpenDB(conf *DBConfiguration) *gorm.DB

打开数据库

func ParseJson

func ParseJson(str string, t interface{}) error

func PathExists

func PathExists(path string) (bool, error)

func PrettyTime

func PrettyTime(timestamp int64) string

*

  • 将时间格式换成 xx秒前,xx分钟前...
  • 规则:
  • 59秒--->刚刚
  • 1-59分钟--->x分钟前(23分钟前)
  • 1-24小时--->x小时前(5小时前)
  • 昨天--->昨天 hh:mm(昨天 16:15)
  • 前天--->前天 hh:mm(前天 16:15)
  • 前天以后--->mm-dd(2月18日)

func RuneLen

func RuneLen(s string) int

字符成长度

func StructFields

func StructFields(s interface{}) []reflect.StructField

获取struct字段

func StructName

func StructName(s interface{}) string

获取struct name

func StructToMap

func StructToMap(obj interface{}, excludes ...string) map[string]interface{}

func StructTypeOf

func StructTypeOf(s interface{}) reflect.Type

func Substr

func Substr(s string, start, length int) string

截取字符串

func TimeFormat

func TimeFormat(time time.Time, layout string) string

时间格式化

func TimeFromTimestamp

func TimeFromTimestamp(timestamp int64) time.Time

毫秒时间戳转时间

func TimeFromUnix

func TimeFromUnix(unix int64) time.Time

秒时间戳转时间

func TimeParse

func TimeParse(timeStr, layout string) (time.Time, error)

字符串时间转时间类型

func Timestamp

func Timestamp(t time.Time) int64

毫秒时间戳

func Tx

func Tx(db *gorm.DB, txFunc func(tx *gorm.DB) error) (err error)

事务环绕

func ValidatePassword

func ValidatePassword(encodePassword, inputPassword string) bool

func WithTimeAsStartOfDay

func WithTimeAsStartOfDay(t time.Time) time.Time

返回指定时间当天的开始时间

func WriteString

func WriteString(path string, content string, append bool) error

Types

type CodeError

type CodeError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

errorString is a trivial implementation of error.

func NewError

func NewError(code int, text string) *CodeError

New returns an error that formats as the given text.

func NewError2

func NewError2(err error) *CodeError

func NewErrorMsg

func NewErrorMsg(text string) *CodeError

func (*CodeError) Error

func (e *CodeError) Error() string

type DBConfiguration

type DBConfiguration struct {
	Dialect        string
	Url            string
	MaxIdle        int
	MaxActive      int
	EnableLogModel bool
	Models         []interface{}
}

type GenerateField

type GenerateField struct {
	CamelName   string
	NativeField reflect.StructField
}

type GenerateStruct

type GenerateStruct struct {
	Name   string
	Fields []GenerateField
}

func GetGenerateStruct

func GetGenerateStruct(s interface{}) GenerateStruct

type GormModel

type GormModel struct {
	Id int64 `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
}

type InputData

type InputData struct {
	PkgName   string
	Name      string // FuckShit
	CamelName string // fuckShit
	KebabName string // FuckShit -> fuck-shit
	Fields    []GenerateField
}

type JsonResult

type JsonResult struct {
	ErrorCode int         `json:"errorCode"`
	Message   string      `json:"message"`
	Data      interface{} `json:"data"`
	Success   bool        `json:"success"`
}

func Error

func Error(err *CodeError) *JsonResult

func ErrorCode

func ErrorCode(code int, message string) *JsonResult

func ErrorMsg

func ErrorMsg(message string) *JsonResult

func Json

func Json(code int, message string, data interface{}, success bool) *JsonResult

func JsonData

func JsonData(data interface{}) *JsonResult

func Success

func Success() *JsonResult

type MdOption

type MdOption func(*SimpleMd)

option

func MdWithSummaryLength

func MdWithSummaryLength(summaryLength int) MdOption

生成摘要的长度

func MdWithTOC

func MdWithTOC() MdOption

开启toc

func MdWithThumb

func MdWithThumb(md *SimpleMd) MdOption

开启缩略图

type MdResult

type MdResult struct {
	ContentHtml string // 内容
	SummaryText string // 摘要
	TocHtml     string // TOC目录
	ThumbUrl    string // 缩略图
}

type OrderByCol

type OrderByCol struct {
	Column string // 排序字段
	Asc    bool   // 是否正序
}

排序信息

type PageResult

type PageResult struct {
	Page    *Paging     `json:"page"`    // 分页信息
	Results interface{} `json:"results"` // 数据
}

分页返回数据

type Paging

type Paging struct {
	Page  int `json:"page"`  // 页码
	Limit int `json:"limit"` // 每页条数
	Total int `json:"total"` // 总数据条数
}

分页请求数据

func GetPaging

func GetPaging(ctx iris.Context) *Paging

func (*Paging) Offset

func (p *Paging) Offset() int

func (*Paging) TotalPage

func (p *Paging) TotalPage() int

type ParamQueries

type ParamQueries struct {
	Ctx         iris.Context
	Queries     []queryPair  // 条件
	OrderByCols []OrderByCol // 排序
	Paging      *Paging      // 分页
}

func NewParamQueries

func NewParamQueries(ctx iris.Context) *ParamQueries

func (*ParamQueries) Asc

func (o *ParamQueries) Asc(column string) *ParamQueries

func (*ParamQueries) Desc

func (o *ParamQueries) Desc(column string) *ParamQueries

func (*ParamQueries) Eq

func (o *ParamQueries) Eq(column string, args ...interface{}) *ParamQueries

func (*ParamQueries) EqAuto

func (o *ParamQueries) EqAuto(column string) *ParamQueries

func (*ParamQueries) Gt

func (o *ParamQueries) Gt(column string, args ...interface{}) *ParamQueries

func (*ParamQueries) GtAuto

func (o *ParamQueries) GtAuto(column string) *ParamQueries

func (*ParamQueries) Gte

func (o *ParamQueries) Gte(column string, args ...interface{}) *ParamQueries

func (*ParamQueries) GteAuto

func (o *ParamQueries) GteAuto(column string) *ParamQueries

func (*ParamQueries) Like

func (o *ParamQueries) Like(column string, str string) *ParamQueries

func (*ParamQueries) LikeAuto

func (o *ParamQueries) LikeAuto(column string) *ParamQueries

func (*ParamQueries) Limit

func (o *ParamQueries) Limit(limit int) *ParamQueries

func (*ParamQueries) Lt

func (o *ParamQueries) Lt(column string, args ...interface{}) *ParamQueries

func (*ParamQueries) LtAuto

func (o *ParamQueries) LtAuto(column string) *ParamQueries

func (*ParamQueries) Lte

func (o *ParamQueries) Lte(column string, args ...interface{}) *ParamQueries

func (*ParamQueries) LteAuto

func (o *ParamQueries) LteAuto(column string) *ParamQueries

func (*ParamQueries) NotEq

func (o *ParamQueries) NotEq(column string, args ...interface{}) *ParamQueries

func (*ParamQueries) NotEqAuto

func (o *ParamQueries) NotEqAuto(column string) *ParamQueries

func (*ParamQueries) OrderBy

func (o *ParamQueries) OrderBy(column string, asc bool) *ParamQueries

func (*ParamQueries) Page

func (o *ParamQueries) Page(page, limit int) *ParamQueries

func (*ParamQueries) PageAuto

func (o *ParamQueries) PageAuto() *ParamQueries

func (*ParamQueries) StartCount

func (o *ParamQueries) StartCount(db *gorm.DB) *gorm.DB

func (*ParamQueries) StartQuery

func (o *ParamQueries) StartQuery(db *gorm.DB) *gorm.DB

func (*ParamQueries) Where

func (o *ParamQueries) Where(query string, args ...interface{}) *ParamQueries

type QueryCnd

type QueryCnd struct {
	Query  string
	Args   []interface{}
	Orders []string
	Limit  int
	Offset int
}

func NewQueryCnd

func NewQueryCnd(query string, args ...interface{}) *QueryCnd

func (*QueryCnd) DoQuery

func (q *QueryCnd) DoQuery(db *gorm.DB) *gorm.DB

func (*QueryCnd) Order

func (q *QueryCnd) Order(order string) *QueryCnd

func (*QueryCnd) Page

func (q *QueryCnd) Page(page, size int) *QueryCnd

func (*QueryCnd) Size

func (q *QueryCnd) Size(size int) *QueryCnd

type RspBuilder

type RspBuilder struct {
	Data map[string]interface{}
}

func NewEmptyRspBuilder

func NewEmptyRspBuilder() *RspBuilder

func NewRspBuilder

func NewRspBuilder(obj interface{}) *RspBuilder

func NewRspBuilderExcludes

func NewRspBuilderExcludes(obj interface{}, excludes ...string) *RspBuilder

func (*RspBuilder) Build

func (this *RspBuilder) Build() map[string]interface{}

func (*RspBuilder) JsonResult

func (this *RspBuilder) JsonResult() *JsonResult

func (*RspBuilder) Put

func (this *RspBuilder) Put(key string, value interface{}) *RspBuilder

type SimpleMd

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

simple md

func NewMd

func NewMd(options ...MdOption) *SimpleMd

new simple md

func (*SimpleMd) Run

func (this *SimpleMd) Run(mdText string) *MdResult

run

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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