utils

package
v0.0.0-...-0e32600 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: Apache-2.0 Imports: 8 Imported by: 8

Documentation

Overview

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotSlice    = errors.New("value is not a slice")
	ErrInvalidType = errors.New("invalid type")
)

Functions

func ElemInSlice

func ElemInSlice(slice, elem interface{}) (bool, error)

ElemInSlice is a generic function for comparing a value with all elements in a slice.

Types

type KeyValParser

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

KeyValParser is a parser that reading lines in format 'key=value\n'. Entries collected during parsing and can be retrieved by calling KeyValParser.Collect(). Keys appearing multiple times will have their values merged into a single list.

func (*KeyValParser) Collect

func (k *KeyValParser) Collect() map[string][]string

Collect() data read during Parse(). Map keys correspond to entry names, while map values is a list of entry values collected for particular key.

For instance, input:

foo=bar
baz=1
baz=zen

will be converted to:

map[string][]string{
    "foo": []string{"bar"},
    "baz": []string{"1", "zen"}
}

If no data was collected during Parse(), returns nil. A non-nil may be returned regardless of errors reported byParse(), in such case, the data will contain entries collected up to a point when error was detected.

func (*KeyValParser) Parse

func (k *KeyValParser) Parse(raw io.Reader) error

type LimitedWriteCloser

type LimitedWriteCloser struct {
	W io.WriteCloser // underlying resource
	N uint64         // number of bytes remaining
}

func (*LimitedWriteCloser) Close

func (lw *LimitedWriteCloser) Close() error

func (*LimitedWriteCloser) Write

func (lw *LimitedWriteCloser) Write(p []byte) (int, error)

type ProgressWriter

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

func NewProgressWriter

func NewProgressWriter(size int64) *ProgressWriter

func (*ProgressWriter) Tick

func (p *ProgressWriter) Tick(n uint64)

func (*ProgressWriter) Write

func (p *ProgressWriter) Write(data []byte) (int, error)

Jump to

Keyboard shortcuts

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