Apply .gitignore rules

This commit is contained in:
皮蛋13361098506
2025-01-06 16:21:36 +08:00
parent 1b77f62820
commit ccd2c530cf
580 changed files with 69806 additions and 0 deletions

View File

@@ -0,0 +1,122 @@
package webServer
import (
config "common/configsYaml"
"common/resultStatus"
"common/utils"
"encoding/json"
"fmt"
"framework/ipMgr"
"goutil/logUtilPlus"
"goutil/stringUtil"
"goutil/webUtil"
"net/http"
"strings"
)
// selfDefineMux
//
// @description: 定义自定义的Mux对象
type selfDefineMux struct {
}
// ServeHTTP
//
// @description: ServeHTTP
//
// parameter:
//
// @receiver mux: mux
// @w: w
// @r: r
//
// return:
func (mux *selfDefineMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
responseObj := GetInitResponseObj()
defer utils.LogReqErrorRecover(r)
// 判断是否是接口文档
if strings.Contains(r.RequestURI, "Remarks") && r.Method == "GET" {
remarkFunc(w, r)
return
}
// 判断是否是POST方法
if r.Method != "POST" {
responseResult(w, responseObj.SetResultStatus(resultStatus.OnlySupportPOST))
return
}
// 验证IP是否正确
if config.DEBUG == false && ipMgr.IsIpValid(webUtil.GetRequestIP(r)) == false {
logUtilPlus.ErrorLog(fmt.Sprintf("请求的IP%s无效", webUtil.GetRequestIP(r)))
responseResult(w, responseObj.SetResultStatus(resultStatus.IPForbid))
return
}
// 构造contex
context, errMsg := NewApiContext(r, w, false)
if errMsg != nil {
// 输出结果
responseResult(w, responseObj.SetResultStatus(resultStatus.APIDataError))
return
}
// 根据路径选择不同的处理方法
if handlerFunObj, exists := GetHandleFunc(r.RequestURI); exists {
defer func() {
if config.DEBUG {
b, _ := json.Marshal(responseObj)
msg := fmt.Sprintf("API:%v 请求数据:%v;返回数据:%s;",
r.RequestURI, string(context.GetRequestBytes()), string(b))
logUtilPlus.DebugLog(msg)
}
}()
// 输出结果
responseObj := handlerFunObj.HandleFun()(context)
responseResult(w, responseObj)
return
}
// 通过反射选择不同的方法
strs := stringUtil.Split(r.RequestURI, []string{"/"})
var params []interface{}
var err error
isJson := false
// 参数错误
if len(strs) != 2 {
responseResult(w, responseObj.SetResultStatus(resultStatus.APIDataError))
return
}
//验证是否登录
if strs[0] != "AdminApi" || strs[1] != "Login" {
tokenStr := context.header.Get("token")
// token 转型成 int64
token := stringUtil.StringToInt64(tokenStr)
//是否存在
if !CheckToken(token) {
responseResult(w, responseObj.SetResultStatus(resultStatus.NotLogin))
return
}
}
params, err = context.RequestDataBySlice2ByJson()
if err != nil {
responseResult(w, responseObj.SetResultStatus(resultStatus.APIDataError))
return
}
resquestData := NewRequestObject(strs[0], strs[1], params)
resp := CallFunction(resquestData)
if isJson {
responseResultByJson(w, resp)
} else {
responseResult(w, resp)
}
}

View File

@@ -0,0 +1,48 @@
package remark
// ModuleRemark
// @description: 模块说明对象
type ModuleRemark struct {
// 模块名称
Name string
// 模块描述
Desc string
// 接口作者
Author string
// 修改者
Mendor string
// 接口设计日期
Date string
// 方法对象列表
MethodRemarkSlice []*MethodRemark
}
// newModuleRemark
// @description: 创建新的模块说明对象
// parameter:
// @name: 模块名称
// @desc: 模块描述
// @author: 模块作者
// @mendor: 模块修改者(多个用,分隔)
// @date: 创建日期
// return:
// @*ModuleRemark: 新的模块说明对象
func newModuleRemark(name, desc, author, mendor, date string) *ModuleRemark {
if mendor == "" {
mendor = "无"
}
return &ModuleRemark{
Name: name,
Desc: desc,
Author: author,
Mendor: mendor,
Date: date,
MethodRemarkSlice: make([]*MethodRemark, 0, 16),
}
}

View File

