utils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	AsyncLogSuffix = "" /* 137-byte string literal not displayed */
)
View Source
const (
	EmptyNamespaceError = "no space targeted, use 'kf target --space SPACE' to target a space"
)

Variables

This section is empty.

Functions

func ConfigError

func ConfigError(err error) bool

ConfigError returns true if the error is due to user error.

func CreateProxy

func CreateProxy(w io.Writer, host, gateway string) *httputil.ReverseProxy

CreateProxy creates a proxy to the specified gateway with the specified host in the request header.

func GetBuildConfig

func GetBuildConfig() build.BuildV1alpha1Interface

GetBuildConfig returns the build interface.

func GetServingConfig

func GetServingConfig() cserving.ServingV1alpha1Interface

GetServingConfig returns the serving interface.

func NewPrefixFilter

func NewPrefixFilter(prefixes map[string]io.Writer, defaultWriter io.Writer) io.Writer

func PrintCurlExamples

func PrintCurlExamples(w io.Writer, listener net.Listener, host, gateway string, withProxy bool)

PrintCurlExamples lists example HTTP requests the user can send.

func ValidateNamespace

func ValidateNamespace(p *config.KfParams) error

ValidateNamespace validate non-empty namespace param

Types

type AsyncFlags

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

AsyncFlags is a flag set for managing whether or not a command runs asynchronously.

Example
var async AsyncFlags

cmd := &cobra.Command{
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("Running async?", async.IsAsync())
	},
}
async.Add(cmd)

cmd.SetArgs([]string{})
cmd.ExecuteC()

cmd.SetArgs([]string{"--async"})
cmd.ExecuteC()
Output:

Running async? false
Running async? true

func (*AsyncFlags) Add

func (flags *AsyncFlags) Add(cmd *cobra.Command)

Add adds the async flag to the Cobra command.

func (*AsyncFlags) AwaitAndLog

func (flags *AsyncFlags) AwaitAndLog(w io.Writer, action string, callback func() error) error

AwaitAndLog waits for the action to be completed if the flag specifies the command should run synchronously. In either case, it will notify the user of the decision by logging to the writer whether it waited or not. If an error is returned by the callback the result will be an error, otherwise the error will be nil.

func (*AsyncFlags) IsAsync

func (flags *AsyncFlags) IsAsync() bool

IsAsync returns true if the user wanted the operation to run asynchronously.

func (*AsyncFlags) IsSynchronous

func (flags *AsyncFlags) IsSynchronous() bool

IsSynchronous returns true if the user wants the operation to be completed synchronously.

Example
var async AsyncFlags

cmd := &cobra.Command{
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("Running sync?", async.IsSynchronous())
	},
}
async.Add(cmd)

cmd.SetArgs([]string{})
cmd.ExecuteC()

cmd.SetArgs([]string{"--async"})
cmd.ExecuteC()
Output:

Running sync? true
Running sync? false

type Config

type Config struct {
	Namespace   string
	Args        []string
	AllArgs     []string
	Flags       map[string][]string
	SourceImage string
	Stdout      io.Writer
	Stderr      io.Writer
}

func InBuildParseConfig

func InBuildParseConfig() Config

InBuildParseConfig is used by container images that parse args and flags.

type ConfigErr

type ConfigErr struct {
	// Reason holds the error message.
	Reason string
}

ConfigErr is used to indicate that the returned error is due to a user's invalid configuration.

func (ConfigErr) Error

func (e ConfigErr) Error() string

Error implements error.

type KfParams

type KfParams struct {
	Output    io.Writer
	Namespace string
}

KfParams stores everything needed to interact with the user and Knative.

Jump to

Keyboard shortcuts

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