helper

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: Apache-2.0 Imports: 19 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.

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 AddPagingFlags added in v0.3.2

func AddPagingFlags(params *api.PageParams, flags *pflag.FlagSet)

func AddPagingFlagsToken added in v0.3.2

func AddPagingFlagsToken(params *api.PageParams, flags *pflag.FlagSet)

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 CheckErrInfo added in v0.3.1

func CheckErrInfo(err error)

func CheckErrParams added in v0.3.0

func CheckErrParams(params api.ParametersE) *api.Request

func CheckErrs

func CheckErrs(err ...error)

CheckErrs prints a user friendly error message to stderr

func PrintError added in v0.3.1

func PrintError(msg string, cmd *cobra.Command)

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
	Default  string
	Type     OutputType
	Truncate bool
	Flush    bool
	Paging   bool
	// contains filtered or unexported fields
}

OutputConf contains all options for the output

func (*OutputConf) AddOutputFlags

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

AddOutputFlags extends the passed command with flags for output

func (*OutputConf) AddOutputFlagsPaging added in v0.3.2

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

AddOutputFlags extends the passed command with flags for output

func (*OutputConf) PrintPaged added in v0.3.0

func (o *OutputConf) PrintPaged(pager *Pager) error

func (*OutputConf) PrintResponse added in v0.3.0

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

func (*OutputConf) PrintTable added in v0.2.0

func (o *OutputConf) PrintTable(pager *Pager) error

PrintTable prints out multiple JSON responses into one table

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) 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
	// WideOut is used for wide tablized output
	WideOut
	// RawOut is used for raw output
	RawOut
	// PVOut is using two columns path and value
	PVOut
	// PVOut is using three columns name, value and path
	NVPOUT
)

type Pager added in v0.3.0

type Pager struct {
	Func         api.Func
	Auth         *api.AuthenticationConfig
	Requests     []*api.Request
	Context      context.Context
	PageFilter   []string
	ObjectFilter []string
	PagePath     []string
	PageParams   []string
	// contains filtered or unexported fields
}

Pager executes a REST function and handles automatically the subsequent calls to get paged responses

func NewPager added in v0.3.0

func NewPager(f api.Func, auth *api.AuthenticationConfig, requests ...*api.Request) *Pager

NewPager creates an initialzed Pager object. It uses JSONFilter to process payload and paging data.

func (*Pager) Call added in v0.3.0

func (p *Pager) Call() error

Call executes the REST function

func (*Pager) Next added in v0.3.0

func (p *Pager) Next() bool

Next returns true, if a REST call can be executed

func (*Pager) OF added in v0.3.0

func (p *Pager) OF(path ...string) *Pager

OF sets the object filter. The object is the payload of the JSON document

func (*Pager) P added in v0.3.0

func (p *Pager) P(params ...string) *Pager

P sets the page parameters. These are the URL query parameters which are necessary for the following paging requests

func (*Pager) PF added in v0.3.0

func (p *Pager) PF(path ...string) *Pager

PF sets the page filter

func (*Pager) PP added in v0.3.0

func (p *Pager) PP(path ...string) *Pager

PP sets the page path

func (*Pager) Prepare added in v0.3.0

func (p *Pager) Prepare()

func (*Pager) Run added in v0.3.0

func (p *Pager) Run() error

Run executes all REST calls

func (*Pager) RunOnce added in v0.3.2

func (p *Pager) RunOnce() error

RunOnce executes only one REST call

func (*Pager) SetObjectHandler added in v0.3.0

func (p *Pager) SetObjectHandler(f func(util.JSONResponse) error)

Add adds the handler for the payload with the passed path

func (*Pager) SingleCall added in v0.3.0

func (p *Pager) SingleCall() (*http.Response, error)

type RefTransformer added in v0.3.0

type RefTransformer struct {
	Path []string
}

func NewRefTransformer added in v0.3.0

func NewRefTransformer(path ...string) *RefTransformer

func (*RefTransformer) Header added in v0.3.0

func (t *RefTransformer) Header(wide bool) []string

func (*RefTransformer) Iterator added in v0.3.0

func (t *RefTransformer) Iterator(c *util.JSONCursor) (util.JSONResponse, error)

func (*RefTransformer) Preprocess added in v0.3.0

func (t *RefTransformer) Preprocess(i util.JSONResponse) error

func (*RefTransformer) WriteRow added in v0.3.0

func (t *RefTransformer) WriteRow(q *util.Query, w *util.RowWriter, wide bool) error

type Transformer

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

Transformer objects will implement transformation logic for certain OutputTypes

type TreeTransformer added in v0.3.0

type TreeTransformer struct {
	Path []string
}

func NewTreeTransformer added in v0.3.0

func NewTreeTransformer(path ...string) *TreeTransformer

func (*TreeTransformer) Header added in v0.3.0

func (t *TreeTransformer) Header(wide bool) []string

func (*TreeTransformer) Iterator added in v0.3.0

func (*TreeTransformer) Preprocess added in v0.3.0

func (t *TreeTransformer) Preprocess(i util.JSONResponse) error

func (*TreeTransformer) WriteRow added in v0.3.0

func (t *TreeTransformer) WriteRow(q *util.Query, w *util.RowWriter, wide bool) error

Jump to

Keyboard shortcuts

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