当前位置: 首页>>代码示例>>Golang>>正文


Golang logg.Err函数代码示例

本文整理汇总了Golang中logg.Err函数的典型用法代码示例。如果您正苦于以下问题:Golang Err函数的具体用法?Golang Err怎么用?Golang Err使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Err函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Add

// Adds a new column.
func (table *Table) Add(name string, length int) int {
	_, exists := table.Columns[name]
	if exists {
		return st.ColumnAlreadyExists
	}
	if len(name) > constant.MaxColumnNameLength {
		return st.ColumnNameTooLong
	}
	if length <= 0 {
		return st.InvalidColumnLength
	}
	var numberOfRows int
	numberOfRows, status := table.NumberOfRows()
	if status == st.OK && numberOfRows > 0 {
		// Rebuild data file if there are already rows in the table.
		// (To leave space for the new column)
		status = table.RebuildDataFile(name, length)
		table.pushNewColumn(name, length)
	} else {
		newColumn := table.pushNewColumn(name, length)
		// Write definition of the new column into definition file.
		_, err := table.DefFile.Seek(0, 2)
		if err != nil {
			logg.Err("table", "Add", err.String())
			return st.CannotSeekTableDefFile
		}
		_, err = table.DefFile.WriteString(column.ColumnToDef(newColumn))
		if err != nil {
			logg.Err("table", "Add", err.String())
			return st.CannotWriteTableDefFile
		}
	}
	table.RowLength += length
	return st.OK
}
开发者ID:postfix,项目名称:DBGo,代码行数:36,代码来源:table.go

示例2: Insert

// Inserts a row to the bottom of the table.
func (table *Table) Insert(row map[string]string) int {
	// Seek to EOF
	_, err := table.DataFile.Seek(0, 2)
	if err == nil {
		// For the columns in their order
		for _, column := range table.ColumnsInOrder {
			value, exists := row[column.Name]
			if !exists {
				value = ""
			}
			// Keep writing the column value.
			status := table.Write(column, value)
			if status != st.OK {
				return status
			}
		}
		// Write a new-line character.
		_, err = table.DataFile.WriteString("\n")
		if err != nil {
			logg.Err("table", "Insert", err.String())
			return st.CannotWriteTableDataFile
		}
	} else {
		logg.Err("table", "Insert", err.String())
		return st.CannotSeekTableDataFile
	}
	return st.OK
}
开发者ID:postfix,项目名称:DBGo,代码行数:29,代码来源:table.go

示例3: CreateAndWrite

// Creates a file and writes the content into it.
func CreateAndWrite(filename, content string) int {
	file, err := os.Create(filename)
	defer file.Close()
	if err != nil {
		logg.Err("util", "CreateAndWrite", err)
		return st.CannotCreateFile
	}
	_, err = file.WriteString(content)
	if err != nil {
		logg.Err("util", "CreateAndWrite", err)
		return st.CannotCreateFile
	}
	return st.OK
}
开发者ID:postfix,项目名称:DBGo,代码行数:15,代码来源:file.go

示例4: OpenFiles

// Opens file handles.
func (table *Table) OpenFiles() int {
	var err os.Error
	table.DefFile, err = os.OpenFile(table.DefFilePath, os.O_RDWR, constant.DataFilePerm)
	if err == nil {
		table.DataFile, err = os.OpenFile(table.DataFilePath, os.O_RDWR, constant.DataFilePerm)
		if err != nil {
			logg.Err("table", "OpenFiles", err.String())
			return st.CannotOpenTableDataFile
		}
	} else {
		logg.Err("table", "OpenFiles", err.String())
		return st.CannotOpenTableDefFile
	}
	return st.OK
}
开发者ID:postfix,项目名称:DBGo,代码行数:16,代码来源:table.go

示例5: Delete

