marshal

package
v0.1.0-memsql Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Example
type Name struct {
	FirstName string `scim:"givenName"`
	LastName  string `scim:"familyName"`
}

type ResourceStruct struct {
	UserName string
	Name     Name
}

resourceStruct := ResourceStruct{
	UserName: "di-wu",
	Name: Name{
		FirstName: "Quint",
		LastName:  "Daenen",
	},
}

r, _ := Marshal(resourceStruct)
fmt.Println(r)

resourceMap := map[string]interface{}{
	"userName": "di-wu",
	"name": map[string]interface{}{
		"givenName":  "Quint",
		"familyName": "Daenen",
	},
}

var resource ResourceStruct
_ = Unmarshal(resourceMap, &resource)
fmt.Println(resource)
Output:

map[name:map[familyName:Daenen givenName:Quint] userName:di-wu]
{di-wu {Quint Daenen}}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(value interface{}) (map[string]interface{}, error)

func Unmarshal

func Unmarshal(data map[string]interface{}, value interface{}) error
Example
var r testUnmarshalInterface
_ = Unmarshal(map[string]interface{}{
	"name": "Quint",
}, &r)
fmt.Println(r)
Output:

{Quint}
Example (Extension)
type EnterpriseUserExtension struct {
	EmployeeNumber string
}

type User struct {
	UserName       string
	EnterpriseUser EnterpriseUserExtension `scim:"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User"`
}

var user User
_ = Unmarshal(map[string]interface{}{
	"userName": "di-wu",
	"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User": map[string]interface{}{
		"employeeNumber": "0001",
	},
}, &user)
fmt.Println(user)
Output:

{di-wu {0001}}

Types

type IDMarshaler

type IDMarshaler interface {
	MarshalSCIMUUID() (string, error)
}

type IDUnMarshaler

type IDUnMarshaler interface {
	UnmarshalSCIMUUID(interface{}) error
}

type Marshaler

type Marshaler interface {
	MarshalSCIM() (map[string]interface{}, error)
}

Marshaler is the interface implemented by types that can marshal themselves into SCIM resources.

type Unmarshaler

type Unmarshaler interface {
	UnmarshalSCIM(map[string]interface{}) error
}

Unmarshaler is the interface implemented by types that can unmarshal a SCIM description of themselves.

Jump to

Keyboard shortcuts

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