Documentation ¶
Overview ¶
Copyright 2024 Jake Nichols (MIT License)
Copyright 2024 Jake Nichols (MIT License)
Copyright 2024 Jake Nichols (MIT License)
Index ¶
- func FileReader(file string) (rc io.ReadCloser, err error)
- func FileWriter(file string, flag int, mode os.FileMode) (rc io.WriteCloser, err error)
- func HttpReader(address string) (rc io.ReadCloser, err error)
- func LocalSyslog() (io.Writer, error)
- func LogHandler(max slog.Level, tag string, out io.Writer) slog.Handler
- func LogWithSystem(l *slog.Logger, system string) *slog.Logger
- func Reader(source string) (rc io.ReadCloser, err error)
- func SockReader(kind, socket string) (rc io.ReadCloser, err error)
- func SockWriter(kind, socket string) (rc io.WriteCloser, err error)
- func Writer(source string) (rc io.WriteCloser, err error)
- type Set
- func (s *Set[T]) Add(vals ...T)
- func (s *Set[T]) Contains(val T) (found bool)
- func (s *Set[T]) Difference(u *Set[T]) (v *Set[T])
- func (s *Set[T]) ForEach(f func(val T))
- func (s *Set[T]) Intersection(u *Set[T]) (v *Set[T])
- func (s *Set[T]) Remove(val T)
- func (s *Set[T]) String() (str string)
- func (s *Set[T]) Union(u *Set[T]) (v *Set[T])
- type SyslogHandler
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 ¶
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 ¶
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 ¶
LogHandler returns a SyslogHandler with a max level and tag. The handler writes to the provided io.Writer.
func LogWithSystem ¶
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]) Contains ¶
Contains returns true if the set contains a value.
func (*Set[T]) Difference ¶
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 ¶
Intersection produces intersection(s, u), all elements in both.
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 (*SyslogHandler) Handle ¶
func (*SyslogHandler) WithAttrs ¶
func (handler *SyslogHandler) WithAttrs(attrs []slog.Attr) slog.Handler
func (*SyslogHandler) WithGroup ¶
func (handler *SyslogHandler) WithGroup(name string) slog.Handler