gosf

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: MIT Imports: 29 Imported by: 0

README

GOSF

a simple service framework for go.

For personal study only.

Installation

Use Go modules to install GOSF in your application.

go get github.com/oyjz/gosf

Getting started

To get started with GOSF, start here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearFileContent

func ClearFileContent(filePath string) error

清空文件内容

func Configer

func Configer(file string) config.Config

Configer 获取配置实例

func Exit

func Exit(v ...any)

Exit 退出程序

func GetFileMD5

func GetFileMD5(filePath string) (string, error)

func GetLocation

func GetLocation(target string) string

func InForString

func InForString(items []string, item string) bool

func IsProcessRunning

func IsProcessRunning(processName string) (bool, error)

func IsRelease

func IsRelease() bool

IsRelease 判断是否是二进制运行

func KillProcessByName

func KillProcessByName(processName string) error

func MkdirAll

func MkdirAll(path string)

func PanicErr

func PanicErr(err error, v ...any)

PanicErr 错误处理

func PathExists

func PathExists(path string) (bool, error)

PathExists 判断文件/文件夹是否存在

func ReadFile

func ReadFile(filePath string) string

func ReplaceFile

func ReplaceFile(sourcePath, destPath string) error

替换文件

func RootPath

func RootPath() string

RootPath 获取运行目录

func StartProgram

func StartProgram(programDir, programName string, args ...string) error

Types

type Cache

type Cache struct {
	*cache.Cache // 嵌入 cache.Cache
}

func NewCache

func NewCache(defaultExpiration, cleanupInterval time.Duration) *Cache

func (*Cache) Lock

func (p *Cache) Lock(key string, interval time.Duration, setLock bool) bool

Lock 缓存锁

func (*Cache) UnLock

func (p *Cache) UnLock(key string)

UnLock 解锁

type Config

type Config struct {
	Name       string // APP名称,默认二进制文件名
	Path       string // APP所在路径,默认二进制文件所在目录
	LogPath    string // APP日志保存目录
	LogMaxSize int    // 日志文件最大大小,单位M
	Version    string
}

Config APP配置

type DbPool

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

DbPool 数据库操作处理结构体

func (*DbPool) All

func (p *DbPool) All() []map[string]interface{}

All 获取多条数据,返回数据类型为slice,slice内层为map

func (*DbPool) BatchInsert

func (p *DbPool) BatchInsert(params []map[string]interface{}) (affectRows int, err error)

BatchInsert 批量插入

func (*DbPool) Close added in v1.0.1

func (p *DbPool) Close()

func (*DbPool) Count

func (p *DbPool) Count() int

Count 查询记录数

func (*DbPool) Delete

func (p *DbPool) Delete() (affectRows int, err error)

Delete 定义删除数据方法

func (*DbPool) Execute

func (p *DbPool) Execute(Sql string) (affectRows int, err error)

Execute 查询执行SQL方法

func (*DbPool) FetchAll

func (p *DbPool) FetchAll(Sql string) []map[string]interface{}

FetchAll 定义执行SQL返回多条数据方法

func (*DbPool) FetchOne

func (p *DbPool) FetchOne(Sql string) map[string]interface{}

FetchOne 定义执行SQL返回一条数据方法

func (*DbPool) Get

func (p *DbPool) Get() map[string]interface{}

Get 获取第一条数据,返回数据类型为map

func (*DbPool) GetPool

func (p *DbPool) GetPool() *sql.DB

func (*DbPool) GroupBy

func (p *DbPool) GroupBy(params ...string) *DbPool

GroupBy 定义数据库分组函数,入参类似于python的args

func (*DbPool) Insert

func (p *DbPool) Insert(params map[string]interface{}) (lastId int, err error)

Insert 定义创建数据方法,返回最后的ID

func (*DbPool) LastSql

func (p *DbPool) LastSql() string

LastSql 获取最后执行SQL

func (*DbPool) Limit

func (p *DbPool) Limit(limit int) *DbPool

Limit

func (*DbPool) OrderBy

func (p *DbPool) OrderBy(params ...string) *DbPool

OrderBy 定义数据库排序函数,入参类似于python的args

func (*DbPool) Page

func (p *DbPool) Page(page int) *DbPool

Page

func (*DbPool) Select

func (p *DbPool) Select(params ...string) *DbPool

Select 查询select条件入参,入参类似python的args

func (*DbPool) Table

func (p *DbPool) Table(name string) *DbPool

Table 查询数据表获取

func (*DbPool) Tx

func (p *DbPool) Tx(tx *sql.Tx) *DbPool

Tx 设置事务

func (*DbPool) Update

func (p *DbPool) Update(params map[string]interface{}) (affectRows int, err error)

Update 定义更新数据方法,返回影响的行数

func (*DbPool) Where

func (p *DbPool) Where(query interface{}, values ...interface{}) *DbPool

Where 查询where条件入参,入参类似于python的args

type FilesystemInfo

type FilesystemInfo struct {
	Filesystem string `json:"filesystem"`
	Size       string `json:"size"`
	Used       string `json:"used"`
	Available  string `json:"available"`
	Use        string `json:"use"`
	Mount      string `json:"mount"`
}

FilesystemInfo 磁盘挂载信息

type Gosf

type Gosf struct {
	Config    Config
	IsRelease bool
	Logger    *Logger
	WaitGroup sync.WaitGroup
	Task      []func(app *Gosf)
}

func App

