tools

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2018 License: Apache-2.0 Imports: 6 Imported by: 20

Documentation

Overview

Package tools contains some internal functionalities needed for expipe. Config package contains the logic required for reading configuration from files. Any logic required for converting data types will land in the datatype package. The token package contains only logic required for generating request based tokens. Other commonly used logic are places in the internal package itself. There are numeric and string searches, logging setup, etc.

Index

Examples

Constants

View Source
const (
	// InfoLevel for Info level
	InfoLevel = logrus.InfoLevel
	// WarnLevel for Warn level
	WarnLevel = logrus.WarnLevel
	// DebugLevel for Debug level
	DebugLevel = logrus.DebugLevel
	// ErrorLevel for Error level
	ErrorLevel = logrus.ErrorLevel
)

Variables

This section is empty.

Functions

func IsJSON added in v0.11.0

func IsJSON(input []byte) bool

IsJSON checks is the input content is a valid JSON input.

func SanitiseURL

func SanitiseURL(url string) (string, error)

SanitiseURL prepends a protocol to the url if not defined, and checks if it's a valid url.

Example

This example shows how to sanitise a URL.

package main

import (
	"fmt"

	"github.com/arsham/expipe/tools"
)

func main() {
	res, err := tools.SanitiseURL("http localhost")
	fmt.Printf("Error: %v\n", err)
	fmt.Printf("Result: <%s>\n", res)

	res, err = tools.SanitiseURL("127.0.0.1")
	fmt.Printf("Error: %v\n", err)
	fmt.Printf("Result: <%s>\n", res)

	res, _ = tools.SanitiseURL("https://localhost.localdomain")
	fmt.Printf("Result: <%s>\n", res)

}
Output:

Error: invalid url: http localhost
Result: <>
Error: <nil>
Result: <http://127.0.0.1>
Result: <https://localhost.localdomain>

func StringInMapKeys

func StringInMapKeys(niddle string, haystack map[string]string) bool

StringInMapKeys returns true if niddle is in the haystack's keys

func StringInSlice

func StringInSlice(niddle string, haystack []string) bool

StringInSlice returns true if niddle is in the haystack

Types

type Entry

type Entry struct{ *logrus.Entry }

Entry embeds logrus.Entry

type FieldLogger

type FieldLogger logrus.FieldLogger

FieldLogger interface set by logrus

type InvalidURLError

type InvalidURLError string

InvalidURLError is returned when the URL is not a valid one.

func (InvalidURLError) Error

func (i InvalidURLError) Error() string

type Level

type Level logrus.Level

Level type set by logrus

type Logger

type Logger struct{ *logrus.Logger }

Logger embeds logrus.Logger

func DiscardLogger

func DiscardLogger() *Logger

DiscardLogger returns a dummy logger. This is useful for tests when you don't want to actually write to the Stdout.

func GetLogger

func GetLogger(level string) *Logger

GetLogger returns the default logger with the given log level.

Example

To get a logger with info level.

package main

import (
	"github.com/arsham/expipe/tools"
)

func main() {
	tools.GetLogger("info")
	// It's case insensitive.
	tools.GetLogger("INFO")
}
Output:

func StandardLogger

func StandardLogger() *Logger

StandardLogger returns an instance of Logger

Directories

Path Synopsis
Package config contains the logic for reading the configurations from a file in order to bootstrap it.
Package config contains the logic for reading the configurations from a file in order to bootstrap it.
Package token contains necessary logic for passing messages.
Package token contains necessary logic for passing messages.

Jump to

Keyboard shortcuts

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