@@ -0,0 +1,25 @@
package xpath
// A Node is an element node that can navigating to
// an node attribute and another node.
//type Node interface{}
// A type of XPath node.
type NodeType int
const (
// A root node of the XML document or node tree.
RootNode NodeType = iota
// An element, such as <element>.
ElementNode
// An attribute, such as id='123'.
AttributeNode
// The text content of a node.
TextNode
// A comment node, such as <!-- my comment -->
CommentNode
)

View File

@@ -0,0 +1,195 @@
package dbUtil
import (
"fmt"
"time"
"goutil/typeUtil"
)
// 类型转换为byte
// 返回值:
// byte:结果
// error:错误数据
func Byte(row *DataRow, key string) (byte, error) {
val, errMsg := row.CellValueByName(key)
if errMsg != nil {
return 0, errMsg
}
if val == nil {
return 0, fmt.Errorf("value is nil")
}
return typeUtil.Byte(val)
}
// 类型转换为int
// 返回值:
// int:结果
// error:错误数据
func Int32(row *DataRow, key string) (int32, error) {
val, errMsg := row.CellValueByName(key)
if errMsg != nil {
return 0, errMsg
}
if val == nil {
return 0, fmt.Errorf("value is nil")
}
return typeUtil.Int32(val)
}
// 类型转换为uint32
// 返回值:
// int:结果
// error:错误数据
func Uint32(row *DataRow, key string) (uint32, error) {
val, errMsg := row.CellValueByName(key)
if errMsg != nil {
return 0, errMsg
}
if val == nil {
return 0, fmt.Errorf("value is nil")
}
return typeUtil.Uint32(val)
}
// 类型转换为int
// 返回值:
// int:结果
// error:错误数据
func Int(row *DataRow, key string) (int, error) {
val, errMsg := row.CellValueByName(key)
if errMsg != nil {
return 0, errMsg
}
if val == nil {
return 0, fmt.Errorf("value is nil")
}
return typeUtil.Int(val)
}
// 类型转换为int
// 返回值:
// int:结果
// error:错误数据
func Uint(row *DataRow, key string) (uint, error) {
val, errMsg := row.CellValueByName(key)
if errMsg != nil {
return 0, errMsg
}
if val == nil {
return 0, fmt.Errorf("value is nil")
}
return typeUtil.Uint(val)
}
// 类型转换为int
// 返回值:
// int:结果
// error:错误数据
func Int64(row *DataRow, key string) (int64, error) {
val, errMsg := row.CellValueByName(key)
if errMsg != nil {
return 0, errMsg
}
if val == nil {
return 0, fmt.Errorf("value is nil")
}
return typeUtil.Int64(val)
}
// 类型转换为int
// 返回值:
// int:结果
// error:错误数据
func Uint64(row *DataRow, key string) (uint64, error) {
val, errMsg := row.CellValueByName(key)
if errMsg != nil {
return 0, errMsg
}
if val == nil {
return 0, fmt.Errorf("value is nil")
}
return typeUtil.Uint64(val)
}
// 类型转换为int
// 返回值:
// float64:结果
// error:错误数据
func Float64(row *DataRow, key string) (float64, error) {
val, errMsg := row.CellValueByName(key)
if errMsg != nil {
return 0, errMsg
}
if val == nil {
return 0, fmt.Errorf("value is nil")
}
return typeUtil.Float64(val)
}
// 类型转换为bool
// 返回值:
// bool:结果
// error:错误信息
func Bool(row *DataRow, key string) (bool, error) {
val, errMsg := row.CellValueByName(key)
if errMsg != nil {
return false, errMsg
}
if val == nil {
return false, fmt.Errorf("value is nil")
}
return typeUtil.Bool(val)
}
// 类型转换为字符串
// 返回值:
// string:结果
// error:错误信息
func String(row *DataRow, key string) (string, error) {
val, errMsg := row.CellValueByName(key)
if errMsg != nil {
return "", errMsg
}
if val == nil {
return "", fmt.Errorf("value is nil")
}
return typeUtil.String(val)
}
// 转换为时间格式如果是字符串则要求内容格式形如2017-02-14 05:20:00
// 返回值:
// bool:结果
// error:错误信息
func DateTime(row *DataRow, key string) (time.Time, error) {
val, errMsg := row.CellValueByName(key)
if errMsg != nil {
return time.Time{}, errMsg
}
if val == nil {
return time.Time{}, fmt.Errorf("value is nil")
}
return typeUtil.DateTime(val)
}

View File

