Documentation
¶
Index ¶
- Constants
- Variables
- func CurrentDirFS() (fs.FS, error)
- func GoPath() string
- func GoRoot() string
- func GoVersion() string
- func Interruptible(r Runner, sigs ...os.Signal) error
- func InterruptibleContext(ctx context.Context, r Runner, sigs ...os.Signal) error
- func InterruptibleFunc(fn func(ctx context.Context) error, sigs ...os.Signal) error
- func IsGoSrcDir(dir string) bool
- func NewBytesPool(cap ...int) *sync.Pool
- func NopReadWriteCloser(rw io.ReadWriter) io.ReadWriteCloser
- func NopWriteCloser(w io.Writer) io.WriteCloser
- func PathExists(path string) bool
- func ReadCloserFromDescriptor(desc string) (io.ReadCloser, error)
- func SafeCloser(c io.Closer) io.Closer
- func SafeSyncCloser(c io.Closer) io.Closer
- func ToBool(v any) bool
- func ToDuration(v any) (time.Duration, bool)
- func ToFloat(v any) (float64, bool)
- func ToInt(v any) (int64, bool)
- func ToString(v any) string
- func ToTime(v any, opt ...*time.Location) (time.Time, bool)
- func UnmarshalFs(dest any, name string, fa ...fs.FS) error
- func WriteCloserFromDescriptor(desc string) (io.WriteCloser, error)
- type Closers
- type Decoder
- type FormattedText
- type FormattedTextFile
- type GoPackageHint
- type GoPackageHints
- type HjsonText
- type HuJsonText
- type JsonText
- type JsonnetText
- type JwccText
- type Registry
- type Runner
- type RunnerFunc
- type TomlText
- type XmlText
- type YamlText
Constants ¶
const ( ExtJson = ".json" ExtHjson = ".hjson" ExtHuJson = ".hujson" ExtJwcc = ".jwcc" ExtYml = ".yml" ExtYaml = ".yaml" ExtToml = ".toml" ExtJsonnet = ".jsonnet" ExtXml = ".xml" )
const ( IoStdout = "<stdout>" IoStderr = "<stderr>" IoStdin = "<stdin>" IoNull = "<null>" IoDevNull = "/dev/null" IoEmpty = "" )
Variables ¶
var ( ErrDuplicateEntry = errors.New("duplicate entry") ErrEntryDoesNotExists = errors.New("entry does not exists") )
var (
DevNull = devNull{}
)
DevNull mimics /dev/null behaviour It discard on write, and return EOF on read.
var (
ErrDecoderUnsupportedType = errors.New("Decoder, unsuported type")
)
var (
ErrInvalidSemVer = errors.New("invalid Semantic Version")
)
Functions ¶
func CurrentDirFS ¶
CurrentDirFS return fs.FS for current working directory
func Interruptible ¶
Interruptible execute Runner and cancel it when SIGINT is captured. Here, context.Background is used as the parent context. By default, the function listen to os.Interrupt and syscall.SIGINT, if additional signals are needed, pass them to optional `sigs` argument.
func InterruptibleContext ¶
InterruptibleContext execute Runner and cancel it when SIGINT is captured. The argument `ctx` is used as the parent context for constructing cancelable context. By default, the function listen to os.Interrupt and syscall.SIGINT, if additional signals are needed, pass them to optional `sigs` argument.
func InterruptibleFunc ¶ added in v0.2.0
InterruptibleFunc execute runner with given function
func IsGoSrcDir ¶
func NewBytesPool ¶
NewBytesPool return pool with pre-allocated []byte Arg `cap` is opitonal, and if not specified, the capacity is 8192 bytes.
func NopReadWriteCloser ¶
func NopReadWriteCloser(rw io.ReadWriter) io.ReadWriteCloser
NopReadWriteCloser wrap io.ReadWriter with nop Close method.
func NopWriteCloser ¶
func NopWriteCloser(w io.Writer) io.WriteCloser
NopWriteCloser create writer with Close method
func ReadCloserFromDescriptor ¶
func ReadCloserFromDescriptor(desc string) (io.ReadCloser, error)
ReadCloserFromDescriptor create reader with closer from given descriptor
func ToBool ¶
ToBool convert any value to boolean Part of these code is taken from github.com/mattn/anko
func ToDuration ¶
ToDuration convert any valid duration representation to time.Duration
func UnmarshalFs ¶
UnmarshalFs decode content specified as name to dest. Arg `fa` is an array of file system, in which if its not specified, `name` will be searched from current directory (`.`). If multiple fa are specified, UnmarshalFs will finish once its succeeded to decode the content.
func WriteCloserFromDescriptor ¶
func WriteCloserFromDescriptor(desc string) (io.WriteCloser, error)
WriteCloserFromDescriptor return io.WriteCloser from given descriptr. Valid descriptor are: <null>, <stdout>, <stderr> and "desc" as filename
Types ¶
type Closers ¶
type Closers interface {
io.Closer
Append(io.Closer) Closers
Remove(io.Closer) Closers
TakeFirst() (io.Closer, bool)
TakeLast() (io.Closer, bool)
Empty() bool
Len() int
Clear()
}
Closers hold list of io.Closer
func NewClosers ¶
type Decoder ¶
Decoder decodes input file/stream/data into golang's data type.
func NewBytesDecoder ¶
NewBytesDecoder return decoder for given stream
func NewDecoder ¶
NewDecoder return decoder for given rider and ext type
func NewFsDecoder ¶
NewFsDecoder decode given file into object. Supported format and corresponding decoders are: - json: encoding/json - hjson: github.com/hjson/hjson-go/v4 - hujson, jwcc: github.com/tailscale/hujson - yaml, yml: github.com/goccy/go-yaml - toml: github.com/BurntSushi/toml - jsonnet: github.com/google/go-jsonnet
type FormattedText ¶
FormattedText has Decoder and Stringer interface
type FormattedTextFile ¶
type FormattedTextFile string
FormattedTextFile holds the filename for formatted file content. Filename extension is use to determined the content type.
func (FormattedTextFile) Decode ¶
func (f FormattedTextFile) Decode(dest any) error
func (FormattedTextFile) Ext ¶
func (f FormattedTextFile) Ext() string
func (FormattedTextFile) String ¶
func (f FormattedTextFile) String() string
type GoPackageHint ¶
type GoPackageHint struct {
Domain string
RelPath string
ImportPath string
SrcDir string
IsStdPkg bool
ModGoVersion string
Version string
HasGoMod bool
Valid bool
}
func GetGoModHint ¶
func GetGoModHint(base, importDirective, dir string) (*GoPackageHint, error)
func (*GoPackageHint) GoVariableName ¶
func (g *GoPackageHint) GoVariableName() string
func (*GoPackageHint) ID ¶
func (g *GoPackageHint) ID() string
func (*GoPackageHint) OutputFilename ¶
func (g *GoPackageHint) OutputFilename() string
func (*GoPackageHint) SanitizeImportPath ¶
func (g *GoPackageHint) SanitizeImportPath()
type GoPackageHints ¶
type GoPackageHints struct {
BaseDir string
GoVersion string
Hints []*GoPackageHint
}
func GetGoPackageHints ¶
func GetGoPackageHints(tgtVer, tgtImport, pkgSrcDir string, rootDir ...string) (*GoPackageHints, error)
func GetStdGoPackageHints ¶
func GetStdGoPackageHints(version string, rootDir ...string) (*GoPackageHints, error)
type HuJsonText ¶
type HuJsonText []byte
func (HuJsonText) Decode ¶
func (h HuJsonText) Decode(dest any) error
func (HuJsonText) Ext ¶
func (h HuJsonText) Ext() string
func (HuJsonText) String ¶
func (h HuJsonText) String() string
type JsonnetText ¶
type JsonnetText []byte
func (JsonnetText) Decode ¶
func (j JsonnetText) Decode(dest any) error
func (JsonnetText) Ext ¶
func (j JsonnetText) Ext() string
func (JsonnetText) String ¶
func (j JsonnetText) String() string
type Registry ¶
type Registry[K comparable, V any] interface { Register(k K, v V) error MustRegister(k K, v V) Exists(k K) bool Set(k K, v V) Get(k K) (V, error) MustGet(k K) V Map() map[K]V }
Registry for storing entry.
func NewRegistry ¶
func NewRegistry[K comparable, V any]() Registry[K, V]
NewRegistry create map-based registry. Please note that this registry is not safe for concurrent usage.
func NewSyncRegistry ¶
func NewSyncRegistry[K comparable, V any]() Registry[K, V]
NewRegistry create map-based registry guarded with Mutex. This registry is safe for concurrent usage.
type RunnerFunc ¶
RunnerFunc is adapter to allow function to be used as Runner
func (RunnerFunc) RunContext ¶
func (f RunnerFunc) RunContext(ctx context.Context) error