gokit

package module
v0.0.0-...-b688e8a Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 11 Imported by: 4

Documentation

Overview

Copyright 2024 Jake Nichols (MIT License)

Copyright 2024 Jake Nichols (MIT License)

Copyright 2024 Jake Nichols (MIT License)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileReader

func FileReader(file string) (rc io.ReadCloser, err error)

fileReader gets an io.ReadCloser for a file. Requires removing the file:// prefix.

func FileWriter

func FileWriter(file string, flag int, mode os.FileMode) (rc io.WriteCloser, err error)

fileWriter gets an io.WriteCloser for a file. Requires removing the file:// prefix.

func HttpReader

func HttpReader(address string) (rc io.ReadCloser, err error)

httpReader gets an io.ReadCloser as the response to a GET request to the provided URI.

func LocalSyslog

func LocalSyslog() (io.Writer, error)

LocalSyslog returns an io.Writer to the unix socket at /dev/log. This is generally good enough to connect to the local syslog daemon on linux systems, which is what I personally wanted out of this whole thing, but your mileage may vary.

func LogHandler

func LogHandler(max slog.Level, tag string, out io.Writer) slog.Handler

LogHandler returns a SyslogHandler with a max level and tag. The handler writes to the provided io.Writer.

func LogWithSystem

func LogWithSystem(l *slog.Logger, system string) *slog.Logger

WithSystem returns a copy of l with the attribute system=[system]. This is useful for propagating loggers while maintaining unique information about each user, but isn't based on any standard or anything, I just like the pattern

func Reader

func Reader(source string) (rc io.ReadCloser, err error)

Reader opens a source for reading. Sources are formatted type://xxx, and the following types are supported:

  • file: files
  • http, https: GET over HTTP
  • unix, unixgram, unixpacket: UNIX socket
  • tcp, tcp4, tcp6: TCP socket
  • udp, udp4, udp6: UDP socket

Reader supports (sane) relative paths for files and unix sockets; starting with ~/ will use your home directory, .. is resolved, and paths not starting with / will be treated relative to the working directory.

HTTP(S) requests are very basic GET requests.

Reader returns a ReadCloser--you need to close it after you're done.

func SockReader

func SockReader(kind, socket string) (rc io.ReadCloser, err error)

func SockWriter

func SockWriter(kind, socket string) (rc io.WriteCloser, err error)

func Writer

func Writer(source string) (rc io.WriteCloser, err error)

Writer opens a source for writing. Sources are formatted type://xxx, and the following types are supported:

  • file: files (truncate/create)
  • unix, unixgram, unixpacket: UNIX socket
  • tcp, tcp4, tcp6: TCP socket
  • udp, udp4, udp6: UDP socket

Writing over HTTP is not supported.

Writer supports (sane) relative paths for files and unix sockets; starting with ~/ will use your home directory, .. is resolved, and paths not starting with / will be treated relative to the working directory.

Writer returns a WriteCloser--you need to close it after you're done.

Types

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

Set is an unordered collection of unique values optimized for read speed. It accepts any Ordered type as a type parameter, which allows binary search when doing a Contains operation. It's much faster--see set_test.go.

func NewSet

func NewSet[T comparable]() (s *Set[T])

func (*Set[T]) Add

func (s *Set[T]) Add(vals ...T)

Add adds values to the set.

func (*Set[T]) Contains

func (s *Set[T]) Contains(val T) (found bool)

Contains returns true if the set contains a value.

func (*Set[T]) Difference

func (s *Set[T]) Difference(u *Set[T]) (v *Set[T])

Difference produces difference(s, u), all elements in s not in u.

func (*Set[T]) ForEach

func (s *Set[T]) ForEach(f func(val T))

ForEach iterates over the set values and runs f for each.

func (*Set[T]) Intersection

func (s *Set[T]) Intersection(u *Set[T]) (v *Set[T])

Intersection produces intersection(s, u), all elements in both.

func (*Set[T]) Remove

func (s *Set[T]) Remove(val T)

Remove removes a value from the set.

func (*Set[T]) String

func (s *Set[T]) String() (str string)

func (*Set[T]) Union

func (s *Set[T]) Union(u *Set[T]) (v *Set[T])

Union produces union(s, u), all elements in either.

type SyslogHandler

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

SyslogHandler implements slog.Handler and formats messages in the rfc3164 format

func (*SyslogHandler) Enabled

func (handler *SyslogHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*SyslogHandler) Handle

func (handler *SyslogHandler) Handle(ctx context.Context, r slog.Record) error

func (*SyslogHandler) WithAttrs

func (handler *SyslogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*SyslogHandler) WithGroup

func (handler *SyslogHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

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