Documentation ¶
Index ¶
- func CheckString(str string) []string
- func Parse(jsonStr string) (*wJson, error)
- func SetRegexpString(regexpStr string)
- func Test()
- type Config
- type Contrast
- type IsPrimaryKeyO
- type IsShowPrintO
- type LinkSQLO
- type MaxLinkNumber
- type MysqlDB
- type Option
- type RetryTimeO
- type SQLConfig
- type Setting
- func (s *Setting) Add(table string, keys []string, values [][]string, Debug *log.Logger, ...) ([]int64, []error)
- func (s *Setting) DecryptID(primaryKey string, ids []string) ([]bool, [][]string, [][]int)
- func (s *Setting) Delete(table string, forKey string, ids []string, Debug *log.Logger, ...) ([]int64, []error)
- func (s *Setting) EncryptPrimaryKey(queryDatas []map[string]string, primaryKey string) []map[string]string
- func (s *Setting) IsRetryConnect(item int) bool
- func (s *Setting) Link(item int) (*MysqlDB, error)
- func (s *Setting) MysqlClose(i int, options ...IsShowPrintO)
- func (s *Setting) MysqlIsRun(item int, options ...LinkSQLO) (int, error)
- func (s *Setting) Query(table string, from string, primaryKey string, where string, order string, ...) ([]map[string]string, []error)
- func (s *Setting) QueryID(table string, from string, primaryKey string, ids []string, order string, ...) ([]map[string]string, []error)
- func (s *Setting) SelectLastID(table string, primaryKey string, Debug *log.Logger, options ...IsShowPrintO) (int, int, error)
- func (s *Setting) Update(table string, key []string, value [][]string, forKey string, ids []string, ...) ([]int64, []error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckString ¶ added in v0.0.5
===============
检查字符串中是否有linux下的非法字符和SQL注入
"
str string "需要检查的字符串" return bool "是否有非法字符"
===============
Check whether there are illegal characters and SQL injection under Linux in the string str string "String to be checked" return bool "Whether there are illegal characters"
func Parse ¶
===============
解析json字符串 jsonStr string "需要解析的json字符串" return 1 *Json "解析后的json对象" return 2 error "解析错误" ============== Parsing JSON strings jsonStr string "json string" return1 *Json "parsed json object" return2 error "parsing error"
func SetRegexpString ¶ added in v0.0.5
func SetRegexpString(regexpStr string)
===============
设置正则表达式 regexpStr string "正则表达式 空字符串时修改为默认值"
===============
Set regular expression regexpStr string "Regular expression When the string is empty, it is default"
Types ¶
type Config ¶
type Config struct { MysqlName string `json:"mysql_name"` Mysql []SQLConfig `json:"mysql"` MaxLink MaxLinkNumber `json:"MaxLinkNumber"` Contrast Contrast `json:"contrast"` }
type IsPrimaryKeyO ¶ added in v0.0.4
type IsPrimaryKeyO func(*Option)
是否为主键的可选配置
Optional configuration for whether it is a primary key
func OIPKIsPrimaryKey ¶ added in v0.0.4
func OIPKIsPrimaryKey(IsPrimaryKey bool) IsPrimaryKeyO
===============
设置是否为主键 IsPrimaryKey bool "是否为主键"
===============
Set whether it is a primary key IsPrimaryKey bool "Whether it is a primary key"
func OIPKIsShowPrint ¶ added in v0.0.4
func OIPKIsShowPrint(IsShowPrint bool) IsPrimaryKeyO
===============
是否输出到控制台 IsShowPrint bool "是否输出到控制台"
===============
Whether to output to the console IsShowPrint bool "Whether to output to the console"
type IsShowPrintO ¶ added in v0.0.4
type IsShowPrintO func(*Option)
是否输出到控制台
Whether to output to the console
func OIsShowPrint ¶ added in v0.0.4
func OIsShowPrint(IsShowPrint bool) IsShowPrintO
===============
是否输出到控制台 IsShowPrint bool "是否输出到控制台"
===============
Whether to output to the console IsShowPrint bool "Whether to output to the console"
type LinkSQLO ¶ added in v0.0.4
type LinkSQLO func(*Option)
连接MySQL时的可选配置
Optional configuration when connecting to MySQL
func OLIsShowPrint ¶ added in v0.0.4
===============
设置是输出到控制台 IsShowPrint bool "是否输出到控制台"
===============
Set whether to output to the console IsShowPrint bool "Whether to output to the console"
func OLWaitCount ¶ added in v0.0.4
===============
设置等待次数 WaitCount int "等待次数"
===============
Set the number of waits WaitCount int "Number of waits"
func OLWaitTime ¶ added in v0.0.4
===============
设置每次等待时间,单位毫秒 WaitTime int "每次等待时间,单位毫秒"
===============
Set the waiting time per time, in milliseconds WaitTime int "Waiting time per time, in milliseconds"
type MaxLinkNumber ¶
type MysqlDB ¶
type MysqlDB struct { // 数据库名 // // Database name Name string // 当前连接的数据库在配置中的位置 // // The location of the currently connected database in the configuration DBItem int // 数据库连接 // // Database connection DB *sql.DB }
func (*MysqlDB) Close ¶
func (db *MysqlDB) Close()
===============
关闭数据库
===============
Close database
func (*MysqlDB) ExecCMD ¶
func (s *MysqlDB) ExecCMD(sqlStr string, Debug *log.Logger, options ...IsShowPrintO) (int64, int64, error)
===============
根据 *Setting 从数据库集中调用单行SQL指令 sqlStr string "SQL指令" Debug *log.Logger "调试输出" options []IsShowPrintO "配置" IsShowPrint bool "是否输出到控制台" return 1 int64 "插入的行数" return 2 int64 "影响的行数" return 3 []error "错误信息"
===============
According to *Setting, call single row SQL instruction from database set sqlStr string "SQL instruction" Debug *log.Logger "Debug output" options []IsShowPrintO "Configuration" isShowPrint bool "Whether to output to the console" return 1 int64 "Number of rows inserted" return 2 int64 "Number of rows affected" return 3 []error "Error message"
func (*MysqlDB) QueryCMD ¶
func (s *MysqlDB) QueryCMD(sqlStr string, Debug *log.Logger, options ...IsShowPrintO) ([]map[string]string, error)
===============
根据 *Setting 从数据库集中调用单行SQL查询指令 sqlStr string "SQL指令" Debug *log.Logger "调试输出" options []IsShowPrintO "配置" IsShowPrint bool "是否输出到控制台" return 1 []map[string]string "查询结果" return 2 []error "错误信息"
===============
According to *Setting, call single row SQL query instruction from database set sqlStr string "SQL instruction" Debug *log.Logger "Debug output" options []IsShowPrintO "Configuration" IsShowPrint bool "Whether to output to the console" return 1 []map[string]string "Query result" return 2 []error "Error message"
type Option ¶
type Option struct { // 等待次数 // // Number of waits WaitCount int // 每次等待时间,单位毫秒 // // Waiting time per time, in milliseconds WaitTime int // 是否为主键 // // Whether it is a primary key IsPrimaryKey bool // 重试时间 // // Retry time RetryTime int // 是否输出到控制台 // // Whether to output to the console IsShowPrint bool }
type RetryTimeO ¶ added in v0.0.4
type RetryTimeO func(*Option)
重试时间的可选配置
Optional configuration of retry time
func OptionRetryTime ¶ added in v0.0.3
func OptionRetryTime(RetryTime int) RetryTimeO
===============
设置重试时间 RetryTime int "重试等待时间(ms)"
===============
Set retry time RetryTime int "Retry wait time(ms)"
type SQLConfig ¶
type SQLConfig struct { User string `json:"mysql_user"` Password string `json:"mysql_pwd"` Address string `json:"mysql_addr"` Port string `json:"mysql_port"` DB string `json:"mysql_db"` }
func GetSQLConfig ¶
===============
从json字符串中解析MySQL配置 config string "需要解析的json字符串" return 1 *SQLConfig "解析后的MySQL配置对象" return 2 error "解析错误" ============== Parse MySQL configuration from json string config string "json string" return 1 *SQLConfig "parsed MySQL configuration object" return 2 error "parsing error"
func GetSQLConfigMap ¶
===============
从字典中解析MySQL配置 configMap map[string]interface{} "需要解析的字典" return 1 *SQLConfig "解析后的MySQL配置对象" ============== Parse MySQL configuration from dictionary configMap map[string]interface{} "dictionary" return 1 *SQLConfig "parsed MySQL configuration object"
type Setting ¶
type Setting struct { // 数据库配置 // // Database configuration SqlConfigs []SQLConfig // 数据库名 // // Database name DBName string // 下一个数据库ID号,起始为1 // // Next database ID number, starting at 1 NextDBID int // 数据库最大数目 // // Maximum number of databases DBMaxNum int // 连接数目 // // Number of connections LinkNum int // 最大连接数目 // // Maximum number of connections MaxLink int // 数据库连接 // // Database connection MySQLDB []*MysqlDB // 加密对象 // // Encryption object SEKey *simpleEncryption.SecretKey // 重新连接数据库的时间间隔 // // Time interval for reconnecting to the database ConnectAgainTime int // 上次连接失败的时间, 用于判断是否需要重新连接 // // The last time the connection failed, used to determine whether to reconnect ConnectFailTime []*time.Time }
func New ¶
func New(configString string, options ...RetryTimeO) (*Setting, error)
===============
数据库配置 configString string "配置文件字符串" options []RetryTimeO "配置" RetryTime int "重试时间(ms)" return 1 *Setting "数据库配置对象" return 2 error "错误信息"
===============
Database config configString string "Configuration file string" options []RetryTimeO "Configuration" RetryTime int "Retry time(ms)" return 1 *Setting "Database configuration object" return 2 error "Error message"
func (*Setting) Add ¶
func (s *Setting) Add(table string, keys []string, values [][]string, Debug *log.Logger, options ...IsShowPrintO) ([]int64, []error)
===============
自动根据 *Setting 向下一个数据库中的指定表添加数据 table string "表名" keys []string "键名" values [][]string "值" Debug *log.Logger "调试输出" options []IsShowPrintO "配置" IsShowPrint bool "是否输出到控制台" return 1 []int64 "插入的行数" return 2 []error "错误信息"
===============
Automatically add data to the specified table in the next database according to *Setting table string "table name" keys []string "key name" values [][]string "value" Debug *log.Logger "debug output" options []IsShowPrintO "Configuration" IsShowPrint bool "Whether to output to the console" return 1 []int64 "Number of rows inserted" return 2 []error "Error message"
func (*Setting) DecryptID ¶
===============
根据主键和id数组解密出数据库ID和主键ID primaryKey string "主键字段名" ids []string "主键ID数组" return 1 []bool "解密出的ID是否有对应的数据库" return 2 [][]string "解密出的数据库ID" return 3 [][]int "解密出的主键ID在原数组中的位置"
===============
Decrypt the database ID and primary key ID based on the primary key and ID array primaryKey string "primary key field name" ids []string "primary key ID array" return 1 []bool "Whether the decrypted ID has a corresponding database" return 2 [][]string "Decrypted database ID" return 3 [][]int "The position of the decrypted primary key ID in the original array"
func (*Setting) Delete ¶
func (s *Setting) Delete(table string, forKey string, ids []string, Debug *log.Logger, options ...IsPrimaryKeyO) ([]int64, []error)
===============
自动根据 *Setting 向下一个数据库中的指定表删除数据 table string "表名" forKey string "键名" ids []string "值" Debug *log.Logger "调试输出" options []IsPrimaryKeyO "配置" IsPrimaryKey bool "是否为主键" IsShowPrint bool "是否输出到控制台" return 1 []int64 "删除的行数" return 2 []error "错误信息"
===============
Automatically delete data from the specified table in the next database according to *Setting table string "table name" forKey string "key name" ids []string "value" Debug *log.Logger "debug output" options []IsPrimaryKeyO "Configuration" IsPrimaryKey bool "Whether it is a primary key" IsShowPrint bool "Whether to output to the console" return 1 []int64 "Number of rows deleted" return 2 []error "Error message"
func (*Setting) EncryptPrimaryKey ¶
func (s *Setting) EncryptPrimaryKey(queryDatas []map[string]string, primaryKey string) []map[string]string
===============
加密主键, *Setting.SEKey 为 nil 时不加密 queryDatas []map[string]string "查询结果" primaryKey string "主键字段名 为空字符串时不加密" return []map[string]string "查询结果"
===============
Encrypt primary key, *Setting.SEKey is not encrypted when nil queryDatas []map[string]string "query result" primaryKey string "primary key field name When it is an empty string, it is not encrypted" return []map[string]string query result
func (*Setting) IsRetryConnect ¶ added in v0.0.3
===============
判断是否可以连接数据库 item int "需要连接的数据库在配置中的位置" return 1 bool "是否可以尝试连接"
===============
Determine whether the database can be connected item int "Location of the database to be connected in the configuration" return 1 bool "Whether to try to connect"
func (*Setting) Link ¶
===============
连接数据库 item int "需要连接的数据库在配置中的位置" return 1 *MysqlDB "连接池中的位置" return 2 error "错误信息"
===============
Connect to MySQL database item int "Location of the database to be connected in the configuration" return 1 *MysqlDB "Location in the connection pool" return 2 error "Error message"
func (*Setting) MysqlClose ¶
func (s *Setting) MysqlClose(i int, options ...IsShowPrintO)
===============
关闭MySQL连接 i int "连接池中的位置"
===============
Close MySQL connection i int "Position in the connection pool"
func (*Setting) MysqlIsRun ¶
===============
连接MySQL数据库并放入连接池 item int "配置文件中的第几个MySQL配置" options []LinkSQLO "配置" WaitCount int "等待次数" WaitTime int "每次等待时间,单位毫秒" return 1 int "连接池中的位置" return 2 error "错误信息"
===============
Connect to MySQL database and put it into Connection pool item int "Which MySQL configuration in the configuration file" options []LinkSQLO "Configuration" WaitCount int "Number of waits" WaitTime int "Waiting time per time, in milliseconds" return 1 int "Position in the connection pool" return 2 error "Error message"
func (*Setting) Query ¶
func (s *Setting) Query(table string, from string, primaryKey string, where string, order string, limit string, Debug *log.Logger, options ...IsShowPrintO) ([]map[string]string, []error)
===============
根据 *Setting 从数据库集中查询 table string "表名" from string "查询字段 空字符串为默认值 *" primaryKey string "主键 空字符串时不加密" where string "查询条件" order string "排序" limit string "分页 空字符串为默认值:100" Debug *log.Logger "调试日志对象" options []IsShowPrintO "配置" IsShowPrint bool "是否输出到控制台" return 1 []map[string]string "查询结果" return 2 []error "错误信息"
===============
According to *Setting, query from the database set table string "Table name" from string "Query field Empty string is the default value *" primaryKey string "Primary key Empty string is not encrypted" where string "Query condition" order string "Sorting" limit string "Paging Empty string is the default value: 100" Debug *log.Logger "Debug log object" options []IsShowPrintO "Configuration" IsShowPrint bool "Whether to output to the console" return 1 []map[string]string "Query result" return 2 []error "Error message"
func (*Setting) QueryID ¶
func (s *Setting) QueryID(table string, from string, primaryKey string, ids []string, order string, Debug *log.Logger, options ...IsShowPrintO) ([]map[string]string, []error)
===============
自动根据 *Setting 从数据库集中,根据加密后的主键查询 table string "表名" from string "查询的字段" primaryKey string "主键" ids []string "加密后的主键" order string "排序" Debug *log.Logger "调试输出" options []IsShowPrintO "配置" IsShowPrint bool "是否输出到控制台" return 1 []map[string]string "查询到的数据" return 2 []error "错误信息"
===============
Automatically query from the database set according to *Setting, according to the encrypted primary key table string "table name" from string "query field" primaryKey string "primary key" ids []string "encrypted primary key" order string "sort" Debug *log.Logger "debug output" options []IsShowPrintO "Configuration" IsShowPrint bool "Whether to output to the console" return 1 []map[string]string "query data" return 2 []error "error message"
func (*Setting) SelectLastID ¶
func (s *Setting) SelectLastID(table string, primaryKey string, Debug *log.Logger, options ...IsShowPrintO) (int, int, error)
===============
根据 *Setting 从数据库集中查询指定表的最后一条数据的 ID table string "表名" primaryKey string "主键名,主键类型必须为数字类型" Debug *log.Logger "Debug 日志对象" options []IsShowPrintO "配置" IsShowPrint bool "是否输出到控制台" return 1 int "下一条数据所在的数据库索引" return 2 int "下一条数据的 ID" return 3 error "错误信息"
===============
According to *Setting, query the ID of the last data of the specified table from the database set table string "table name" primaryKey string "primary key name,The primary key type must be a numeric type" Debug *log.Logger "Debug log object" options []IsShowPrintO "Configuration" IsShowPrint bool "Whether to output to the console" return 1 int "The database index where the next data is located" return 2 int "ID of the next data" return 3 error "Error message"
func (*Setting) Update ¶
func (s *Setting) Update(table string, key []string, value [][]string, forKey string, ids []string, Debug *log.Logger, options ...IsPrimaryKeyO) ([]int64, []error)
===============
更新数据 table string "表名" key []string "字段名" value [][]string "值" forKey string "加密用的key" ids []string "主键" Debug *log.Logger "调试输出" options []UpdateOptionConfig "配置" IsPrimaryKey bool "是否使用主键" IsShowPrint bool "是否输出到控制台" return 1 []int64 "更新的行数" return 2 error "错误信息"
===============
Update data table string "Table name" key []string "Field name" value [][]string "Value" forKey string "Encryption key" ids []string "Primary key" Debug *log.Logger "Debug output" options []UpdateOptionConfig "Configuration" IsPrimaryKey bool "Whether to use the primary key" IsShowPrint bool "Whether to output to the console" return 1 []int64 "Number of rows updated" return 2 error "Error message"