utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Author: Paul Côté Last Change Author: Paul Côté Last Date Changed: 2022/09/20

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Author: Paul Côté Last Change Author: Paul Côté Last Date Changed: 2022/06/10

ISC License

Copyright (c) 2013-2017 The btcsuite developers Copyright (c) 2016-2017 The Lightning Network Developers

Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Author: Paul Côté Last Change Author: Paul Côté Last Date Changed: 2022/06/10

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	AppVersion = "1.0.0"
	AppName    = "laniakea"
)
View Source
const (
	ErrFloatLargerThanOne = bg.Error("float is larger than or equal to 1")
)
View Source
const (
	ErrUnsupportedAddressType = bg.Error("unsupported address type")
)

Variables

This section is empty.

Functions

func AppDataDir

func AppDataDir(appName string, roaming bool) string

AppDataDir returns an operating system specific directory to be used for storing application data for an application.

The appName parameter is the name of the application the data directory is being requested for. This function will prepend a period to the appName for POSIX style operating systems since that is standard practice. An empty appName or one with a single dot is treated as requesting the current directory so only "." will be returned. Further, the first character of appName will be made lowercase for POSIX style operating systems and uppercase for Mac and Windows since that is standard practice.

The roaming parameter only applies to Windows where it specifies the roaming application data profile (%APPDATA%) should be used instead of the local one (%LOCALAPPDATA%) that is used by default.

Example results:

dir := AppDataDir("myapp", false)
 POSIX (Linux/BSD): ~/.myapp
 Mac OS: $HOME/Library/Application Support/Myapp
 Windows: %LOCALAPPDATA%\Myapp
 Plan 9: $home/myapp

func ClientAddressDialer

func ClientAddressDialer(defaultPort string) func(context.Context,
	string) (net.Conn, error)

ClientAddressDialer creates a gRPC dialer that can also dial unix socket addresses instead of just TCP addresses.

func FileExists

func FileExists(name string) bool

FileExists reports whether the named file or directory exists. This function is taken from https://github.com/lightningnetwork/lnd

func IsLoopback

func IsLoopback(addr string) bool

IsLoopback returns true if an address describes a loopback interface.

func IsUnix

func IsUnix(addr net.Addr) bool

IsUnix returns true if an address describes an Unix socket address.

func NormalizeAddresses

func NormalizeAddresses(addrs []string, defaultPort string,
	tcpResolver TCPResolver) ([]net.Addr, error)

NormalizeAddresses returns a new slice with all the passed addresses normalized with the given default port and all duplicates removed.

func NormalizeToNDecimalPlace

func NormalizeToNDecimalPlace(oldF float64) (float64, error)

NormalizeToNDecimalPlace will take any float below 1 and get the factor to transform it to 1 with equivalent decimal places

func NumDecPlaces

func NumDecPlaces(v float64) int

NumDecPlaces returns the number of decimal places a float is specified to

func ParseAddressString

func ParseAddressString(strAddress string, defaultPort string,
	tcpResolver TCPResolver) (net.Addr, error)

ParseAddressString converts an address in string format to a net.Addr that is compatible with laniakea. UDP is not supported because laniakea needs reliable connections. We accept a custom function to resolve any TCP addresses so that caller is able control exactly how resolution is performed.

func RandSeq

func RandSeq(n int) string

RandSeq generates a random string of length n

func StrInStrSlice

func StrInStrSlice(strSlice []string, str string) bool

StrInStrSlice checks if a given string is in a string slice

func UniqueFileName

func UniqueFileName(path string) string

UniqueFileName creates a unique file name if the provided one exists

func ValidatePluginExec

func ValidatePluginExec(exec string) bool

ValidatePluginExec validates the plugin executable

func ValidatePluginName

func ValidatePluginName(name string) bool

ValidatePluginName validates the plugin name

Types

type TCPResolver

type TCPResolver = func(network, addr string) (*net.TCPAddr, error)

TCPResolver is a function signature that resolves an address on a given network.

Jump to

Keyboard shortcuts

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