internal

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package files contains file-related utilities.

Copyright © 2023 NAME HERE <EMAIL ADDRESS>

Index

Constants

View Source
const (
	Usage = `` /* 1186-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func Generate

func Generate(dir string, pkgs []string, opt Options) error

Generate generates Kod code for the specified packages. The list of supplied packages are treated similarly to the arguments passed to "go build" (see "go help packages" for details).

func ImportsCode

func ImportsCode(code string) ([]byte, error)

func Struct2Interface added in v0.2.0

func Struct2Interface(cmd *cobra.Command, dir string) error

func Watch added in v0.2.0

func Watch(watcher Watcher, dir string, callback func(), verbose bool)

Watch watches the directory and calls the callback function when a file is modified.

Types

type Method

type Method struct {
	Code string
	Docs []string
}

func (*Method) Lines

func (m *Method) Lines() []string

type Options

type Options struct {
	// If non-nil, use the specified function to report warnings.
	Warn func(error)
}

Options controls the operation of Generate.

type Watcher added in v0.2.0

type Watcher interface {
	Add(string) error
	Remove(string) error
	Events() chan fsnotify.Event
	Errors() chan error
}

type Writer

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

Writer writes a sequence of bytes to a file. In case of errors, the old file contents remain untouched since the writes are applied atomically when the Writer is closed.

func NewWriter

func NewWriter(file string) *Writer

NewWriter returns a writer that writes to the named files.

The caller should eventually call Cleanup. A recommended pattern is:

w := files.NewWriter(dst)
defer w.Cleanup()
... write to w ...
err := w.Close()

func (*Writer) Cleanup

func (w *Writer) Cleanup()

Cleanup releases any resources in use by the writer, without attempting to write collected bytes to the destination. It is safe to call Cleanup() even if Close or Cleanup have already been called.

func (*Writer) Close

func (w *Writer) Close() error

Close saves the written bytes to the destination file and closes the writer. Close returns an error if any errors were encountered, including during earlier Write calls.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write writes p and returns the number of bytes written, which will either be len(p), or the returned error will be non-nil.

Jump to

Keyboard shortcuts

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