ebase

package module
v0.0.0-...-cc2e26c Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: BSD-3-Clause Imports: 32 Imported by: 1

README

ebase

ForEase's golang application base library

Install ebase

go get github.com/forease/ebase

Import ebase

import . "github.com/forease/ebase"

Use ebase

About

北京实易时代科技有限公司
Beijing ForEase Times Technology Co., Ltd.
http://www.forease.net

Contact me

Jonsen Yang
im16hot#gmail.com (replace # with @)

Documentation

Overview

Ebase frame for daemon program Author Jonsen Yang Date 2013-07-05 Copyright (c) 2013 ForEase Times Technology Co., Ltd. All rights reserved.

Ebase frame for daemon program Author Jonsen Yang Date 2013-07-05 Copyright (c) 2013 ForEase Times Technology Co., Ltd. All rights reserved.

Index

Constants

View Source
const (
	LevelCritical = iota
	LevelError
	LevelWarning
	LevelInfo
	LevelDebug
	LevelTrace
)

Log levels to control the logging output.

Variables

View Source
var (
	// 日志
	Log        *BaseLog
	Config     *config.Config
	SigHandler = make(map[string]interface{}) //
	G          = make(map[string]interface{}) //

	AppName = path.Base(os.Args[0])
)

Functions

func CreatePid

func CreatePid()

create pid file

func Daemon

func Daemon(nochdir, noclose int) int

func DelFiles

func DelFiles(files []os.FileInfo, count int, fileDir string)

获取所有文件 如果文件达到最上限,按时间删除

func EbaseInit

func EbaseInit()

func FileGetContent

func FileGetContent(file string) (string, error)

get string from text file

func FileMTime

func FileMTime(file string) (int64, error)

get file modified time

func FilePutContent

func FilePutContent(file string, content string) (int, error)

put string to file

func FileSize

func FileSize(file string) (int64, error)

get file size as how many bytes

func GetHost

func GetHost(req *http.Request) string

func GetInt64Str

func GetInt64Str(d int64) string

int64 to string

func GetIntArrToStr

func GetIntArrToStr(i []int, d string) (s string)

int slice to string

func GetIntStr

func GetIntStr(d int) string

int to string

func GetStrFloat64

func GetStrFloat64(s string) float64

string to float64

func GetStrInt

func GetStrInt(d string) int

string to int

func GetStrInt64

func GetStrInt64(d string) int64

string to int64

func GetStrUint

func GetStrUint(d string) uint

string to uint

func GetStrUint32

func GetStrUint32(d string) uint32

string to uint32

func GetStrUint64

func GetStrUint64(d string) uint64

string to uint64

func GetTimeAgo

func GetTimeAgo(t int64) (s string)

func GetUint64Str

func GetUint64Str(d uint64) string

uint64 to string

func GetUintStr

func GetUintStr(d uint) string

uint to string

func Help

func Help()

func IsExist

func IsExist(path string) bool

IsExist returns whether a file or directory exists.

func IsFile

func IsFile(file string) bool

it returns false when it's a directory or does not exist.

func LoadConfig

func LoadConfig(configFile string) (cfg *config.Config)

func Md5

func Md5(key string) string

encode md5

func Mkdir

func Mkdir(src string) error

create dir

func NewXorm

func NewXorm(opt *OrmOption) (orm *xorm.Engine, err error)

func Rename

func Rename(file, to string) error

rename file name

func SignalHandle

func SignalHandle(funcs map[string]interface{})
func Unlink(file string) error

delete file

Types

type AuthClients

type AuthClients []interface{}

func LoadAuthClients

func LoadAuthClients(auths string) AuthClients

func (AuthClients) ClientAuthor

func (clients AuthClients) ClientAuthor(ipAddr net.IP) bool

type BaseLog

type BaseLog struct {
	Loger    *log.Logger
	LogFile  string
	LogLevel int
	LogType  string
}

func NewLog

func NewLog(opt *LogOptions) (l *BaseLog)

New log example:

opt := &LogOptions{Type: logType, File: logFile, Level: logLevel, Flag: logFlag}
log := NewLog(opt)

func (*BaseLog) Critical

func (l *BaseLog) Critical(v ...interface{})

func (*BaseLog) Criticalf

func (l *BaseLog) Criticalf(format string, v ...interface{})

func (*BaseLog) Debug

func (l *BaseLog) Debug(v ...interface{})

func (*BaseLog) Debugf

func (l *BaseLog) Debugf(format string, v ...interface{})

func (*BaseLog) Error

func (l *BaseLog) Error(v ...interface{})

func (*BaseLog) Errorf

func (l *BaseLog) Errorf(format string, v ...interface{})

func (*BaseLog) Info

func (l *BaseLog) Info(v ...interface{})

func (*BaseLog) Infof

func (l *BaseLog) Infof(format string, v ...interface{})

func (*BaseLog) Panic

func (l *BaseLog) Panic(v ...interface{})

func (*BaseLog) Panicf

func (l *BaseLog) Panicf(format string, v ...interface{})

func (*BaseLog) Printf

func (l *BaseLog) Printf(format string, v ...interface{})

func (*BaseLog) Println

func (l *BaseLog) Println(v ...interface{})

func (*BaseLog) Trace

func (l *BaseLog) Trace(v ...interface{})

func (*BaseLog) Tracef

func (l *BaseLog) Tracef(format string, v ...interface{})

