Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

git.fractalqb.de/fractalqb/daq

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git.fractalqb.de/fractalqb/daq

  • v0.11.0
  • Go
  • Socket score

Version published
Created
Source

daq – Data Queries

Access nested properties in Go data structures.

Go Reference Go Report Card

Go code for working with dynamic data structures can sometimes become somewhat verbose. E.g. like this:

var data any
json.Unmarshal([]byte(`{
	"glossary": {
		"title": "example glossary",
		"GlossDiv": {
			"title": "S",
			"GlossList": {
				"GlossEntry": {
					"ID": "SGML",
					"GlossTerm": "Standard Generalized Markup Language"
				}
			}
		}
	}
}`), &data)

title := "-no title-"
jObj, ok := data.(map[string]any)
if !ok {
	fmt.Println(title)
	return
}
if data = jObj["glossary"]; data == nil {
	fmt.Println(title)
	return
}
if jObj, ok = data.(map[string]any); !ok {
	fmt.Println(title)
	return
}
if data = jObj["title"]; data == nil {
	fmt.Println(title)
	return
}
title, _ = data.(string)

fmt.Println(title)
// Output:
// example glossary

Package daq helps for example to make it much more concise:

var data any
json.Unmarshal([]byte(`{
	"glossary": {
		"title": "example glossary",
		"GlossDiv": {
			"title": "S",
			"GlossList": {
				"GlossEntry": {
					"ID": "SGML",
					"GlossTerm": "Standard Generalized Markup Language"
				}
			}
		}
	}
}`), &data)

title := StringOr("-no title-")(Get(data, "glossary", "title"))

fmt.Println(title)
// Output:
// example glossary

In addition, daq can do even more, e.g. evaluate static data structures with the same API, iterate and … please consult the reference.

FAQs

Package last updated on 10 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc