converter

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2020 License: MIT Imports: 5 Imported by: 3

README

converter

converter est une librairie en Go pour convertir des variables entre elles.

Installation

La librairie peut être installée dans le répertoire $GOPATH via la commande suivante :

go get framagit.org/benjamin.vaudour/converter

ou bien être utilisée directement dans un projet (nécessite Go ≥ 1.12) via un import :

import (
	"framagit.org/benjamin.vaudour/converter"
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone(e interface{}, deep ...bool) interface{}

Clone retourne une copie de l’élément fournit en paramètre. Si deep est fourni et vaut true, le clonage s’effectue récursivement.

func Convert

func Convert(src, dest interface{}, safe ...bool) bool

Convert convertit la valeur du paramètre source vers le paramètre destination et retourne true si l’opération s’est effectuée avec succès. La destination doit être un pointeur, afin de pouvoir modifier sa valeur. Si le paramètre optionnel safe est fourni et vaut true, la destination n’est modifiée que si son type est équivalent à celui de la source (par exemple int vers int64, mais pas int vers string).

func IsBool

func IsBool(e interface{}) bool

func IsBoolMap

func IsBoolMap(e interface{}) bool

func IsBoolSet

func IsBoolSet(e interface{}) bool

func IsBoolSlice

func IsBoolSlice(e interface{}) bool

func IsByte

func IsByte(e interface{}) bool

func IsByteMap

func IsByteMap(e interface{}) bool

func IsByteSet

func IsByteSet(e interface{}) bool

func IsByteSlice

func IsByteSlice(e interface{}) bool

func IsChar

func IsChar(e interface{}) bool

func IsCollection

func IsCollection(e interface{}) bool

func IsElement

func IsElement(e interface{}) bool

func IsFloat

func IsFloat(e interface{}) bool

func IsFloatMap

func IsFloatMap(e interface{}) bool

func IsFloatSet

func IsFloatSet(e interface{}) bool

func IsFloatSlice

func IsFloatSlice(e interface{}) bool

func IsGenericMap

func IsGenericMap(e interface{}) bool

func IsGenericSet

func IsGenericSet(e interface{}) bool

func IsGenericSlice

func IsGenericSlice(e interface{}) bool

func IsInt

func IsInt(e interface{}) bool

func IsIntMap

func IsIntMap(e interface{}) bool

func IsIntSet

func IsIntSet(e interface{}) bool

func IsIntSlice

func IsIntSlice(e interface{}) bool

func IsInterface

func IsInterface(e interface{}) bool

func IsInvalid

func IsInvalid(e interface{}) bool

func IsMap

func IsMap(e interface{}) bool

func IsNil

func IsNil(e interface{}) bool

func IsNumber

func IsNumber(e interface{}) bool

func IsPointer

func IsPointer(e interface{}) bool

func IsRune

func IsRune(e interface{}) bool

func IsRuneMap

func IsRuneMap(e interface{}) bool

func IsRuneSet

func IsRuneSet(e interface{}) bool

func IsRuneSlice

func IsRuneSlice(e interface{}) bool

func IsSet

func IsSet(e interface{}) bool

func IsSlice

func IsSlice(e interface{}) bool

func IsString

func IsString(e interface{}) bool

func IsStringMap

func IsStringMap(e interface{}) bool

func IsStringSet

func IsStringSet(e interface{}) bool

func IsStringSlice

func IsStringSlice(e interface{}) bool

func IsStruct

func IsStruct(e interface{}) bool

func IsUint

func IsUint(e interface{}) bool

func IsUintMap

func IsUintMap(e interface{}) bool

func IsUintSet

func IsUintSet(e interface{}) bool

func IsUintSlice

func IsUintSlice(e interface{}) bool

func IsZero

func IsZero(e interface{}) bool

func PointerOf

func PointerOf(e interface{}) interface{}

PointerOf retourne un pointeur vers une variable ayant la même valeur que le paramètre d’entrée.

func SetZero

func SetZero(dst interface{}) bool

SetZero réinitialise la variable pointée par le paramètre d’entrée à sa valeur initiale

func ToBool

func ToBool(src interface{}, safe ...bool) (dest bool, ok bool)

func ToBoolMap added in v1.0.2

func ToBoolMap(src interface{}, safe ...bool) (dest map[string]bool, ok bool)

func ToBoolSet added in v1.0.2

func ToBoolSet(src interface{}, safe ...bool) (dest map[bool]bool, ok bool)

func ToBoolSlice added in v1.0.2

func ToBoolSlice(src interface{}, safe ...bool) (dest []bool, ok bool)

func ToByte

func ToByte(src interface{}, safe ...bool) (dest byte, ok bool)

func ToByteMap added in v1.0.2

func ToByteMap(src interface{}, safe ...bool) (dest map[string]byte, ok bool)

func ToByteSet added in v1.0.2

func ToByteSet(src interface{}, safe ...bool) (dest map[byte]bool, ok bool)

func ToByteSlice added in v1.0.2

func ToByteSlice(src interface{}, safe ...bool) (dest []byte, ok bool)

func ToFloat

func ToFloat(src interface{}, safe ...bool) (dest float64, ok bool)

func ToFloatMap added in v1.0.2

func ToFloatMap(src interface{}, safe ...bool) (dest map[string]float64, ok bool)

func ToFloatSet added in v1.0.2

func ToFloatSet(src interface{}, safe ...bool) (dest map[float64]bool, ok bool)

func ToFloatSlice added in v1.0.2

func ToFloatSlice(src interface{}, safe ...bool) (dest []float64, ok bool)

func ToInt

func ToInt(src interface{}, safe ...bool) (dest int, ok bool)

func ToIntMap added in v1.0.2

func ToIntMap(src interface{}, safe ...bool) (dest map[string]int, ok bool)

func ToIntSet added in v1.0.2

func ToIntSet(src interface{}, safe ...bool) (dest map[int]bool, ok bool)

func ToIntSlice added in v1.0.2

func ToIntSlice(src interface{}, safe ...bool) (dest []int, ok bool)

func ToInterface

func ToInterface(src interface{}, safe ...bool) (dest interface{}, ok bool)

func ToMap

func ToMap(src interface{}, safe ...bool) (dest map[string]interface{}, ok bool)

func ToRune

func ToRune(src interface{}, safe ...bool) (dest rune, ok bool)

func ToRuneMap added in v1.0.2

func ToRuneMap(src interface{}, safe ...bool) (dest map[string]rune, ok bool)

func ToRuneSet added in v1.0.2

func ToRuneSet(src interface{}, safe ...bool) (dest map[rune]bool, ok bool)

func ToRuneSlice added in v1.0.2

func ToRuneSlice(src interface{}, safe ...bool) (dest []rune, ok bool)

func ToSet

func ToSet(src interface{}, safe ...bool) (dest map[interface{}]bool, ok bool)

func ToSlice

func ToSlice(src interface{}, safe ...bool) (dest []interface{}, ok bool)

func ToString

func ToString(src interface{}, safe ...bool) (dest string, ok bool)

func ToStringMap added in v1.0.2

func ToStringMap(src interface{}, safe ...bool) (dest map[string]string, ok bool)

func ToStringSet added in v1.0.2

func ToStringSet(src interface{}, safe ...bool) (dest map[string]bool, ok bool)

func ToStringSlice added in v1.0.2

func ToStringSlice(src interface{}, safe ...bool) (dest []string, ok bool)

func ToUint

func ToUint(src interface{}, safe ...bool) (dest uint, ok bool)

func ToUintMap added in v1.0.2

func ToUintMap(src interface{}, safe ...bool) (dest map[string]uint, ok bool)

func ToUintSet added in v1.0.2

func ToUintSet(src interface{}, safe ...bool) (dest map[uint]bool, ok bool)

func ToUintSlice added in v1.0.2

func ToUintSlice(src interface{}, safe ...bool) (dest []uint, ok bool)

func ValueOf

func ValueOf(e interface{}) interface{}

ValueOf retourne la valeur pointée paramètre d’entrée. Si le paramètre n’est pas un pointeur, elle retourne le paramètre lui-même.

func ZeroOf

func ZeroOf(e interface{}) interface{}

ZeroOf retourne le zéro du type du paramètre d’entrée.

Types

type Checker

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

Checker est une structure permettant d’analyser finement les propriétés d’une variable en recherchant les classes auxquelles elle appartient.

func NewChecker

func NewChecker(e interface{}) *Checker

NewChecker retourne un checker pour analyser le paramètre fourni.

func (*Checker) AllClasses

func (c *Checker) AllClasses() Classes

AllClasses retournes toutes les classes d’appartenance de la valeur : - Type général/sur-ensemble, - Sous-ensemble éventuel dans le cas des collections, - Classes d’état (Nil et Zero).

func (*Checker) IsBool

func (c *Checker) IsBool() bool

func (*Checker) IsBoolMap

func (c *Checker) IsBoolMap() bool

func (*Checker) IsBoolSet

func (c *Checker) IsBoolSet() bool

func (*Checker) IsBoolSlice

func (c *Checker) IsBoolSlice() bool

func (*Checker) IsByte

func (c *Checker) IsByte() bool

func (*Checker) IsByteMap

func (c *Checker) IsByteMap() bool

func (*Checker) IsByteSet

func (c *Checker) IsByteSet() bool

func (*Checker) IsByteSlice

func (c *Checker) IsByteSlice() bool

func (*Checker) IsChar

func (c *Checker) IsChar() bool

func (*Checker) IsCollection

func (c *Checker) IsCollection() bool

func (*Checker) IsElement

func (c *Checker) IsElement() bool

func (*Checker) IsFloat

func (c *Checker) IsFloat() bool

func (*Checker) IsFloatMap

func (c *Checker) IsFloatMap() bool

func (*Checker) IsFloatSet

func (c *Checker) IsFloatSet() bool

func (*Checker) IsFloatSlice

func (c *Checker) IsFloatSlice() bool

func (*Checker) IsGenericMap

func (c *Checker) IsGenericMap() bool

func (*Checker) IsGenericSet

func (c *Checker) IsGenericSet() bool

func (*Checker) IsGenericSlice

func (c *Checker) IsGenericSlice() bool

func (*Checker) IsInt

func (c *Checker) IsInt() bool

func (*Checker) IsIntMap

func (c *Checker) IsIntMap() bool

func (*Checker) IsIntSet

func (c *Checker) IsIntSet() bool

func (*Checker) IsIntSlice

func (c *Checker) IsIntSlice() bool

func (*Checker) IsInterface

func (c *Checker) IsInterface() bool

func (*Checker) IsInvalid

func (c *Checker) IsInvalid() bool

func (*Checker) IsMap

func (c *Checker) IsMap() bool

func (*Checker) IsNil

func (c *Checker) IsNil() bool

IsNil est équivalent à la méthode IsZero de reflect.Value à la différence qu’aucun panic n’est généré en cas de valeur non nilable.

func (*Checker) IsNumber

func (c *Checker) IsNumber() bool

func (*Checker) IsPointer

func (c *Checker) IsPointer() bool

func (*Checker) IsRune

func (c *Checker) IsRune() bool

func (*Checker) IsRuneMap

func (c *Checker) IsRuneMap() bool

func (*Checker) IsRuneSet

func (c *Checker) IsRuneSet() bool

func (*Checker) IsRuneSlice

func (c *Checker) IsRuneSlice() bool

func (*Checker) IsSet

func (c *Checker) IsSet() bool

func (*Checker) IsSlice

func (c *Checker) IsSlice() bool

func (*Checker) IsString

func (c *Checker) IsString() bool

func (*Checker) IsStringMap

func (c *Checker) IsStringMap() bool

func (*Checker) IsStringSet

func (c *Checker) IsStringSet() bool

func (*Checker) IsStringSlice

func (c *Checker) IsStringSlice() bool

func (*Checker) IsStruct

func (c *Checker) IsStruct() bool

func (*Checker) IsUint

func (c *Checker) IsUint() bool

func (*Checker) IsUintMap

func (c *Checker) IsUintMap() bool

func (*Checker) IsUintSet

func (c *Checker) IsUintSet() bool

func (*Checker) IsUintSlice

func (c *Checker) IsUintSlice() bool

func (*Checker) IsZero

func (c *Checker) IsZero() bool

IsZero est équivalent à la méthode IsZero de reflect.Value à la différence qu’aucun panic n’est généré en cas de valeur de type reflect.Invalid

func (*Checker) Kind

func (c *Checker) Kind() reflect.Kind

func (*Checker) KindClass

func (c *Checker) KindClass() Classes

KindClass retourne la liste des classes de premier niveau

func (*Checker) MapClass

func (c *Checker) MapClass() Classes

MapClass retourne la sous-classe d’un élément de type Map

func (*Checker) SetClass

func (c *Checker) SetClass() Classes

SetClass retourne la sous-classe d’un élément de type Set

func (*Checker) SliceClass

func (c *Checker) SliceClass() Classes

SliceClass retourne la sous-classe d’un élément de type Slice

func (*Checker) Type

func (c *Checker) Type() reflect.Type

func (*Checker) Value

func (c *Checker) Value() reflect.Value

type Class

type Class uint

Class permet de classifier les types de données. On y retrouve : - Les classes standard implémentées dans reflect: Ptr, Struct, String, etc. - Des sur-ensembles de classes: Element, Number, Collection, etc. - Des sous-emsembles de classes (nécessitant d’analyser le type plus en profondeur): [*]Slice, [*]Map et [*]Set - Des classes décrivant l’état de la valeur de la donnée : Zero et Nil

À noter que certains types de données reflect ne sont pas géré par converter: Chan, Func, etc. Par ailleurs, la terminologie pour les type de nombres est quelque peut différente par rapport à reflect : - Int regroupe tous les type d’entiers (int, int8, int16, int32, int64) - Float regroupe tous les nombres à virgule flottante (float32, float64) - Contrairement à reflect, une distinction est faite entre les entiers purs et les entiers décrivant des caractères (rune et byte)

Concernant les variables de type map[typeKey]typeValue, seules sont supportées : - map[string]elementType (regroupées sous la classe Map) - map[elementType]bool (regroupées sous la classe Set) Tous les autres types de map sont rattachés uniquement à la classe Collection.

const (
	Invalid Class = iota
	Zero
	Nil
	Ptr
	Struct
	Interface
	Element
	Number
	Char
	Collection
	Slice
	Map
	Set
	Bool
	Int
	Uint
	Float
	Rune
	Byte
	String
	GenericSlice
	BoolSlice
	IntSlice
	UintSlice
	FloatSlice
	RuneSlice
	ByteSlice
	StringSlice
	GenericMap
	BoolMap
	IntMap
	UintMap
	FloatMap
	RuneMap
	ByteMap
	StringMap
	GenericSet
	BoolSet
	IntSet
	UintSet
	FloatSet
	RuneSet
	ByteSet
	StringSet
)

type Classes

type Classes map[Class]bool

Classes est un ensemble de classes

func NewClasses

func NewClasses(classes ...Class) Classes

func (Classes) Add

func (l Classes) Add(classes ...Class) Classes

func (Classes) Remove

func (l Classes) Remove(classes ...Class) Classes

Jump to

Keyboard shortcuts

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