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,153 @@
package xmlUtil
import (
"strings"
"testing"
)
var doc = loadXml()
func TestXPath(t *testing.T) {
if list := Find(doc, "//book"); len(list) != 12 {
t.Fatal("count(//book) != 12")
}
if node := FindOne(doc, "//book[@id='bk101']"); node == nil {
t.Fatal("//book[@id='bk101] is not found")
}
if node := FindOne(doc, "//book[price>=44.95]"); node == nil {
t.Fatal("//book/price>=44.95 is not found")
}
if list := Find(doc, "//book[genre='Fantasy']"); len(list) != 4 {
t.Fatal("//book[genre='Fantasy'] items count is not equal 4")
}
}
func loadXml() *Node {
// https://msdn.microsoft.com/en-us/library/ms762271(v=vs.85).aspx
s := `
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
<book id="bk104">
<author>Corets, Eva</author>
<title>Oberon's Legacy</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-03-10</publish_date>
<description>In post-apocalypse England, the mysterious
agent known only as Oberon helps to create a new life
for the inhabitants of London. Sequel to Maeve
Ascendant.</description>
</book>
<book id="bk105">
<author>Corets, Eva</author>
<title>The Sundered Grail</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-09-10</publish_date>
<description>The two daughters of Maeve, half-sisters,
battle one another for control of England. Sequel to
Oberon's Legacy.</description>
</book>
<book id="bk106">
<author>Randall, Cynthia</author>
<title>Lover Birds</title>
<genre>Romance</genre>
<price>4.95</price>
<publish_date>2000-09-02</publish_date>
<description>When Carla meets Paul at an ornithology
conference, tempers fly as feathers get ruffled.</description>
</book>
<book id="bk107">
<author>Thurman, Paula</author>
<title>Splish Splash</title>
<genre>Romance</genre>
<price>4.95</price>
<publish_date>2000-11-02</publish_date>
<description>A deep sea diver finds true love twenty
thousand leagues beneath the sea.</description>
</book>
<book id="bk108">
<author>Knorr, Stefan</author>
<title>Creepy Crawlies</title>
<genre>Horror</genre>
<price>4.95</price>
<publish_date>2000-12-06</publish_date>
<description>An anthology of horror stories about roaches,
centipedes, scorpions and other insects.</description>
</book>
<book id="bk109">
<author>Kress, Peter</author>
<title>Paradox Lost</title>
<genre>Science Fiction</genre>
<price>6.95</price>
<publish_date>2000-11-02</publish_date>
<description>After an inadvertant trip through a Heisenberg
Uncertainty Device, James Salway discovers the problems
of being quantum.</description>
</book>
<book id="bk110">
<author>O'Brien, Tim</author>
<title>Microsoft .NET: The Programming Bible</title>
<genre>Computer</genre>
<price>36.95</price>
<publish_date>2000-12-09</publish_date>
<description>Microsoft's .NET initiative is explored in
detail in this deep programmer's reference.</description>
</book>
<book id="bk111">
<author>O'Brien, Tim</author>
<title>MSXML3: A Comprehensive Guide</title>
<genre>Computer</genre>
<price>36.95</price>
<publish_date>2000-12-01</publish_date>
<description>The Microsoft MSXML3 parser is covered in
detail, with attention to XML DOM interfaces, XSLT processing,
SAX and more.</description>
</book>
<book id="bk112">
<author>Galos, Mike</author>
<title>Visual Studio 7: A Comprehensive Guide</title>
<genre>Computer</genre>
<price>49.95</price>
<publish_date>2001-04-16</publish_date>
<description>Microsoft Visual Studio 7 is explored in depth,
looking at how Visual Basic, Visual C++, C#, and ASP+ are
integrated into a comprehensive development
environment.</description>
</book>
</catalog>`
node, err := LoadFromReader(strings.NewReader(s))
if err != nil {
panic(err)
}
return node
}

View File

