util

package module
v0.0.0-...-727f7c1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIrregularFileFound = errors.New("filetree contains an irregular file")
)

Functions

func BusySleep

func BusySleep(duration time.Duration)

func DoesFileExist

func DoesFileExist(path string) (bool, error)

func GetListenerPort

func GetListenerPort(listener net.Listener) (int, error)

func GetRandUint64

func GetRandUint64() (uint64, error)

func IsDir

func IsDir(path string) (bool, error)

func ListenWebSocket

func ListenWebSocket(port uint, logger *log.Logger) chan *WebSocket

Starts one goroutine to listen for sockets. Starts one goroutine to handle each socket. Exits when Complete is called.

You can receive and use sockets concurrently.

func NewDefaultLogger

func NewDefaultLogger() (*log.Logger, error)

func NewLogger

func NewLogger(loggerOptions LoggerOptions) (*log.Logger, error)

Logger can be used concurrently.

func NewPrefixLogger

func NewPrefixLogger(prefix string) (*log.Logger, error)

func ParseJsonFile

func ParseJsonFile(path string, object interface{}) error

func PostJson

func PostJson(host string, port uint, object interface{}) (*http.Response, error)

func StartServer

func StartServer(port uint, logger *log.Logger) (chan JsonRequest, error)

Starts one goroutine to listen for requests. Starts a goroutine to handle each request. Exits when Complete is called.

You can receive requests concurrently. You can complete requests concurrently and in any order.

func WriteJsonFile

func WriteJsonFile(path string, object interface{}) error

Types

type JsonRequest

type JsonRequest struct {
	Json     interface{}
	Response http.ResponseWriter
	// contains filtered or unexported fields
}

func (JsonRequest) Complete

func (jsonRequest JsonRequest) Complete()

func (JsonRequest) RespondJson

func (jsonRequest JsonRequest) RespondJson(object interface{}) error

type LoggerOptions

type LoggerOptions struct {
	UseStdout         bool
	FilePath          string
	AdditionalWriters []io.Writer
}

type Node

type Node struct {
	// Go's os package represents filenames as strings,
	// so we assume that all OSes can convert their filenames
	// to Go strings.
	Name     *string
	Data     []byte
	Children []*Node
}

The wire representation of a filetree: UTF-8 encoded JSON. File names are Unicode and UTF-8 encoded. File contents are byte streams which are base64 encoded and UTF-8 encoded. Go's json.Marshal already does this, but you can implement an en/decoder in any language.

func ConvertFilesToNode

func ConvertFilesToNode(path string) (*Node, error)

func (Node) Encode

func (node Node) Encode() ([]byte, error)

func (Node) IsDir

func (node Node) IsDir() bool

func (Node) String

func (node Node) String() string

type WebSocket

type WebSocket struct {
	Conn *websocket.Conn
	// contains filtered or unexported fields
}

func (*WebSocket) Complete

func (webSocket *WebSocket) Complete()

type ZeroReader

type ZeroReader struct{}

func (ZeroReader) Read

func (zeroReader ZeroReader) Read(p []byte) (n int, err error)

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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