decoder

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: JSON Imports: 9 Imported by: 1

Documentation

Overview

Package decoder provide a way to decode credentials from a service to a structure It provide a cloud tag to help user match the correct credentials

This is what you can pass as a structure:

// Name is key of a service credentials, decoder will look at any matching credentials which have the key name and will pass the value of this credentials
	Name    string `cloud:"name"`           // note: by default if you don't provide a cloud tag the key will be the field name in snake_case
	Uri     decoder.ServiceUri              // ServiceUri is a special type. Decoder will expect an uri as a value and will give a ServiceUri
	User    string `cloud:".*user.*,regex"` // by passing `regex` in cloud tag it will say to decoder that the expected key must be match the regex
	Password string `cloud:".*user.*,regex" cloud-default:"apassword"` // by passing a tag named `cloud-default` decoder will understand that if the key is not found it must fill the field with this value
    Aslice   []string `cloud:"aslice" cloud-default:"value1,value2"` // you can also pass a slice
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewErrDecode

func NewErrDecode(content string) error

func NewErrTypeNotSupported

func NewErrTypeNotSupported(field reflect.Value) error

func Unmarshal

func Unmarshal(serviceCredentials map[string]interface{}, obj interface{}) error

Decode a map of credentials into a structure

func UnmarshalNoDefault

func UnmarshalNoDefault(serviceCredentials map[string]interface{}, obj interface{}) error

Decode a map of credentials into a structure without default values

func UnmarshalToValue

func UnmarshalToValue(serviceCredentials map[string]interface{}, ps reflect.Value, noDefaultVal bool) error

Decode a map of credentials into a reflected Value

Types

type ErrDecode

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

func (ErrDecode) Error

func (e ErrDecode) Error() string

type ErrTypeNotSupported

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

func (ErrTypeNotSupported) Error

func (e ErrTypeNotSupported) Error() string

type QueryUri

type QueryUri struct {
	Key   string
	Value string
}

type ServiceUri

type ServiceUri struct {
	Username string
	Password string
	Scheme   string
	Host     string
	Name     string
	Query    []QueryUri
	RawQuery string
	Port     int
}

type Tag

type Tag struct {
	Name         string
	Skip         bool
	IsRegex      bool
	DefaultValue string
}

type Unmarshaler

type Unmarshaler interface {
	UnmarshalCloud(data interface{}) error
}

The Unmarshaler interface may be implemented by types to customize their behavior when being unmarshaled from a Map cloud. The UnmarshalCloud method receives a function that may be called to unmarshal the original value into a field or variable. It is safe to call the unmarshal function parameter more than once if necessary.

Jump to

Keyboard shortcuts

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