util

package
v0.0.0-...-f342e06 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2018 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StructTag is the key we use in struct field names for key mapping.
	StructTag = "lang"
	// DBusInterface is the dbus interface that contains genereal methods.
	DBusInterface = "org.freedesktop.DBus"
	// DBusAddMatch is the dbus method to receive a subset of dbus broadcast
	// signals.
	DBusAddMatch = DBusInterface + ".AddMatch"
	// DBusRemoveMatch is the dbus method to remove a previously defined
	// AddMatch rule.
	DBusRemoveMatch = DBusInterface + ".RemoveMatch"
)

Variables

This section is empty.

Functions

func B64ToRes

func B64ToRes(str string) (engine.Res, error)

B64ToRes decodes a resource from a base64 encoded string (after deserialization).

func GetGID

func GetGID(group string) (int, error)

GetGID returns the GID of a group. It supports a GID or a group name. Caller should first check group is not empty. It will return an error if it can't lookup the GID or group name.

func GetUID

func GetUID(username string) (int, error)

GetUID returns the UID of an user. It supports an UID or an username. Caller should first check user is not empty. It will return an error if it can't lookup the UID or username.

func LangFieldNameToStructFieldName

func LangFieldNameToStructFieldName(kind string) (map[string]string, error)

LangFieldNameToStructFieldName returns the mapping from lang (AST) field names to field name as used in the struct. The logic here is a bit strange; if the resource has struct tags, then it uses those, otherwise it falls back to using the lower case versions of things. It might be clever to combine the two so that tagged fields are used as such, and others are used in lowercase, but this is currently not implemented. TODO: should this behaviour be changed?

func LangFieldNameToStructType

func LangFieldNameToStructType(kind string) (map[string]*types.Type, error)

LangFieldNameToStructType returns the mapping from lang (AST) field names, and the expected type in our type system for each.

func LowerStructFieldNameToFieldName

func LowerStructFieldNameToFieldName(res engine.Res) (map[string]string, error)

LowerStructFieldNameToFieldName returns a mapping from the lower case version of each field name to the actual field name. It only returns public fields. It returns an error if it finds a collision.

func ResToB64

func ResToB64(res engine.Res) (string, error)

ResToB64 encodes a resource to a base64 encoded string (after serialization).

func StructKindToFieldNameTypeMap

func StructKindToFieldNameTypeMap(kind string) (map[string]*types.Type, error)

StructKindToFieldNameTypeMap returns a map from field name to expected type in the lang type system.

func StructTagToFieldName

func StructTagToFieldName(res engine.Res) (map[string]string, error)

StructTagToFieldName returns a mapping from recommended alias to actual field name. It returns an error if it finds a collision. It uses the `lang` tags.

Types

This section is empty.

Jump to

Keyboard shortcuts

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