maps

package
v0.3.89 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromStruct

func FromStruct(v any) (map[string]any, error)

FromStruct is a helper function to make map[string]any from struct

func Get

func Get[T any](data map[string]any, path string, defaults ...T) T

Get is a helper function to get value from map[string]any it's posible to get value from nested map by using dot (.) as separator

Example
package main

import (
	"fmt"

	"github.com/gowok/gowok/maps"
)

func main() {
	var m = map[string]any{
		"mantap": "jos",
		"gandos": map[string]any{
			"jos": "yoi",
		},
	}

	fmt.Println(maps.Get[string](m, "gandos.jos"))
}
Output:
yoi

func MapToStruct deprecated

func MapToStruct(data any, v any) error

MapToStruct is a helper function to convert map[string]any to struct

Deprecated: Use ToStruct instead.

func ToStruct

func ToStruct(data map[string]any, v any) error

ToStruct is a helper function to convert map[string]any to struct

Example
package main

import (
	"fmt"

	"github.com/gowok/gowok/maps"
)

func main() {
	type Config struct {
		Host string `json:"host"`
	}

	var m = map[string]any{
		"host": "localhost",
	}

	var c Config
	err := maps.ToStruct(m, &c)
	if err != nil {
		panic(err)
	}

	fmt.Println(c.Host)
}
Output:
localhost

Types

This section is empty.

Jump to

Keyboard shortcuts

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