@@ -0,0 +1,104 @@
package dbUtil
import (
"errors"
"time"
)
// 数据行结果
type DataRow struct {
// 所属数据表
table *DataTable
// 行的所有值
cells []interface{}
}
// 行的所有原始值
func (this *DataRow) CellOriginValues() []interface{} {
return this.cells
}
// 值的个数
func (this *DataRow) Len() int {
return len(this.cells)
}
// 单元格的字符串值可能为nil,如果有设置连接字符串parseTime=true则会有time.Time
// celIndex:单元格序号
// 返回值:
// interface{}:单元格的字符串值
// error:错误信息
func (this *DataRow) CellValue(celIndex int) (interface{}, error) {
if len(this.cells) <= celIndex {
return nil, errors.New("cell out of range")
}
// 检查是否为nil
if this.cells[celIndex] == nil {
return nil, nil
}
// 转换为字符串
switch this.cells[celIndex].(type) {
case []byte:
return string(this.cells[celIndex].([]byte)), nil
case string:
return this.cells[celIndex].(string), nil
case time.Time:
return this.cells[celIndex].(time.Time), nil
}
return nil, errors.New("unknown value type")
}
// 单元格的字符串值可能为nil,如果有设置连接字符串parseTime=true则会有time.Time
// cellName:单元格名称
// 返回值:
// interface{}:单元格的字符串值
// error:错误信息
func (this *DataRow) CellValueByName(cellName string) (interface{}, error) {
celIndex := this.table.cellIndex(cellName)
if celIndex < 0 {
return nil, errors.New("cell name no exist")
}
return this.CellValue(celIndex)
}
// 单元格的原始值
// celIndex:单元格序号
// 返回值:
// interface{}:单元格的字符串值
// error:错误信息
func (this *DataRow) OriginCellValue(celIndex int) (interface{}, error) {
if len(this.cells) <= celIndex {
return nil, errors.New("cell out of range")
}
return this.cells[celIndex], nil
}
// 单元格的原始值
// cellName:单元格名称
// 返回值:
// interface{}:单元格的字符串值
// error:错误信息
func (this *DataRow) OriginCellValueByName(cellName string) (interface{}, error) {
celIndex := this.table.cellIndex(cellName)
if celIndex < 0 {
return nil, errors.New("cell name no exist")
}
return this.OriginCellValue(celIndex)
}
// 创建单元格对象
// _table:所属表对象
// _cells:单元格的值集合
func newDataRow(_table *DataTable, _cells []interface{}) *DataRow {
return &DataRow{
table: _table,
cells: _cells,
}
}

View File

