utils

package
v2.0.0-rc.2+incompatible Latest Latest
Warning

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

Go to latest
Published: May 31, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = &http.Client{

	Timeout: 0,
	Transport: &http.Transport{
		DialContext:           DefaultDialer.DialContext,
		MaxIdleConns:          100,
		MaxIdleConnsPerHost:   10,
		IdleConnTimeout:       time.Second * 20,
		TLSHandshakeTimeout:   time.Second * 10,
		ExpectContinueTimeout: 2 * time.Second,
	},
}

DefaultClient is the default HTTP client for qscamel.

View Source
var DefaultDialer = &Dialer{
	&net.Dialer{
		DualStack: false,
		Timeout:   time.Second * 30,
	},
	time.Second * 30,
	time.Second * 30,
}

DefaultDialer is the default dialer for qscamel.

View Source
var DisableCache bool

DisableCache will disable caching of the home directory. Caching is enabled by default.

Functions

func CheckError

func CheckError(fn func() error)

CheckError will execute the func, handle it's panic and error

func CreateFile

func CreateFile(p string) (f *os.File, err error)

CreateFile will create a file recursively.

func Dir

func Dir() (string, error)

Dir returns the home directory for the executing user.

This uses an OS-specific method for discovering the home directory. An error is returned if a home directory cannot be detected.

func Expand

func Expand(path string) (string, error)

Expand expands the path to include the home directory if the path is prefixed with `~`. If it isn't prefixed with `~`, the path is returned as-is.

func FromTaskContext

func FromTaskContext(ctx context.Context) string

FromTaskContext will extract task name from context.

func GetMarkers

func GetMarkers(n int) []byte

GetMarkers will generate markers for every list worker.

func IsTimeoutError

func IsTimeoutError(err error) bool

IsTimeoutError will check whether the err is a timeout error.

func Join

func Join(in ...string) string

Join will join path together which will make sure not leading or trailing "/"

func NewTaskContext

func NewTaskContext(ctx context.Context, t string) context.Context

NewTaskContext will create a ctx with task name.

func Recover

func Recover()

Recover will recover a goroutine from panic.

func Relative

func Relative(full, prefix string) string

Relative will calculate the relative path for full by prefix.

Types

type Conn

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

Conn is a generic stream-oriented network connection.

func NewConn

func NewConn(c netConn) *Conn

NewConn will create a new conn.

func (Conn) Close

func (c Conn) Close() (err error)

Close will close the conn.

func (Conn) Read

func (c Conn) Read(buf []byte) (n int, err error)

Read will read from the conn.

func (*Conn) SetReadTimeout

func (c *Conn) SetReadTimeout(d time.Duration)

SetReadTimeout will set the conn's read timeout.

func (*Conn) SetWriteTimeout

func (c *Conn) SetWriteTimeout(d time.Duration)

SetWriteTimeout will set the conn's write timeout.

func (Conn) Write

func (c Conn) Write(buf []byte) (n int, err error)

Write will write into the conn.

type ContextKey

type ContextKey string

ContextKey is the type for context key.

const (
	ContextKeyTask ContextKey = "task"
)

Context keys.

type Dialer

type Dialer struct {
	*net.Dialer
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

Dialer is wrapped dialer provided by qingstor go sdk.

We provide this dialer wrapper ReadTimeout & WriteTimeout attributes into connection object. This timeout is for individual buffer I/O operation like other language (python, perl... etc), so don't bother with SetDeadline or stupid nethttp.Client timeout.

func NewDialer

func NewDialer(connTimeout, readTimeout, writeTimeout time.Duration) *Dialer

NewDialer will create a new dialer.

func (*Dialer) Dial

func (d *Dialer) Dial(network, addr string) (net.Conn, error)

Dial connects to the address on the named network.

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

DialContext connects to the address on the named network using the provided context.

Jump to

Keyboard shortcuts

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