utils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 27 Imported by: 2

Documentation

Overview

Package utils contains utility functions

Package utils contails useful helper functions

Package utils contains utility functions

Package utils has some utility functions and interfaces

Package utils has some utility functions and interfaces

Package utils has some utility functions and interfaces

Package utils contains utility functions

Package utils contails useful helper functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualProtoSlices added in v0.2.0

func EqualProtoSlices[T proto.Message](x, y []T) bool

EqualProtoSlices is a helper function to compare protobuf slices

func ExtractPagination added in v0.2.0

func ExtractPagination(pageSize int32, pageToken string, pagination map[string]int) (size int, offset int, err error)

ExtractPagination fetches pagination from the database, calculate size and offset

func InitTracerProvider added in v0.2.0

func InitTracerProvider(service string) *sdktrace.TracerProvider

InitTracerProvider returns an OpenTelemetry TracerProvider configured to use the OTLP exporter that will send spans to OTEL_EXPORTER_OTLP_ENDPOINT url. The returned // TracerProvider will also use a Resource configured with all the information about the application.

func InterceptorLogger added in v0.2.0

func InterceptorLogger(l *log.Logger) logging.Logger

InterceptorLogger creates logger for interceptors based on default Go logger

func LimitPagination added in v0.2.0

func LimitPagination[T any](result []T, offset int, size int) ([]T, bool)

LimitPagination returns subset of the slice per gived size and offset

func ProtoClone added in v0.2.0

func ProtoClone[T proto.Message](protoStruct T) T

ProtoClone is a helper function to clone and cast protobufs

func SetupTLSCredentials added in v0.2.0

func SetupTLSCredentials(config TLSConfig) (grpc.ServerOption, error)

SetupTLSCredentials returns a service options to enable TLS for gRPC server

Types

type Frr added in v0.2.0

type Frr interface {
	TelnetDialAndCommunicate(ctx context.Context, command string, port int) (string, error)
	FrrZebraCmd(ctx context.Context, command string) (string, error)
	FrrBgpCmd(ctx context.Context, command string) (string, error)
	Password(conn *telnet.Conn, delim string) error
	EnterPrivileged(conn *telnet.Conn) error
	ExitPrivileged(conn *telnet.Conn) error
}

Frr represents limited subset of functions from Frr package

type FrrWrapper added in v0.2.0

type FrrWrapper struct {
	// contains filtered or unexported fields
}

FrrWrapper wrapper for Frr package

func NewFrrWrapper added in v0.2.0

func NewFrrWrapper() *FrrWrapper

NewFrrWrapper creates initialized instance of FrrWrapper with default address

func NewFrrWrapperWithArgs added in v0.2.0

func NewFrrWrapperWithArgs(address string) *FrrWrapper

NewFrrWrapperWithArgs creates initialized instance of FrrWrapper

func (*FrrWrapper) EnterPrivileged added in v0.2.0

func (n *FrrWrapper) EnterPrivileged(conn *telnet.Conn) error

EnterPrivileged turns on privileged mode command

func (*FrrWrapper) ExitPrivileged added in v0.2.0

func (n *FrrWrapper) ExitPrivileged(conn *telnet.Conn) error

ExitPrivileged turns off privileged mode command

func (*FrrWrapper) FrrBgpCmd added in v0.2.0

func (n *FrrWrapper) FrrBgpCmd(ctx context.Context, command string) (string, error)

FrrBgpCmd connects to Bgp telnet with password and runs command

func (*FrrWrapper) FrrZebraCmd added in v0.2.0

func (n *FrrWrapper) FrrZebraCmd(ctx context.Context, command string) (string, error)

FrrZebraCmd connects to Zebra telnet with password and runs command

func (*FrrWrapper) MultiLineCmd added in v0.2.0

func (n *FrrWrapper) MultiLineCmd(conn *telnet.Conn, command string) (string, error)

MultiLineCmd breaks command by lines, sends each and waits for output and returns combined output

func (*FrrWrapper) Password added in v0.2.0

func (n *FrrWrapper) Password(conn *telnet.Conn, delim string) error

Password handles password sending

func (*FrrWrapper) TelnetDialAndCommunicate added in v0.2.0

func (n *FrrWrapper) TelnetDialAndCommunicate(ctx context.Context, command string, port int) (string, error)

TelnetDialAndCommunicate connects to telnet with password and runs command

