util

package
v0.0.0-...-d4285bb Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2014 License: BSD-2-Clause Imports: 24 Imported by: 0

Documentation

Overview

Package util provides utility methods for performing operations which are used throughout impendulo such as io, type conversion and logging.

Index

Constants

View Source
const (
	DPERM = 0777
	FPERM = os.O_WRONLY | os.O_CREATE | os.O_TRUNC
	EOT   = "\u0004"
)

Variables

This section is empty.

Functions

func AddToZip

func AddToZip(zw *zip.Writer, n string, d []byte) error

AddToZip adds a new file to a zip.Writer.

func BaseDir

func BaseDir() (string, error)

BaseDir retrieves the Impendulo directory.

func CalcTime

func CalcTime(s string) (time.Time, error)

CalcTime converts a time string formatted as yyyymmddhhmmssmmm to a time.Time.

func ComputeHash

func ComputeHash(p, s string) string

ComputeHash computes the hash for a password and its salt.

func CookieKeys

func CookieKeys() ([]byte, []byte, error)

CookieKeys generates cookie keys.

func Copy

func Copy(d, s string) error

Copy copies the contents of s to d.

func CopyFile

func CopyFile(d, s string) error

func CurMilis

func CurMilis() int64

CurMilis returns the current time in miliseconds.

func Date

func Date(m int64) string

Date returns a string representation of the date represented by the miliseconds provided.

func EqualsOne

func EqualsOne(i interface{}, as ...interface{}) bool

EqualsOne returns true if i is equal to any of the members of as.

func Exists

func Exists(p string) bool

Exists checks whether a given path exists.

func Extension

func Extension(n string) (string, string)

func ExtractBytes

func ExtractBytes(zf *zip.File) ([]byte, error)

ExtractBytes extracts data from a zip.File.

func ExtractFile

func ExtractFile(zf *zip.File, d string) error

ExtractFile extracts the contents of a zip.File and saves it in dir.

func GenString

func GenString(n int) string

GenString generates a psuedo-random string using the crypto/rand package.

func GetMilis

func GetMilis(t time.Time) int64

CurMilis returns the time in miliseconds.

func GetPackage

func GetPackage(r io.Reader) string

GetPackage retrieves the package name from a Java source file.

func GetTime

func GetTime(m int64) time.Time

GetTime returns an instance of time.Time for the miliseconds provided.

func Hash

func Hash(p string) (string, string)

Hash hashes the provided password and returns the hash as well as the salt used.

func InstallPath

func InstallPath() (string, error)

InstallPath retrieves the location where Impendulo is currently installed. It first checks for the IMPENDULO_PATH environment variable otherwise the install path is constructed from GOPATH and the Impendulo's package.

func IsDir

func IsDir(p string) bool

IsDir checks whether a given path is a directory.

func IsExec

func IsExec(p string) bool

IsExec checks whether a given path is an executable file.

func IsFile

func IsFile(p string) bool

IsFile checks whether a given path is a file.

func JSON

func JSON(i interface{}) ([]byte, error)

func LoadMap

func LoadMap(n string) (map[bson.ObjectId]bool, error)

LoadMap loads a map stored in a file.

func Log

func Log(v ...interface{})

Log sends data to be logged to the appropriate logger.

func LogDir

func LogDir() (string, error)

func Max

func Max(a, b int) int

func Min

func Min(a, b int) int

func ReadBytes

func ReadBytes(r io.Reader) []byte

ReadBytes reads bytes from a reader until io.EOF is encountered. If the reader can't be read an empty []byte is returned.

func ReadData

func ReadData(r io.Reader) ([]byte, error)

ReadData reads data from a reader until io.EOF or []byte("eof") is encountered.

func ReadJSON

func ReadJSON(r io.Reader) (map[string]interface{}, error)

ReadJSON reads all JSON data from a reader.

func RemoveAll

func RemoveAll(c string, symbols ...string) string

func RemoveEmpty

func RemoveEmpty(c string) string

RemoveEmpty removes whitespace characters from a string.

func Round

func Round(x float64, prec int) float64

func SaveFile

func SaveFile(n string, d []byte) error

SaveFile saves a file (given as a []byte) as n.

func SaveMap

func SaveMap(m map[bson.ObjectId]bool, n string) error

SaveMap saves a map to the filesystem.

func SaveTemp

func SaveTemp(d []byte) (string, error)

func SetErrorLogging

func SetErrorLogging(s string)

SetErrorConsoleLogging sets whether errors should be logged to the console.

func SetInfoLogging

func SetInfoLogging(s string)

SetInfoConsoleLogging sets whether info should be logged to the console.

func ShortName

func ShortName(n string) string

ShortName gets the shortened class name of a Java class.

func SplitTitles

func SplitTitles(titles string) []string

func Title

func Title(s string) string

func Unzip

func Unzip(d string, p []byte) error

Unzip extracts a file (given as a []byte) to dir.

func UnzipKV

func UnzipKV(w KVWriter, d []byte) error

func UnzipToMap

func UnzipToMap(d []byte) (map[string][]byte, error)

UnzipToMap reads the contents of a zip file into a map. Each file's path is a map key and its data is the associated value.

func Validate

func Validate(h, s, p string) bool

Validate authenticates a provided password against a hashed password.

func WriteJSON

func WriteJSON(w io.Writer, i interface{}) error

WriteJSON writes JSON marshalled data to to the writer.

func ZipKV

func ZipKV(r KVReader) ([]byte, error)

func ZipMap

func ZipMap(m map[string][]byte) ([]byte, error)

Zip creates a zip archive from a map which has file names as its keys and file contents as its values.

Types

type E

type E struct{}

empty

type KVReader

type KVReader interface {
	Next() (string, []byte, error)
}

type KVWriter

type KVWriter interface {
	Write(string, []byte) error
}

type Logger

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

Logger allows for concurrent logging.

func NewLogger

func NewLogger(n string) (*Logger, error)

NewLogger creates a new SyncLogger which writes its logs to the specified file.

func (*Logger) Log

func (l *Logger) Log(v ...interface{})

Log safely logs data to this logger's log file.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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