// Deletes table files
func Delete(path string, name string) int {
	for _, ext := range constant.TableFiles() {
		err := os.Remove(path + name + ext)
		if err != nil {
			logg.Err("tablefilemanager", "Delete", err)
			return st.CannotRemoveTableFile
		}
	}
	for _, dir := range constant.TableDirs() {
		err := os.RemoveAll(path + name + dir)
		if err != nil {
			logg.Err("tablefilemanager", "Delete", err)
			return st.CannotRemoveTableDir
		}
	}
	return st.OK
}
开发者ID:postfix,项目名称:DBGo,代码行数:18,代码来源:tablefilemanager.go

示例6: Rename

// Renames table files.
func Rename(path string, oldName string, newName string) int {
	for _, ext := range constant.TableFiles() {
		err := os.Rename(path+oldName+ext, path+newName+ext)
		if err != nil {
			logg.Err("tablefilemanager", "Rename", err)
			return st.CannotRenameTableFile
		}
	}
	for _, dir := range constant.TableDirs() {
		err := os.Rename(path+oldName+dir, path+newName+dir)
		if err != nil {
			logg.Err("tablefilemanager", "Rename", err)
			return st.CannotRenameTableDir
		}
	}
	return st.OK
}
开发者ID:postfix,项目名称:DBGo,代码行数:18,代码来源:tablefilemanager.go

示例7: NumberOfRows

// Returns the number of rows in this table.
func (table *Table) NumberOfRows() (int, int) {
	var numberOfRows int
	var dataFileInfo *os.FileInfo
	dataFileInfo, err := table.DataFile.Stat()
	if err != nil {
		logg.Err("table", "NumberOfRows", err.String())
		return 0, st.CannotStatTableDataFile
	}
	numberOfRows = int(dataFileInfo.Size) / table.RowLength
	return numberOfRows, st.OK
}
开发者ID:postfix,项目名称:DBGo,代码行数:12,代码来源:table.go

示例8: Seek

// Seeks to a row (e.g. row number 10).
func (table *Table) Seek(rowNumber int) int {
	var numberOfRows int
	numberOfRows, status := table.NumberOfRows()
	if status == st.OK && rowNumber < numberOfRows {
		_, err := table.DataFile.Seek(int64(rowNumber*table.RowLength), 0)
		if err != nil {
			logg.Err("table", "Seek", err.String())
			return st.CannotSeekTableDataFile
		}
	}
	return st.OK
}
开发者ID:postfix,项目名称:DBGo,代码行数:13,代码来源:table.go

示例9: ColumnFromDef

// Constructs a Column from a column's text definition.
func ColumnFromDef(offset int, definition string) (*Column, int) {
	var column *Column
	// Extract length and name from the definition.
	lengthName := strings.Split(definition, ":")
	length, err := strconv.Atoi(lengthName[1])
	if err != nil {
		logg.Err("Column", "ColumnFromDef", "Definition malformed: "+definition)
		return nil, st.InvalidColumnDefinition
	}
	column = &Column{Offset: offset, Length: length, Name: lengthName[0]}
	return column, st.OK
}
开发者ID:postfix,项目名称:DBGo,代码行数:13,代码来源:column.go

示例10: Open

// Opens a table.
func Open(path, name string) (*Table, int) {
	var table *Table
	table = new(Table)
	table.Path = path
	table.Name = name
	status := table.Init()
	if status != st.OK {
		logg.Err("table", "Open", "Failed to open"+path+name+" Err: "+string(status))
		return nil, status
	}
	return table, st.OK
}
开发者ID:postfix,项目名称:DBGo,代码行数:13,代码来源:table.go

示例11: Create

// Creates table files.
func Create(path string, name string) int {
	if len(name) > constant.MaxTableNameLength {
		return st.TableNameTooLong
	}
	// Create table files with extension names.
	for _, ext := range constant.TableFiles() {
		_, err := os.Create(path + name + ext)
		if err != nil {
			logg.Err("tablefilemanager", "Create", err)
			return st.CannotCreateTableFile
		}
	}
	// Create table directories with name suffixes.
	for _, dir := range constant.TableDirs() {
		err := os.Mkdir(path+name+dir, constant.TableDirPerm)
		if err != nil {
			logg.Err("tablefilemanager", "Create", err)
			return st.CannotCreateTableDir
		}
	}
	return st.OK
}
开发者ID:postfix,项目名称:DBGo,代码行数:23,代码来源:tablefilemanager.go