Netlink represents limited subset of functions from netlink package

type NetlinkWrapper struct {
	// contains filtered or unexported fields
}

NetlinkWrapper wrapper for netlink package

func NewNetlinkWrapper() *NetlinkWrapper

NewNetlinkWrapper creates initialized instance of NetlinkWrapper

func (*NetlinkWrapper) AddrAdd

func (n *NetlinkWrapper) AddrAdd(ctx context.Context, link netlink.Link, addr *netlink.Addr) error

AddrAdd is a wrapper for netlink.AddrAdd

func (*NetlinkWrapper) AddrDel

func (n *NetlinkWrapper) AddrDel(ctx context.Context, link netlink.Link, addr *netlink.Addr) error

AddrDel is a wrapper for netlink.AddrDel

func (*NetlinkWrapper) BridgeVlanAdd

func (n *NetlinkWrapper) BridgeVlanAdd(ctx context.Context, link netlink.Link, vid uint16, pvid, untagged, self, master bool) error

BridgeVlanAdd is a wrapper for netlink.BridgeVlanAdd

func (*NetlinkWrapper) BridgeVlanDel

func (n *NetlinkWrapper) BridgeVlanDel(ctx context.Context, link netlink.Link, vid uint16, pvid, untagged, self, master bool) error

BridgeVlanDel is a wrapper for netlink.BridgeVlanDel

func (*NetlinkWrapper) LinkAdd

func (n *NetlinkWrapper) LinkAdd(ctx context.Context, link netlink.Link) error

LinkAdd is a wrapper for netlink.LinkAdd

func (*NetlinkWrapper) LinkByName

func (n *NetlinkWrapper) LinkByName(ctx context.Context, name string) (netlink.Link, error)

LinkByName is a wrapper for netlink.LinkByName

func (*NetlinkWrapper) LinkDel

func (n *NetlinkWrapper) LinkDel(ctx context.Context, link netlink.Link) error

LinkDel is a wrapper for netlink.LinkDel

func (*NetlinkWrapper) LinkModify

func (n *NetlinkWrapper) LinkModify(ctx context.Context, link netlink.Link) error

LinkModify is a wrapper for netlink.LinkModify

func (*NetlinkWrapper) LinkSetDown

func (n *NetlinkWrapper) LinkSetDown(ctx context.Context, link netlink.Link) error

LinkSetDown is a wrapper for netlink.LinkSetDown

func (*NetlinkWrapper) LinkSetHardwareAddr

func (n *NetlinkWrapper) LinkSetHardwareAddr(ctx context.Context, link netlink.Link, hwaddr net.HardwareAddr) error

LinkSetHardwareAddr is a wrapper for netlink.LinkSetHardwareAddr

func (*NetlinkWrapper) LinkSetMaster

func (n *NetlinkWrapper) LinkSetMaster(ctx context.Context, link, master netlink.Link) error

LinkSetMaster is a wrapper for netlink.LinkSetMaster

func (*NetlinkWrapper) LinkSetNoMaster

func (n *NetlinkWrapper) LinkSetNoMaster(ctx context.Context, link netlink.Link) error

LinkSetNoMaster is a wrapper for netlink.LinkSetNoMaster

func (*NetlinkWrapper) LinkSetUp

func (n *NetlinkWrapper) LinkSetUp(ctx context.Context, link netlink.Link) error

LinkSetUp is a wrapper for netlink.LinkSetUp

type ProtoCodec added in v0.2.0

type ProtoCodec struct{}

ProtoCodec encodes/decodes Go values to/from PROTOBUF.

func (ProtoCodec) Marshal added in v0.2.0

func (c ProtoCodec) Marshal(v interface{}) ([]byte, error)

Marshal encodes a Go value to PROTOBUF.

func (ProtoCodec) Unmarshal added in v0.2.0

func (c ProtoCodec) Unmarshal(data []byte, v interface{}) error

Unmarshal decodes a PROTOBUF value into a Go value.

type TLSConfig added in v0.2.0

type TLSConfig struct {
	ServerCertPath string
	ServerKeyPath  string
	CaCertPath     string
}

TLSConfig contains information required to enable TLS for gRPC server.

func ParseTLSFiles added in v0.2.0

func ParseTLSFiles(tlsFiles string) (TLSConfig, error)

ParseTLSFiles parses a string containing server certificate, server key and CA certificate separated by `:`

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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