util

package
v0.0.0-...-ccb62fa Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package util provides some helpers.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidBits = Error("无效的位数据")
)

Errors.

View Source
var (
	// Root is the root dir of the executable that started the current process.
	Root string
)

Functions

func Task

func Task(d time.Duration, f func(), h, m, s int)

Task calls the function f a the given time.

Types

type Bits

type Bits uint64

Bits represents a bits value.

func MakeBits

func MakeBits(b []byte) (Bits, error)

MakeBits makes bits value from bytes.

func ParseBits

func ParseBits(s string) (Bits, error)

ParseBits parses string to bits value.

func (Bits) Bytes

func (a Bits) Bytes() []byte

Bytes returns the bits value as bytes.

func (Bits) MarshalText

func (a Bits) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Bits) String

func (a Bits) String() string

String returns the bits value as string.

func (*Bits) UnmarshalText

func (a *Bits) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Cache

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

Cache represents the cache.

func NewCache

func NewCache(age time.Duration, loader func(interface{}) (interface{}, error)) *Cache

NewCache creates a new cache.

func (*Cache) Delete

func (a *Cache) Delete(key interface{})

Delete deletes the data from cache.

func (*Cache) Load

func (a *Cache) Load(key interface{}) (interface{}, error)

Load loads the data by key.

func (*Cache) LoadWith

func (a *Cache) LoadWith(key interface{}, loader func(interface{}) (interface{}, error)) (value interface{}, err error)

LoadWith loads the data by key and loader.

type Date

type Date time.Time

Date represents a date.

func (Date) MarshalText

func (a Date) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler interface.

func (Date) String

func (a Date) String() string

String returns the date as string.

func (*Date) UnmarshalText

func (a *Date) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler interface.

type DateTime

type DateTime time.Time

DateTime represents a date time.

func (DateTime) MarshalText

func (a DateTime) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (DateTime) String

func (a DateTime) String() string

String returns the datetime as string.

func (*DateTime) UnmarshalText

func (a *DateTime) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Error

type Error string

Error represents a biz error.

func (Error) Error

func (a Error) Error() string

Error implements error interface.

type HTML

type HTML struct {
	Title    string
	JSFiles  []string
	CSSFiles []string
}

HTML represents a html file.

func NewHTML

func NewHTML(title string) *HTML

NewHTML creates a new html file.

func (*HTML) AddCSS

func (a *HTML) AddCSS(files ...string) *HTML

AddCSS adds css files to the html.

func (*HTML) AddJS

func (a *HTML) AddJS(files ...string) *HTML

AddJS adds js files to the html.

func (*HTML) Build

func (a *HTML) Build() ([]byte, error)

Build builds the html file.

Jump to

Keyboard shortcuts

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