helper

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 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.

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

func NameToID

func NameToID(koc *util.ObjectCache) util.Mapper

NameToID creates a name -> @id mapper from the passed ObjectCache

func NewActivityCache

func NewActivityCache(ac *AutoContainer) *util.KVCache

NewActivityCache creats a new name -> instanceId cache

func NewActivityIDCache

func NewActivityIDCache(ac *AutoContainer) *util.KVCache

NewActivityIDCache creats a new name -> @id cache

func NewCache

func NewCache(ac *AutoContainer, file, schema string, key []string, value []string) *util.KVCache

NewCache creates a new persistent cache for JSON objects

func NewCollectionCache

func NewCollectionCache(ac *AutoContainer) *util.KVCache

NewCollectionCache creats a new name -> instanceId cache

func NewCollectionIDCache

func NewCollectionIDCache(ac *AutoContainer) *util.KVCache

NewCollectionIDCache creats a new name -> @id cache

func NewContainerCache

func NewContainerCache(auth *Authentication) *util.KVCache

NewContainerCache creates a new container cache

func NewFallbackCache

func NewFallbackCache(ac *AutoContainer) *util.KVCache

NewFallbackCache creats a new name -> instanceId cache

func NewFallbackIDCache

func NewFallbackIDCache(ac *AutoContainer) *util.KVCache

NewFallbackIDCache creats a new name -> @id cache

func NewNameToID

func NewNameToID(auth *Authentication, schema string) *util.KVCache

NewNameToID resolves name to @id

func NewNameToInstanceID

func NewNameToInstanceID(auth *Authentication, schema string) *util.KVCache

NewNameToInstanceID resolves name to @id

func NewObjectCache

func NewObjectCache(ac *AutoContainer, schema string) *util.ObjectCache

NewObjectCache creates a new object cache

func NewOfferCache

func NewOfferCache(ac *AutoContainer) *util.KVCache

NewOfferCache creats a new name -> instanceId cache

func NewOfferIDCache

func NewOfferIDCache(ac *AutoContainer) *util.KVCache

NewOfferIDCache creats a new name -> @id cache

func NewPlacementCache

func NewPlacementCache(ac *AutoContainer) *util.KVCache

NewPlacementCache creats a new name -> instanceId cache

func NewPlacementIDCache

func NewPlacementIDCache(ac *AutoContainer) *util.KVCache

NewPlacementIDCache creats a new name -> @id cache

func NewPlacementsCache

func NewPlacementsCache(ac *AutoContainer) *util.ObjectCache

NewPlacementsCache creates a cache for placement objects

func NewRuleCache

func NewRuleCache(ac *AutoContainer) *util.KVCache

NewRuleCache creats a new name -> instanceId cache

func NewRuleIDCache

func NewRuleIDCache(ac *AutoContainer) *util.KVCache

NewRuleIDCache creats a new name -> @id cache

func NewSandboxCache

func NewSandboxCache(auth *Authentication) *util.StringCache

NewSandboxCache creates a new sandbox cache

func NewTagCache

func NewTagCache(ac *AutoContainer) *util.KVCache

NewTagCache creats a new name -> instanceId cache

func NewTagIDCache

func NewTagIDCache(ac *AutoContainer) *util.KVCache

NewTagIDCache creats a new name -> @id cache

func NewTemporaryCache

func NewTemporaryCache(ac *AutoContainer, schema string, key []string, value []string) *util.KVCache

NewTemporaryCache creates a new temporary cache for JSON objects

Types

type Authentication

type Authentication struct {
	Config *api.AuthenticationConfig
	Read   bool
	Write  bool
	AC     *AutoContainer
	AS     *util.KVCache
	TS     *util.KVCache
	PS     *util.KVCache
	OS     *util.KVCache
	FS     *util.KVCache
	CS     *util.KVCache
	RS     *util.KVCache
}

Authentication encapsulates the authentication configuration

func NewAuthentication

func NewAuthentication() *Authentication

NewAuthentication creates an initialized Authentication object

func (*Authentication) AddAuthenticationFlags

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

AddAuthenticationFlags adds all required flags for authentication

func (*Authentication) NoDryRun

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

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

func (*Authentication) ReadCache

func (a *Authentication) ReadCache() bool

ReadCache returns the read-cache flag

func (*Authentication) UniquePath

func (a *Authentication) UniquePath(path ...string) []string

UniquePath generates a unique path based on the client id

func (*Authentication) UniqueSandboxPath

func (a *Authentication) UniqueSandboxPath(path ...string) []string

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

func (*Authentication) Validate added in v0.1.1

func (a *Authentication) Validate() error

func (*Authentication) WriteCache

func (a *Authentication) WriteCache() bool

WriteCache returns the write-cache flag

type AutoContainer

type AutoContainer struct {
	ContainerID string
	Store       *util.KVCache
	Auth        *Authentication
}

AutoContainer resolves autmatically the container id

func NewAutoContainer

func NewAutoContainer(auth *Authentication) *AutoContainer

NewAutoContainer creates an initialized AutoContainer object

func (*AutoContainer) AddContainerFlag

func (q *AutoContainer) AddContainerFlag(cmd *cobra.Command)

AddContainerFlag adds the required container flags to the passed command

func (*AutoContainer) AutoFillContainer

func (q *AutoContainer) AutoFillContainer() error

AutoFillContainer retrieves the container id

func (*AutoContainer) UniquePath

func (q *AutoContainer) UniquePath(path ...string) []string

UniquePath generates a unique path based on the client id, sandbox name and container id

type Decoder

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

Decoder is either a YAML or JSON decoder

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) PrintResult

func (o *OutputConf) PrintResult(obj interface{}, err error)

PrintResult prints the object in the desired output format

func (*OutputConf) SetTransformation

func (o *OutputConf) SetTransformation(tf Transformer)

SetTransformation 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
	// Wide is used for wide tablized output
	Wide
)

type Transformer

type Transformer interface {
	ToTable(interface{}) (*util.Table, error)
	ToWideTable(interface{}) (*util.Table, error)
}

Transformer objects will implement transformation logic for certain OutputTypes type Transformer func(interface{}) (interface{}, error)

type TransformerMap

type TransformerMap map[OutputType]Transformer

TransformerMap is a map of transformers

Jump to

Keyboard shortcuts

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