@@ -0,0 +1,189 @@
package dbUtil
import (
"database/sql"
"errors"
)
// 数据表结构
type DataTable struct {
// 行对象集合
rowData []*DataRow
// 列名称集合
columnNames map[string]int
}
// 数据表初始化
// rows:原始的数据行信息
// 返回值:
// error:初始化的错误信息
func (this *DataTable) init(rows *sql.Rows) error {
defer func() {
rows.Close()
}()
// 读取列信息和保存列名称
tmpColumns, errMsg := rows.Columns()
if errMsg != nil {
return errMsg
}
this.columnNames = make(map[string]int)
for index, val := range tmpColumns {
this.columnNames[val] = index
}
// 读取行数据
this.rowData = make([]*DataRow, 0)
columnCount := len(this.columnNames)
args := make([]interface{}, columnCount)
for rows.Next() {
values := make([]interface{}, columnCount)
for i := 0; i < columnCount; i++ {
args[i] = &values[i]
}
rows.Scan(args...)
this.rowData = append(this.rowData, newDataRow(this, values))
}
return nil
}
// 获取原始单元格值(一般为:string或[]byte
// rowIndex:行序号
// cellIndex:单元格序号
// 返回值:
// interface{}:原始单元格值(一般为:string或[]byte
// error:获取错误信息
func (this *DataTable) OriginCellValueByIndex(rowIndex int, cellIndex int) (interface{}, error) {
if len(this.rowData) <= rowIndex {
return nil, errors.New("row out of range")
}
rowItem := this.rowData[rowIndex]
if len(rowItem.cells) <= cellIndex {
return nil, errors.New("column out of range")
}
return rowItem.OriginCellValue(cellIndex)
}
// 获取原始单元格值(一般为:string或[]byte
// rowIndex:行序号
// cellIndex:单元格序号
// 返回值:
// interface{}:原始单元格值(一般为:string或[]byte
// error:获取错误信息
func (this *DataTable) OriginCellValueByCellName(rowIndex int, cellName string) (interface{}, error) {
if len(this.rowData) <= rowIndex {
return nil, errors.New("row out of range")
}
rowItem := this.rowData[rowIndex]
return rowItem.OriginCellValueByName(cellName)
}
// 获取字符串的单元格值有可能为nil
// rowIndex:行序号
// cellIndex:单元格序号
// 返回值:
// interface{}:字符串的单元格值有可能为nil
// error:获取错误信息
func (this *DataTable) CellValueByIndex(rowIndex int, cellIndex int) (interface{}, error) {
if len(this.rowData) <= rowIndex {
return nil, errors.New("row out of range")
}
rowItem := this.rowData[rowIndex]
if len(rowItem.cells) <= cellIndex {
return nil, errors.New("column out of range")
}
return rowItem.CellValue(cellIndex)
}
// 获取字符串的单元格值有可能为nil
// rowIndex:行序号
// cellIndex:单元格序号
// 返回值:
// interface{}:字符串的单元格值有可能为nil
// error:获取错误信息
func (this *DataTable) CellValueByName(rowIndex int, cellName string) (interface{}, error) {
if len(this.rowData) <= rowIndex {
return nil, errors.New("row out of range")
}
rowItem := this.rowData[rowIndex]
return rowItem.CellValueByName(cellName)
}
// 获取行对象
// rowIndex:行序号
// 返回值:
// *DataRow:行对象
// error:错误信息
func (this *DataTable) Row(rowIndex int) (*DataRow, error) {
if len(this.rowData) <= rowIndex {
return nil, errors.New("row out of range")
}
return this.rowData[rowIndex], nil
}
// 根据列名获取列序号
// cellName:列名
// 返回值:
// int:列序号
func (this *DataTable) cellIndex(cellName string) int {
cellIndex, isExist := this.columnNames[cellName]
if isExist == false {
return -1
}
return cellIndex
}
// 获取所有列的名字
// 返回值:
// []string:列字段名集合
func (this *DataTable) Columns() []string {
result := make([]string, len(this.columnNames))
for key, val := range this.columnNames {
result[val] = key
}
return result
}
// 获取列数量
// 返回值:
// int:列数量
func (this *DataTable) ColumnCount() int {
return len(this.columnNames)
}
// 获取数据行数
// 返回值:
// int:行数
func (this *DataTable) RowCount() int {
return len(this.rowData)
}
// 新建数据表对象
// rows:数据行对象
// 返回值:
// *DataTable:数据表对象
// error:错误信息
func NewDataTable(rows *sql.Rows) (*DataTable, error) {
table := &DataTable{}
errMsg := table.init(rows)
if errMsg != nil {
return nil, errMsg
}
return table, nil
}