@@ -0,0 +1,345 @@
package fileUtil
import (
"bufio"
"fmt"
"io"
"os"
"path/filepath"
"runtime"
"testing"
"time"
)
func BenchmarkWriteFile(b *testing.B) {
path := GetCurrentPath()
fmt.Printf("CurrPath:%s\n", path)
for i := 0; i < b.N; i++ {
WriteFile(path, "test.txt", true, fmt.Sprintf("line %d", i))
}
}
func TestIsFileExists(t *testing.T) {
path := GetCurrentPath()
fmt.Printf("CurrPath:%s\n", path)
fileName := fmt.Sprintf("%s/%s", path, "test.txt")
fmt.Printf("FileName:%s\n", fileName)
if exists, err := IsFileExists(fileName); err != nil || exists {
t.Errorf("the file %s should not be exists, but now it's exists", fileName)
}
if err := WriteFile(path, "test.txt", true, "first line"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
if exists, err := IsFileExists(fileName); err != nil || !exists {
t.Errorf("the file %s should be exists, but now it's not exists", fileName)
}
if content, err := ReadFileContent(fileName); err != nil {
t.Errorf("there should be no error, but now err:%s", err)
} else {
fmt.Printf("Content:%s\n", content)
}
DeleteFile(fileName)
}
func TestIsDirectoryExists(t *testing.T) {
path := GetCurrentPath()
fmt.Printf("CurrPath:%s\n", path)
filePath := filepath.Join(path, "Parent")
if exists, err := IsDirectoryExists(filePath); err != nil || exists {
t.Errorf("the file %s should not be exists, but now it's exists", filePath)
}
fileName := fmt.Sprintf("%s/%s", filePath, "test.txt")
if err := WriteFile(filePath, "test.txt", true, "first line"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
if exists, err := IsDirectoryExists(filePath); err != nil || !exists {
t.Errorf("the file %s should be exists, but now it's not exists", filePath)
}
if content, err := ReadFileContent(fileName); err != nil {
t.Errorf("there should be no error, but now err:%s", err)
} else {
fmt.Printf("Content:%s\n", content)
}
DeleteFile(fileName)
}
func TestIsDirExists(t *testing.T) {
path := GetCurrentPath()
fmt.Printf("CurrPath:%s\n", path)
filePath := filepath.Join(path, "Parent2")
if IsDirExists(filePath) {
t.Errorf("the file %s should not be exists, but now it's exists", filePath)
}
fileName := fmt.Sprintf("%s/%s", filePath, "test.txt")
if err := WriteFile(filePath, "test.txt", true, "first line"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
if IsDirExists(filePath) == false {
t.Errorf("the file %s should be exists, but now it's not exists", filePath)
}
if content, err := ReadFileContent(fmt.Sprintf("%s/%s", filePath, "test.txt")); err != nil {
t.Errorf("there should be no error, but now err:%s", err)
} else {
fmt.Printf("Content:%s\n", content)
}
DeleteFile(fileName)
}
func TestGetFileList(t *testing.T) {
path := GetCurrentPath()
fmt.Printf("CurrPath:%s\n", path)
fileName1 := "2017-09-12-12.txt"
fileName2 := "2017-09-12-13.txt"
fileName3 := "2017-09-12-14.txt"
fileName4 := "2017-09-12.tar.bz2"
seperator := "\\"
if runtime.GOOS != "windows" {
seperator = "/"
}
filePath1 := fmt.Sprintf("%s%s%s", path, seperator, fileName1)
filePath2 := fmt.Sprintf("%s%s%s", path, seperator, fileName2)
filePath3 := fmt.Sprintf("%s%s%s", path, seperator, fileName3)
filePath4 := fmt.Sprintf("%s%s%s", path, seperator, fileName4)
if err := WriteFile(path, fileName1, true, "first line"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
if err := WriteFile(path, fileName2, true, "first line"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
if err := WriteFile(path, fileName3, true, "first line"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
if err := WriteFile(path, fileName4, true, "first line"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
fileList, err := GetFileList(path)
if err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
if fileList[0] != filePath1 {
t.Errorf("Expected:%s, now got:%s", filePath1, fileList[0])
}
if fileList[1] != filePath2 {
t.Errorf("Expected:%s, now got:%s", filePath2, fileList[1])
}
if fileList[2] != filePath3 {
t.Errorf("Expected:%s, now got:%s", filePath3, fileList[2])
}
if fileList[3] != filePath4 {
t.Errorf("Expected:%s, now got:%s", filePath4, fileList[3])
}
DeleteFile(filePath1)
DeleteFile(filePath2)
DeleteFile(filePath3)
DeleteFile(filePath4)
}
func TestGetFileList2(t *testing.T) {
path := GetCurrentPath()
fmt.Printf("CurrPath:%s\n", path)
fileName1 := "2017-09-12-12.txt"
fileName2 := "2017-09-12-13.txt"
fileName3 := "2017-09-12-14.txt"
fileName4 := "2017-09-12.tar.bz2"
seperator := "\\"
if runtime.GOOS != "windows" {
seperator = "/"
}
filePath1 := fmt.Sprintf("%s%s%s", path, seperator, fileName1)
filePath2 := fmt.Sprintf("%s%s%s", path, seperator, fileName2)
filePath3 := fmt.Sprintf("%s%s%s", path, seperator, fileName3)
filePath4 := fmt.Sprintf("%s%s%s", path, seperator, fileName4)
if err := WriteFile(path, fileName1, true, "first line"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
if err := WriteFile(path, fileName2, true, "first line"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
if err := WriteFile(path, fileName3, true, "first line"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
if err := WriteFile(path, fileName4, true, "first line"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
fileList, err := GetFileList2(path, "2017-09-12", "txt")
if err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
fmt.Printf("fileList:%v\n", fileList)
if fileList[0] != filePath1 {
t.Errorf("Expected:%s, now got:%s", filePath1, fileList[0])
}
if fileList[1] != filePath2 {
t.Errorf("Expected:%s, now got:%s", filePath2, fileList[1])
}
if fileList[2] != filePath3 {
t.Errorf("Expected:%s, now got:%s", filePath3, fileList[2])
}
fileList2, err := GetFileList2(path, "2017-09-12", "tar.bz2")
if err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
fmt.Printf("fileList2:%v\n", fileList2)
if fileList2[0] != filePath4 {
t.Errorf("Expected:%s, now got:%s", filePath4, fileList2[0])
}
DeleteFile(filePath1)
DeleteFile(filePath2)
DeleteFile(filePath3)
DeleteFile(filePath4)
}
func TestReadFileLineByLine(t *testing.T) {
path := GetCurrentPath()
fmt.Printf("CurrPath:%s\n", path)
fileName := fmt.Sprintf("%s/%s", path, "test.txt")
if err := WriteFile(path, "test.txt", true, "first line\n"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
if err := WriteFile(path, "test.txt", true, "second line\n"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
expectedFirstLine := "first line"
expectedSecondLine := "second line"
lineList, err := ReadFileLineByLine(fileName)
if err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
if lineList[0] != expectedFirstLine {
t.Errorf("Expected:%s, but now got:%s", expectedFirstLine, lineList[0])
}
if lineList[1] != expectedSecondLine {
t.Errorf("Expected:%s, but now got:%s", expectedSecondLine, lineList[1])
}
if err := DeleteFile(fileName); err != nil {
t.Errorf("There should be no error, but now it has:%s", err)
}
}
func TestReadFileContent(t *testing.T) {
path := GetCurrentPath()
fmt.Printf("CurrPath:%s\n", path)
fileName := fmt.Sprintf("%s/%s", path, "test.txt")
if err := WriteFile(path, "test.txt", true, "first line\n"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
if err := WriteFile(path, "test.txt", true, "second line\n"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
expectedContent := "first line\nsecond line\n"
if content, err := ReadFileContent(fileName); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
} else if content != expectedContent {
t.Errorf("Expected:%s, but now got:%s", expectedContent, content)
}
if err := DeleteFile(fileName); err != nil {
t.Errorf("There should be no error, but now it has:%s", err)
}
}
func TestDeleteFile(t *testing.T) {
path := GetCurrentPath()
fmt.Printf("CurrPath:%s\n", path)
fileName := fmt.Sprintf("%s/%s", path, "test.txt")
if err := WriteFile(path, "test.txt", true, "first line"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
if err := DeleteFile(fileName); err != nil {
t.Errorf("There should be no error, but now it has:%s", err)
}
}
func TestReadWriteSimultaneously(t *testing.T) {
path := GetCurrentPath()
fmt.Printf("CurrPath:%s\n", path)
fileName := fmt.Sprintf("%s/%s", path, "test.txt")
file1, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, os.ModePerm|os.ModeTemporary)
if err != nil {
t.Errorf("1:there should be no err, but now err:%s", err)
}
// for i := 0; i < 10; i++ {
// file1.WriteString(fmt.Sprintf("line %d\n", i))
// }
go func() {
for i := 0; i < 10; i++ {
file1.WriteString(fmt.Sprintf("line %d\n", i))
time.Sleep(time.Second)
}
}()
file2, err := os.OpenFile(fileName, os.O_RDONLY, os.ModePerm|os.ModeTemporary)
if err != nil {
t.Errorf("2:there should be no err, but now err:%s", err)
}
go func() {
offset := 0
// 读取文件
buf := bufio.NewReader(file2)
for {
// 按行读取
line, _, err2 := buf.ReadLine()
if err2 == io.EOF {
time.Sleep(500 * time.Millisecond)
continue
}
if len(line) == 0 {
continue
}
//将byte[]转换为string并添加到列表中
fmt.Printf("line %d:%s\n", offset, string(line))
offset += 1
if offset >= 10 {
break
}
}
}()
time.Sleep(30 * time.Second)
fmt.Println("end")
}

View File

@@ -0,0 +1,33 @@
package impl_localfile
type levelType int
// 日志等级
const (
// info 信息
info levelType = iota
// warn 警告
warn
// debug 调试
debug
// _error 错误
_error
// fatal 致命
fatal
)
var levels = [...]string{
"info",
"warn",
"debug",
"error",
"fatal",
}
func (t levelType) String() string {
return levels[t]
}

View File

@@ -0,0 +1,57 @@
package gameServerMgr
import (
. "Framework/managecenterModel"
)
var (
mResourceVersionLit = make([]*ResourceVersion, 0)
)
// 解析资源版本信息
func ParseResourceVersionInfo(resourceVersionList []*ResourceVersion) {
mResourceVersionLit = resourceVersionList
}
//返回所有的资源包列表
func GetResourceVersionList() (resourceVersionList []*ResourceVersion) {
resourceVersionList = mResourceVersionLit
return
}
//检测资源
func CheckNewResourceVersion(partnerId, serverId, gameVersionId int32, resourceVersionName string) (availableResourceVersionMap map[string]interface{}, exist bool) {
_, exist = GetServerItem(partnerId, serverId)
if !exist {
return
}
//获取服务所在大区Id
areaId := GetAreaIdByGroupId(serverId)
//获取大区的资源列表
var tempResourceVersionList []*ResourceVersion
for _, resourceVerion := range mResourceVersionLit {
if resourceVerion.AreaID == areaId {
tempResourceVersionList = append(tempResourceVersionList, resourceVerion)
}
}
//获取服务器
serverGroup := GetServerGroup()
//获取资源版本列表
availableResourceVersionMap = GetAvailableResource(tempResourceVersionList, partnerId, gameVersionId, resourceVersionName, OfficialOrTest(serverGroup.OfficialOrTest))
//检测是否有新资源
if len(availableResourceVersionMap) != 0 && availableResourceVersionMap["IsNewResource"] == true {
exist = true
return
}
exist = false
return
}