swissknife

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: MIT Imports: 12 Imported by: 3

README ΒΆ

swiss-knife

Library with all sorts of things to create code prototypes super fast

install

go get github.com/Sagleft/swiss-knife
usage example
package main

import (
    "fmt"
    swissknife "github.com/Sagleft/swiss-knife"
)

func main() {
    fmt.Println("Hello, World!")
    swissknife.RunInBackground()
}

image

🌐 Telegram channel

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func CheckErrors ΒΆ added in v1.0.1

func CheckErrors(errChecks ...ErrorFunc) error

CheckErrors - check some errors

func FloatToString ΒΆ added in v1.0.3

func FloatToString(val float64) string

FloatToString - convert float to string

func FormatDuration ΒΆ added in v1.0.4

func FormatDuration(duration time.Duration) string

FormatDuration - format duration 52h -> "2 days 4 hours"

func GetValuePrecision ΒΆ

func GetValuePrecision(val float64) int

GetValuePrecision - find out the precision of the numeric value

func IntArrContains ΒΆ

func IntArrContains(a []int64, x int64) bool

IntArrContains indicates whether x is contained in a.

func IntArrFind ΒΆ

func IntArrFind(a []int64, x int64) int

IntArrFind find element index in arr. -1 if not found

func ReadFile ΒΆ

func ReadFile(filepath string) ([]byte, error)

ReadFile read file to string

func ReadFileLines ΒΆ added in v1.0.5

func ReadFileLines(filePath string) ([]string, error)

ReadFileLines - read file to lines

func ReadFileToString ΒΆ

func ReadFileToString(filepath string) (string, error)

ReadFileToString read file to string

func Reconnect ΒΆ added in v1.0.5

func Reconnect(task ReconnectTask)

Reconnect - setup reconnect

func RunInBackground ΒΆ

func RunInBackground()

RunInBackground - blocking method with no exit

func SaveStringToFile ΒΆ

func SaveStringToFile(filepath string, content string) error

SaveStringToFile save arbitrary string to file

func SaveStructToJSONFile ΒΆ

func SaveStructToJSONFile(i interface{}, filepath string) error

SaveStructToJSONFile save arbitrary structure to JSON file

func Ternary ΒΆ

func Ternary(statement bool, a, b interface{}) interface{}

Ternary operator. conditional operator usage example: var res = ternary(val > 0, "positive", "negative")

Types ΒΆ

type ChannelWorker ΒΆ added in v1.0.6

type ChannelWorker struct {
	MaxCapacity          int
	Events               chan interface{}
	EventHandlerCallback func(event interface{})
	ProcessingEvents     bool
	IsFinished           bool
}

func NewChannelWorker ΒΆ added in v1.0.6

func NewChannelWorker(callback func(event interface{}), maxCapacity int) *ChannelWorker

func (*ChannelWorker) AddEvent ΒΆ added in v1.0.6

func (w *ChannelWorker) AddEvent(event interface{})

func (*ChannelWorker) GetMessagesAvailableCount ΒΆ added in v1.0.6

func (w *ChannelWorker) GetMessagesAvailableCount() int

func (*ChannelWorker) HandleEvents ΒΆ added in v1.0.6

func (w *ChannelWorker) HandleEvents()

func (*ChannelWorker) Start ΒΆ added in v1.0.6

func (w *ChannelWorker) Start()

start handle events

func (*ChannelWorker) Stop ΒΆ added in v1.0.6

func (w *ChannelWorker) Stop()

type ConnFunc ΒΆ added in v1.0.5

type ConnFunc func() error

ConnFunc - some func

type ErrorFunc ΒΆ added in v1.0.1

type ErrorFunc func() error

ErrorFunc - func with error result

type ReconnectTask ΒΆ added in v1.0.5

type ReconnectTask struct {
	ConnectionDescription      string // connection name
	ReconnectionAttemptsNumber int
	ConnectionTimeout          time.Duration
	ReconnectAfterTimeout      time.Duration
	WaitingBetweenAttempts     time.Duration

	// callbacks
	ConnCallback  ConnFunc
	ErrorCallback func(error)
	LogCallback   func(string)
}

Jump to

Keyboard shortcuts

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