func (*BaseLog) Warn

func (l *BaseLog) Warn(v ...interface{})

func (*BaseLog) Warnf

func (l *BaseLog) Warnf(format string, v ...interface{})

type Cache

type Cache struct {
	Item map[interface{}]interface{}
	Lock *sync.RWMutex
	Len  uint64
}

func NewCache

func NewCache() (c *Cache)

新建一个cache

func (*Cache) Cleanup

func (c *Cache) Cleanup(f func(interface{}) bool)

清除cache 参数是一个函数 传递外部函数判断cache里数据,决定是否要删除

func (*Cache) Del

func (c *Cache) Del(key interface{})

删除cache

func (*Cache) Exists

func (c *Cache) Exists(key interface{}) bool

检查cache是否存在

func (*Cache) Get

func (c *Cache) Get(key interface{}) interface{}

从cache里获取

func (*Cache) Set

func (c *Cache) Set(key, val interface{}) bool

设置cache

type FileRepos

type FileRepos []Repository

func (FileRepos) Len

func (r FileRepos) Len() int

func (FileRepos) Less

func (r FileRepos) Less(i, j int) bool

func (FileRepos) Swap

func (r FileRepos) Swap(i, j int)

type KeyValue

type KeyValue struct {
	Key   interface{}
	Value interface{}
}

type LogOptions

type LogOptions struct {
	Type   string // log type: consloe, file, system
	File   string // log file, need type is file
	Level  int    // output log level
	Flag   int    // log flag
	Enable bool
}

type MailMessage

type MailMessage struct {
	From    mail.Address // if From.Address is empty, Config.DefaultFrom will be used
	To      []mail.Address
	Cc      []mail.Address
	Bcc     []mail.Address
	Subject string
	Content string
	S       *Smtp
}

func (*MailMessage) Send

func (self *MailMessage) Send() error

func (*MailMessage) Validate

func (self *MailMessage) Validate() error

Returns the first error

type Mailer

type Mailer struct {
	Subject     string
	Content     string
	To, Cc, Bcc string
}

type Map

type Map map[string]interface{}

func NewMap

func NewMap() Map

func (Map) Get

func (set Map) Get(name string, value interface{}) (err error)

func (Map) String

func (set Map) String() (str string)

type ModelOption

type ModelOption struct {
	Orm   OrmOption
	Redis RedisOption
}

type Models

type Models struct {
	Orm          *xorm.Engine
	OrmCache     bool
	OrmCacheTime int64
	Redis        *Redis
	RedisEnable  bool
	RedisPrefix  string
	Driver       string
}
var Dbh *Models

func NewDefaultModels

func NewDefaultModels() (dbh *Models, err error)

func NewModels

func NewModels(opt *ModelOption) (*Models, error)

func (*Models) Close

func (dbh *Models) Close() error

type OrmOption

type OrmOption struct {
	Driver    string
	Proto     string
	Host      string
	User      string
	Password  string
	Name      string
	Ssl       string
	Path      string
	Schema    string
	Log       string
	Port      int
	CacheTime int
	Cache     bool
	Debug     bool
}

type PageOptions

type PageOptions struct {
	OrderIdx  int
	SearchKey string
	OrderBy   string
}

type Redis

type Redis struct {
	redis.Client
	RedisPrefix string
}

func NewRedis

func NewRedis(opt *RedisOption) (*Redis, error)

func (*Redis) GetRedisKey

func (self *Redis) GetRedisKey(keys ...interface{}) (key string)

func (*Redis) RedisDelete

func (self *Redis) RedisDelete(keys ...interface{}) (bool, error)

func (*Redis) RedisDeleteAll

func (self *Redis) RedisDeleteAll(keys ...interface{}) (s bool, err error)

func (*Redis) RedisExists

func (self *Redis) RedisExists(keys ...interface{}) (bool, error)

func (*Redis) RedisGet

func (self *Redis) RedisGet(keys ...interface{}) (value []byte, err error)

func (*Redis) RedisGetJson

func (self *Redis) RedisGetJson(v interface{}, keys ...interface{}) (err error)

func (*Redis) RedisIncr

func (self *Redis) RedisIncr(keys ...interface{}) (int64, error)

func (*Redis) RedisSet

func (self *Redis) RedisSet(expire int64, value interface{}, keys ...interface{}) (err error)

func (*Redis) RedisSetJson

func (self *Redis) RedisSetJson(expire int64, mp interface{}, keys ...interface{}) (err error)

type RedisOption

type RedisOption struct {
	Host   string
	Auth   string
	Prefix string
	Port   int
	Db     int
	Enable bool
}

type Repository

type Repository struct {
	Name     string
	FileTime int64
}

type Smtp

type Smtp struct {
	SmtpUserName                     string
	SmtpHost, SmtpUser, SmtpPassword string
	SmtpPort                         int
	SmtpAuth, SmtpTLS, SmtpDaemon    bool
	// contains filtered or unexported fields
}

SMTP setup

func NewSmtp

func NewSmtp() *Smtp

func (*Smtp) MailSendServer

func (s *Smtp) MailSendServer()

运行一个goroutine 监听发送邮件任务

func (*Smtp) MailSender

func (s *Smtp) MailSender(subject, content, to string, args ...string) (err error)

func (*Smtp) NewMailMessage

func (s *Smtp) NewMailMessage(m *Mailer) *MailMessage

Jump to

Keyboard shortcuts

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