decoder

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: JSON Imports: 8 Imported by: 1

Documentation

Overview

Package decoder provide a way to decode credentials from a service to a structure It provides 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

Unmarshal Decode a map of credentials into a structure

func UnmarshalNoDefault

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

UnmarshalNoDefault 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

UnmarshalToValue 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
}

Unmarshaler This interface may be implemented by types to customize their behavior when being unmarshalled 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