func App(config Config) Gosf

App 获取一个新的APP实例 Deprecated: User gosf.NewApp()

func NewApp

func NewApp(config Config) *Gosf

NewApp 获取一个新的APP实例 返回Gosf指针

func (*Gosf) Add

func (app *Gosf) Add(f func(app *Gosf))

Add 添加任务

func (*Gosf) Exit

func (app *Gosf) Exit(v ...any)

Exit 中断程序

func (*Gosf) FmtLog

func (app *Gosf) FmtLog(v ...any)

FmtLog 终端输出,日志也记录

func (*Gosf) Log

func (app *Gosf) Log() *Logger

func (*Gosf) PanicErr

func (app *Gosf) PanicErr(err error, v ...any)

PanicErr 错误处理

func (*Gosf) Run

func (app *Gosf) Run()

Run 执行任务

type Header struct {
	Key   string
	Value string
}

type Logger

type Logger struct {
	// *log.Logger
	Path        string
	MaxSize     int
	DebugLogger *log.Logger
	InfoLogger  *log.Logger
	ErrorLogger *log.Logger
	FatalLogger *log.Logger
}

func (*Logger) Debug

func (logger *Logger) Debug(v ...any)

func (*Logger) Error

func (logger *Logger) Error(v ...any)

func (*Logger) Fatal

func (logger *Logger) Fatal(v ...any)

func (*Logger) GetLogFile

func (logger *Logger) GetLogFile(level string) *os.File

func (*Logger) Info

func (logger *Logger) Info(v ...any)

type Mysql

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

func NewMysql

func NewMysql(config config.Config) *Mysql

NewMysql 单例获取数据库实例,初始化后需要调用关闭数据库连接 defer p.Close()

func (*Mysql) Close added in v1.0.1

func (p *Mysql) Close()

func (*Mysql) DB

func (p *Mysql) DB(name string) *DbPool

DB 单例获取数据库实例,初始化后需要调用关闭数据库连接 defer p.Close()

type Proxy

type Proxy struct {
	Ip       string
	Port     int
	User     string
	Password string
}

type Request

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

Request Manage the HTTP GET request parameters

func NewRequest

func NewRequest() *Request

func (*Request) AddHeader

func (p *Request) AddHeader(key string, value string) *Request

AddHeader

func (*Request) AddParam

func (p *Request) AddParam(property string, value string) *Request

AddParam Add URL escape property and value pair

func (*Request) Body

func (p *Request) Body(body string) *Request

func (*Request) BuildParams

func (p *Request) BuildParams() string

BuildParams Concat the property and value pair

func (*Request) Do

func (p *Request) Do() (error, []byte)

func (*Request) Get

func (p *Request) Get() (error, []byte)

func (*Request) InitFrom

func (p *Request) InitFrom(reqParams *Request) *Request

InitFrom Initialized from another instance

func (*Request) Post

func (p *Request) Post() (error, []byte)

func (*Request) Proxy

func (p *Request) Proxy(proxy Proxy) *Request

func (*Request) Timeout

func (p *Request) Timeout(timeout int) *Request

func (*Request) Url

func (p *Request) Url(url string) *Request

type System

type System struct {
	Cpu        string   `json:"cpu"`
	InternalIp []string `json:"internal_ip"`
	PublicIp   string   `json:"public_ip"`
	Disk       string   `json:"disk"`
	Mac        string   `json:"mac"`
	Now        string   `json:"now"`
}

func NewSystem

func NewSystem() *System

func (*System) GetAvailable

func (p *System) GetAvailable(path string) int

GetAvailable 获取指定目录可用磁盘大小

func (*System) GetCpu

func (p *System) GetCpu() string

func (*System) GetDisk

func (p *System) GetDisk() string

func (*System) GetInternalIPs

func (p *System) GetInternalIPs() []string

GetInternalIPs 获取所有内网IP地址

func (*System) GetIp

func (p *System) GetIp() []string

func (*System) GetMac

func (p *System) GetMac() string

func (*System) GetPublicIP

func (p *System) GetPublicIP() string

type Task

type Task struct {
}

func (*Task) Add

func (t *Task) Add(task func())

Add 添加任务

func (*Task) Run

func (t *Task) Run()

Run 运行

type Upgrade

type Upgrade struct {
	ID       string // 【需要设置】当前服务器标识(根据各自业务而定,可以是自定义的唯一标识,也可以是公网IP、MAC地址等)
	AppPath  string // 【必须设置】APP 所在路劲
	AppName  string // 【必须设置】APP 名称
	CheckUrl string // 【必须设置】最新版本文件MD5
	FileUrl  string // 【必须设置】最新版本文件下载链接
	// contains filtered or unexported fields
}

func NewUpgrade

func NewUpgrade() *Upgrade

func (*Upgrade) Do

func (p *Upgrade) Do()

Do 检测升级

func (*Upgrade) KillApp

func (p *Upgrade) KillApp(app *Gosf) error

KillApp 杀掉原进程【程序启动的时候用来检测是否有残留的进程,建议放init方法里】

func (*Upgrade) Run

func (p *Upgrade) Run()

Run 定时检测升级

Directories

Path Synopsis
package config implements methods for reading config files encoded in json using path expressions and default fallback values thanks to https://github.com/creamdog/gonfig
package config implements methods for reading config files encoded in json using path expressions and default fallback values thanks to https://github.com/creamdog/gonfig

Jump to

Keyboard shortcuts

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