Documentation ¶
Overview ¶
Package tiny provides utilities for quick prototyping HTTP/gRPC/TCP servers.
Index ¶
- func GetSecureRandomString(lengthBytes uint) (string, error)
- func LoadConfig(files ...string) error
- func SetupLogger(opts ...tinylog.Opt)
- func StartAndBlock(services ...Service)
- func TimePtrToUnix(t *time.Time) *int64
- func TimeToUnixPtr(t time.Time) *int64
- func ToPtr[V any](v V) *V
- func UnixPtrToTime(u *int64) *time.Time
- func UnixToTimePtr(u int64) *time.Time
- type Service
- type SignalHandler
- type SignalsListener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetSecureRandomString ¶
GetSecureRandomString generates a cryptographically secure string of given length. Result string is encoded to hex.
func LoadConfig ¶ added in v1.0.1
LoadConfig loads configuration from environment variables and optionally from the specified list of files. YAML, JSON and HCL file formats are supported. Configuration is stored into global config.Config instance.
func SetupLogger ¶
SetupLogger configures the global instance of zerolog.Logger. Default configuration can be overwritten by providing custom options as arguments.
func StartAndBlock ¶
func StartAndBlock(services ...Service)
StartAndBlock starts all passed services in their designated goroutines and then blocks the current thread. Thread is unblocked when the process receives SIGINT or SIGTERM signals or one of the Start() functions returns an error. When exiting, StartAndBlock gracefully stops all the services by calling their Stop() functions and waiting for them to exit.
func TimePtrToUnix ¶
TimePtrToUnix returns a pointer to epoch seconds in UTC timezone represented by given pointer to time.Time
func TimeToUnixPtr ¶
TimeToUnixPtr returns a pointer to epoch seconds in UTC timezone represented by given time.Time
func UnixPtrToTime ¶
UnixPtrToTime returns a pointer to time.Time by converting pointer to epoch seconds in UTC timezone
func UnixToTimePtr ¶
UnixToTimePtr returns a pointer to time.Time by converting epoch seconds in UTC timezone
Types ¶
type Service ¶
type Service interface { // Start is expected to start execution of the service and block. // If the execution cannot be started, or it fails abruptly, it should return a non-nil error. Start() error // Stop is expected to stop the running service gracefully and unblock the thread used by Start function. Stop() }
Service represents concurrent job, that is expected to run in background for the whole lifetime of the process. Typical implementations of Service include network servers, such as HTTP or gRPC servers.
type SignalHandler ¶
SignalHandler represents a handler function for OS signals.
type SignalsListener ¶
type SignalsListener struct {
// contains filtered or unexported fields
}
SignalsListener is a listener of OS signals that implements the Service interface.
func NewSignalsListener ¶
func NewSignalsListener(signals []os.Signal, handler SignalHandler) *SignalsListener
NewSignalsListener creates new SignalsListener.
func (*SignalsListener) Start ¶
func (s *SignalsListener) Start() error
Start implements the interface of Service.
func (*SignalsListener) Stop ¶
func (s *SignalsListener) Stop()
Stop implements the interface of Service.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package tinygrpc provides gRPC server implementation.
|
Package tinygrpc provides gRPC server implementation. |
Package tinyhttp provides HTTP server implementation.
|
Package tinyhttp provides HTTP server implementation. |
httpauth
Package httpauth provides authorization middleware for HTTP.
|
Package httpauth provides authorization middleware for HTTP. |
Package tinylog provides an automated configuration of the global zerolog.Logger.
|
Package tinylog provides an automated configuration of the global zerolog.Logger. |
Package tinypostgres provides utilities for handling Postgres.
|
Package tinypostgres provides utilities for handling Postgres. |
Package tinyredis provides utilities for handling Redis.
|
Package tinyredis provides utilities for handling Redis. |
Package tinytcp provides TCP server implementation.
|
Package tinytcp provides TCP server implementation. |