helper

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package helper consists of helping functions.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package helper consists of helping functions.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package helper consists of helping functions.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package helper consists of helping functions.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package helper consists of helping functions.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package helper consists of helping functions.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var ChannelLToS = ChannelSToL.Invert()

ChannelLToS maps long channel names to short ones

View Source
var ChannelSToL = util.Mapper{
	"email":   "https://ns.adobe.com/xdm/channel-types/email",
	"offline": "https://ns.adobe.com/xdm/channel-types/offline",
	"social":  "https://ns.adobe.com/xdm/channel-types/social",
	"web":     "https://ns.adobe.com/xdm/channel-types/web",
}

ChannelSToL maps short channel names to long ones

View Source
var ContentLToS = ContentSToL.Invert()

ContentLToS maps long content names to short ones

View Source
var ContentSToL = util.Mapper{
	"image": "https://ns.adobe.com/experience/offer-management/content-component-imagelink",
	"text":  "https://ns.adobe.com/experience/offer-management/content-component-text",
	"html":  "https://ns.adobe.com/experience/offer-management/content-component-html",
	"json":  "https://ns.adobe.com/experience/offer-management/content-component-json",
}

ContentSToL maps short content names to long ones

View Source
var FilterTypeSToL = util.Mapper{
	"all": "allTags",
	"any": "anyTags",
}

FilterTypeSToL maps short filter types to long ones

Functions

func CheckErr

func CheckErr(err error)

CheckErr prints a user friendly error message to stderr

func CheckErrEOF

func CheckErrEOF(err error)

CheckErrEOF prints a user friendly error message to stderr but ignores EOF

func CheckErrs

func CheckErrs(err ...error)

CheckErrs prints a user friendly error message to stderr

Types

type Configuration added in v0.2.0

type Configuration struct {
	Root           *util.RootConfig
	Authentication *api.AuthenticationConfig
	Read           bool
	Write          bool
}

Configuration encapsulates the global settings

func NewConfiguration added in v0.2.0

func NewConfiguration(gcfg *util.RootConfig) *Configuration

NewConfiguration creates an initialized Authentication object

func (*Configuration) AddAuthenticationFlags added in v0.2.0

func (a *Configuration) AddAuthenticationFlags(cmd *cobra.Command)

AddAuthenticationFlags adds all required flags for authentication

func (*Configuration) NoDryRun added in v0.2.0

func (a *Configuration) NoDryRun() *api.AuthenticationConfig

NoDryRun creates a copy of the current AuthenticationConfig and disables the dry-run falg

func (*Configuration) Path added in v0.2.0

func (a *Configuration) Path(path ...string) string

UniquePath generates a unique path based on the client id

func (*Configuration) ReadCache added in v0.2.0

func (a *Configuration) ReadCache() bool

ReadCache returns the read-cache flag

func (*Configuration) Sandboxed added in v0.2.0

func (a *Configuration) Sandboxed() util.PathProvider

func (*Configuration) UniqueSandboxPath added in v0.2.0

func (a *Configuration) UniqueSandboxPath(path ...string) string

UniqueSandboxPath generates a unique path based on the client id and sandbox name

func (*Configuration) Update added in v0.2.0

func (a *Configuration) Update(cmd *cobra.Command) error

Update loads the configuration and updates the command flags

func (*Configuration) Validate added in v0.2.0

func (a *Configuration) Validate(cmd *cobra.Command) error

Validate updates the command flags and validates the final configuration

func (*Configuration) WriteCache added in v0.2.0

func (a *Configuration) WriteCache() bool

WriteCache returns the write-cache flag

type Decoder

type Decoder interface {
	Decode(v interface{}) error
}

Decoder is either a YAML or JSON decoder

type DownloadConfig added in v0.2.0

type DownloadConfig struct {
	Path string
}

func (*DownloadConfig) Save added in v0.2.0

func (d *DownloadConfig) Save(res *http.Response, name string) error

type FileConfig

type FileConfig struct {
	Path   string
	Format string
}

FileConfig provides the path and format of a file

func (*FileConfig) AddFileFlag

func (c *FileConfig) AddFileFlag(cmd *cobra.Command)

AddFileFlag adds the required file flags to the passed command

func (*FileConfig) AddMandatoryFileFlag

func (c *FileConfig) AddMandatoryFileFlag(cmd *cobra.Command)

AddMandatoryFileFlag adds the required file flags to the passed command. --file becomes mandatory.

func (*FileConfig) IsSet

func (c *FileConfig) IsSet() bool

IsSet returns true if the path is set

func (*FileConfig) IsYAML

func (c *FileConfig) IsYAML() bool

IsYAML checks if format is YAML

func (*FileConfig) Open

func (c *FileConfig) Open() (*FileIterator, error)

Open opens the file and returns a *FileIterator

type FileIterator

type FileIterator struct {
	Decoder Decoder
}

FileIterator helps iterating multiple YAML documents in one file

func (*FileIterator) Load

func (c *FileIterator) Load(obj interface{}) error

Load loads the next available document in the file

type OutputConf

type OutputConf struct {
	Output string
	Type   OutputType
	// contains filtered or unexported fields
}

OutputConf contains all options for the output

func NewOutputConf

func NewOutputConf(tf Transformer) *OutputConf

NewOutputConf creates an initialized OutputConf object

func (*OutputConf) AddOutputFlags

func (o *OutputConf) AddOutputFlags(cmd *cobra.Command)

AddOutputFlags extends the passed command with flags for output

func (*OutputConf) Print added in v0.2.0

func (o *OutputConf) Print(paged api.Paged) error

func (*OutputConf) PrintTable added in v0.2.0

func (o *OutputConf) PrintTable(paged api.Paged) error

func (*OutputConf) SetTableTransformation added in v0.2.0

func (o *OutputConf) SetTableTransformation(td *util.TableDescriptor)

SetTableTransformation changes the Transformer object

func (*OutputConf) SetTransformation

func (o *OutputConf) SetTransformation(tf Transformer)

SetTransformation changes the Transformer object

func (*OutputConf) SetTransformationDesc added in v0.2.0

func (o *OutputConf) SetTransformationDesc(def string) error

SetTransformationDesc changes the Transformer object

func (*OutputConf) StreamResult added in v0.2.0

func (o *OutputConf) StreamResult(i util.JSONResponse, err error)

StreamResult prints the object in the desired output format

func (*OutputConf) StreamResultRaw added in v0.2.0

func (o *OutputConf) StreamResultRaw(res *http.Response, err error)

func (*OutputConf) ValidateFlags

func (o *OutputConf) ValidateFlags() error

ValidateFlags checks the passed flags

type OutputType

type OutputType int

OutputType is used for the encoding of different output formats

const (
	// JSONOut is used for JSON
	JSONOut OutputType = iota
	// JSONPathOut is used for JSON path
	JSONPathOut
	// YAMLOut is used for YAML
	YAMLOut
	// TableOut is used for tablized output
	TableOut
	// Wide is used for wide tablized output
	Wide
	// RawOut is used for raw output
	RawOut
)

type Transformer

type Transformer interface {
	Header(wide bool) []string
	Preprocess(util.JSONResponse) error
	WriteRow(*util.Query, *util.RowWriter, bool) error
	Iterator(io.ReadCloser) (util.JSONResponse, error)
}

Transformer objects will implement transformation logic for certain OutputTypes

Jump to

Keyboard shortcuts

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