utils

package
v0.5.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2020 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorApp  = "app"
	ErrorNode = "node"
	ErrorUser = "user"
)

Error types

View Source
const (
	RequestDELETE = "DELETE"
	RequestGET    = "GET"
	RequestPATCH  = "PATCH"
	RequestPOST   = "POST"
	RequestPUT    = "PUT"
)

Variables

This section is empty.

Functions

func CheckJWTValid

func CheckJWTValid(jwt string) bool

CheckJWTValid returns true if the JWT token is well-formed and not expired This function does not validate the JWT token beyond checking if it's still valid

func EnsureFolder

func EnsureFolder(path string) error

EnsureFolder creates a folder if it doesn't exist already

func ExitWithError

func ExitWithError(errType string, errMessage string, errData error)

ExitWithError prints and error then terminates the app

func FileExists

func FileExists(path string) (bool, error)

FileExists returns true if the path exists on disk and it's not a folder

func FolderExists

func FolderExists(path string) (bool, error)

FolderExists returns true if the path exists on disk and it's a folder

func FormatBytes

func FormatBytes(b int64) string

FormatBytes formats file sizes in human-readable format Source: https://yourbasic.org/golang/formatting-byte-size-to-human-readable-format/

func IsRegularFile

func IsRegularFile(path string) (bool, error)

IsRegularFile returns true if the path is a file

func LaunchBrowser

func LaunchBrowser(url string)

LaunchBrowser opens a web browser at a specified URL

func PathExists

func PathExists(path string) (bool, error)

PathExists returns true if the path exists on disk

func RemoveContents

func RemoveContents(dir string) error

RemoveContents remove all contents within a directory Source: https://stackoverflow.com/a/33451503/192024

func RequestJSON

func RequestJSON(opts RequestOpts) (err error)

RequestJSON fetches a JSON document from the web

func RequestRaw

func RequestRaw(opts RequestOpts) (response io.ReadCloser, err error)

RequestRaw fetches a document from the web and returns the stream as is

func SliceContainsString

func SliceContainsString(s []string, e string) bool

SliceContainsString returns true if the slice of strings contains a certain string

func TarBZ2

func TarBZ2(src string, writers ...io.Writer) error

TarBZ2 creates a tar.bz2 archive from a folder Adapted from: https://gist.github.com/sdomino/e6bc0c98f87843bc26bb

Types

type NodeStore

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

NodeStore class for managing the node store

func (*NodeStore) GetAuthToken

func (s *NodeStore) GetAuthToken(address string) string

GetAuthToken returns the value for the Authorization header It will throw an error and terminate the app if there's no token or if the auth token has expired and can't be refreshed

func (*NodeStore) Init

func (s *NodeStore) Init() error

Init the object

func (*NodeStore) StoreAuthToken

func (s *NodeStore) StoreAuthToken(address string, idToken string, refreshToken string, clientID string, tokenURL string) error

StoreAuthToken adds the ID Token and the Refresh Token to the store

func (*NodeStore) StoreSharedKey

func (s *NodeStore) StoreSharedKey(address string, sharedKey string) error

StoreSharedKey adds the shared key to the store

type RequestOpts

type RequestOpts struct {
	Authorization   string
	Body            io.Reader
	BodyContentType string
	Client          *http.Client
	Method          string
	StatusCode      int
	Target          interface{} // Only used by RequestJSON
	URL             string
}

RequestOpts contains the parameters for the RequestJSON function

Jump to

Keyboard shortcuts

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