util

package
v0.0.0-...-1887219 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2019 License: GPL-3.0 Imports: 13 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"
	// DBusSystemd1Path is the base systemd1 path.
	DBusSystemd1Path = "/org/freedesktop/systemd1"
	// DBusSystemd1Iface is the base systemd1 interface.
	DBusSystemd1Iface = "org.freedesktop.systemd1"
	// DBusSystemd1ManagerIface is the systemd manager interface used for
	// interfacing with systemd units.
	DBusSystemd1ManagerIface = DBusSystemd1Iface + ".Manager"
	// DBusRestartUnit is the dbus method for restarting systemd units.
	DBusRestartUnit = DBusSystemd1ManagerIface + ".RestartUnit"
	// DBusStopUnit is the dbus method for stopping systemd units.
	DBusStopUnit = DBusSystemd1ManagerIface + ".StopUnit"
	// DBusSignalJobRemoved is the name of the dbus signal that produces a
	// message when a dbus job is done (or has errored.)
	DBusSignalJobRemoved = "JobRemoved"
)

Variables

This section is empty.

Functions

func AutoEdgeCombiner

func AutoEdgeCombiner(ae ...engine.AutoEdge) (engine.AutoEdge, error)

AutoEdgeCombiner takes any number of AutoEdge structs, and combines them into a single one, so that the logic from each one can be built separately, and then combined using this utility. This makes implementing different AutoEdge generators much easier. This respects the Next() and Test() API, and ratchets through each AutoEdge entry until they have all run their course.

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 RestartUnit

func RestartUnit(ctx context.Context, conn *dbus.Conn, unit string) error

RestartUnit resarts the given dbus unit and waits for it to finish starting.

func StopUnit

func StopUnit(ctx context.Context, conn *dbus.Conn, unit string) error

StopUnit stops the given dbus unit and waits for it to finish stopping.

func StrListCmp

func StrListCmp(x, y []string) error

StrListCmp compares two lists of strings. If they are not the same length or do not contain identical strings in the same order, then this errors.

func StructFieldCompat

func StructFieldCompat(st1 interface{}, key1 string, st2 interface{}, key2 string) error

StructFieldCompat returns whether a send struct and key is compatible with a recv struct and key. This inputs must both be a ptr to a string, and a valid key that can be found in the struct tag. TODO: add a bool to decide if *string to string or string to *string is okay.

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(stptr interface{}) (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. It must be passed a ptr to a struct or it will error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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