示例12: Open

// Opens a path as database.
func Open(path string) (*Database, int) {
	var db *Database
	db = new(Database)
	db.Tables = make(map[string]*table.Table)
	// Open and read content of the path (as a directory).
	directory, err := os.Open(path)
	if err != nil {
		db = nil
		logg.Err("database", "Open", err.String())
		return db, st.CannotOpenDatabaseDirectory
	}
	defer directory.Close()
	fi, err := directory.Readdir(0)
	if err != nil {
		db = nil
		logg.Err("database", "Open", err.String())
		return db, st.CannotReadDatabaseDirectory
	}
	for _, fileInfo := range fi {
		// Extract extension of file name.
		if fileInfo.IsRegular() {
			name, ext := util.FilenameParts(fileInfo.Name)
			// If extension is .data, open the file as a Table.
			if ext == "data" {
				_, exists := db.Tables[name]
				if !exists {
					var status int
					// Open the table and put it into tables map.
					db.Tables[name], status = table.Open(path, name)
					if status != st.OK {
						return nil, status
					}
				}
			}
		}
	}
	db.Path = path
	return db, db.PrepareForTriggers(false)
}
开发者ID:postfix,项目名称:DBGo,代码行数:40,代码来源:database.go

示例13: Flush

// Flushes table's files
func (table *Table) Flush() int {
	err := table.DefFile.Sync()
	if err == nil {
		err = table.DataFile.Sync()
		if err != nil {
			logg.Err("table", "Flush", err.String())
			return st.CannotFlushTableDataFile
		}
	} else {
		return st.CannotFlushTableDefFile
	}
	return st.OK
}
开发者ID:postfix,项目名称:DBGo,代码行数:14,代码来源:table.go

示例14: RemoveLine

// Removes a line's occurances from a file.
func RemoveLine(filename, line string) int {
	// Open and read the file.
	file, err := os.Open(filename)
	if err != nil {
		logg.Err("util", "RemoveLine", err)
		return st.CannotReadFile
	}
	fi, err := file.Stat()
	if err != nil {
		logg.Err("util", "RemoveLine", err)
		return st.CannotReadFile
	}
	buffer := make([]byte, fi.Size)
	_, err = file.Read(buffer)
	if err != nil {
		logg.Err("util", "RemoveLine", err)
		return st.CannotReadFile
	}
	file.Close()
	// Re-open the file and overwrite it.
	file, err = os.OpenFile(filename, os.O_WRONLY+os.O_TRUNC, 0666)
	defer file.Close()
	if err != nil {
		logg.Err("util", "RemoveLine", err)
		return st.CannotReadFile
	}
	lines := strings.Split(string(buffer), "\n")
	for _, content := range lines {
		if strings.TrimSpace(content) != strings.TrimSpace(line) {
			_, err = file.WriteString(content + "\n")
			if err != nil {
				logg.Err("util", "RemoveLine", err)
				return st.CannotWriteFile
			}
		}
	}
	return st.OK
}
开发者ID:postfix,项目名称:DBGo,代码行数:39,代码来源:file.go

示例15: SeekColumn

// Seeks to a row and column (e.g. row number 10 column "NAME").
func (table *Table) SeekColumn(rowNumber int, columnName string) int {
	status := table.Seek(rowNumber)
	if status == st.OK {
		column, exists := table.Columns[columnName]
		if exists {
			_, err := table.DataFile.Seek(int64(column.Offset), 1)
			if err != nil {
				logg.Err("table", "SeekColumn", err.String())
				return st.CannotSeekTableDataFile
			}
		}
	}
	return st.OK
}
开发者ID:postfix,项目名称:DBGo,代码行数:15,代码来源:table.go


注:本文中的logg.Err函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。