utils

package module
v0.0.0-...-77ce3eb Latest Latest
Warning

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

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

README

Introduction

This project contains utils for Go projects.

Projects

Configuration

Read configuration from file (format key=value).

Functions:
func LoadConfig(filename string) (map[string]string, error) {}

Logging

Ease logging usage.

Usage Example:
import utils "github.com/iMax-pp/go-utils"

var logger *utils.Logger

func main() {
    logger, _ = utils.NewLogger("test.log", utils.LEVEL_TRACE)
    defer logger.Close()

    logger.Info("Logger level:", logger.Level)
}
Functions:
// Logging level type
type LogLevel int
const (
    LEVEL_TRACE LogLevel
    LEVEL_DEBUG
    LEVEL_INFO
    LEVEL_WARN
    LEVEL_ERROR
    LEVEL_OFF
)

// Logger type, is a log.Logger
type Logger struct {
    *log.Logger

    Level  LogLevel
    Output *os.File
}

// Logger creation, from parameters
func NewLogger(output string, level LogLevel) (*Logger, error) {}
// Logger creation, from configuration file
func NewLoggerFromConfig(filename string) (*Logger, error) {}
// Don't forget to close the Logger afterward
func (logger *Logger) Close() {}

// Logging methods…
// Trace
func (logger *Logger) Trace(v ...interface{}) {}
// Trace with format
func (logger *Logger) Tracef(format string, v ...interface{}) {}
// Trace begin
func (logger *Logger) TraceBegin(f string) {}
// Trace end
func (logger *Logger) TraceEnd(f string) {}
// Debug
func (logger *Logger) Debug(v ...interface{}) {}
// Debug with format
func (logger *Logger) Debugf(format string, v ...interface{}) {}
// Info
func (logger *Logger) Info(v ...interface{}) {}
// Info with format
func (logger *Logger) Infof(format string, v ...interface{}) {}
// Warn
func (logger *Logger) Warn(v ...interface{}) {}
// Warn with format
func (logger *Logger) Warnf(format string, v ...interface{}) {}
// Error
func (logger *Logger) Error(v ...interface{}) {}
// Error with format
func (logger *Logger) Errorf(format string, v ...interface{}) {}
// Fatal
func (logger *Logger) Fatal(v ...interface{}) {}
// Fatal with format
func (logger *Logger) Fatalf(format string, v ...interface{}) {}

Mailer

Easily send emails.

Usage Example:
import (
    "log"
	utils "github.com/iMax-pp/go-utils"
)

func main() {
    mailer, err := utils.NewMailer("smtp.server.com", 25, "sender@server.com", "recipient@server.com")
    if err != nil {
        log.Fatalln(err)
    }

    msg := "This is a test message."
    err = mailer.SendMail(msg)
    if err != nil {
        log.Fatalln(err)
    }
}
Functions:
// Mailer type
type Mailer struct {
    Server string
    Port   string
    From   string
    To     string
}

// Mailer creation, from parameters
func NewMailer(server, port, from, to string) *Mailer {}
// Mailer creation, from configuration file
func NewMailerFromConfig(filename string) (*Mailer, error) {}
// Send an email…
func (mail *Mailer) SendMail(msg string) error {}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfig

func LoadConfig(filename string) (map[string]string, error)

Types

type LogLevel

type LogLevel int
const (
	LEVEL_TRACE LogLevel = iota
	LEVEL_DEBUG
	LEVEL_INFO
	LEVEL_WARN
	LEVEL_ERROR
	LEVEL_OFF
)

func (LogLevel) String

func (lvl LogLevel) String() string

type Logger

type Logger struct {
	*log.Logger

	Level  LogLevel
	Output *os.File
}

func NewLogger

func NewLogger(filename string, level LogLevel) (*Logger, error)

func NewLoggerFromConfig

func NewLoggerFromConfig(filename string) (*Logger, error)

func (*Logger) Close

func (logger *Logger) Close()

func (*Logger) Debug

func (logger *Logger) Debug(v ...interface{})

func (*Logger) Debugf

func (logger *Logger) Debugf(format string, v ...interface{})

func (*Logger) Error

func (logger *Logger) Error(v ...interface{})

func (*Logger) Errorf

func (logger *Logger) Errorf(format string, v ...interface{})

func (*Logger) Fatal

func (logger *Logger) Fatal(v ...interface{})

func (*Logger) Fatalf

func (logger *Logger) Fatalf(format string, v ...interface{})

func (*Logger) Info

func (logger *Logger) Info(v ...interface{})

func (*Logger) Infof

func (logger *Logger) Infof(format string, v ...interface{})

func (*Logger) Trace

func (logger *Logger) Trace(v ...interface{})

func (*Logger) TraceBegin

func (logger *Logger) TraceBegin(f string)

func (*Logger) TraceEnd

func (logger *Logger) TraceEnd(f string)

func (*Logger) Tracef

func (logger *Logger) Tracef(format string, v ...interface{})

func (*Logger) Warn

func (logger *Logger) Warn(v ...interface{})

func (*Logger) Warnf

func (logger *Logger) Warnf(format string, v ...interface{})

type Mailer

type Mailer struct {
	Server string
	Port   string
	From   string
	To     string
}

func NewMailer

func NewMailer(server, port, from, to string) *Mailer

func NewMailerFromConfig

func NewMailerFromConfig(filename string) (*Mailer, error)

func (*Mailer) SendMail

func (mail *Mailer) SendMail(msg string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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