Documentation ¶
Index ¶
- func BytesToPrivateKey(priv []byte) (*rsa.PrivateKey, error)
- func BytesToPublicKey(pub []byte) (*rsa.PublicKey, error)
- func DecryptWithPrivateKey(ciphertext []byte, priv *rsa.PrivateKey) ([]byte, error)
- func EncryptWithPublicKey(msg []byte, pub *rsa.PublicKey) ([]byte, error)
- func GenerateKeyPair(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error)
- func GetLogEntry(r *http.Request) *slog.Logger
- func GetRequestIdLogger(r *http.Request) *slog.Logger
- func Identify() string
- func LimitIPMiddleware(limiter *KeyRateLimiter) func(next http.Handler) http.Handler
- func LogAllStatuses(r *http.Request)
- func LogEntrySetAttrs(r *http.Request, attrs ...any)
- func LogEntrySetField(r *http.Request, key string, value interface{})
- func LogEntrySetFields(r *http.Request, fields map[string]interface{})
- func LogHeaders(r *http.Request)
- func NewStructuredLogger(handler slog.Handler, onlyErrs bool) func(next http.Handler) http.Handler
- func PrivateKeyToBytes(priv *rsa.PrivateKey) []byte
- func Protection(next http.Handler) http.Handler
- func PublicKeyToBytes(pub *rsa.PublicKey) ([]byte, error)
- func RealIPFromRequest(r *http.Request) string
- func Recoverer(next http.Handler) http.Handler
- func RequestForwardedHostProtoMiddleware(next http.Handler) http.Handler
- func RequestHost(r *http.Request) (host string)
- func RequestProto(r *http.Request) (proto string)
- type ErrResponse
- type KeyCountLimiter
- type KeyRateLimiter
- type StringLimiter
- type StructuredLogger
- type StructuredLoggerEntry
- type UniqueKeyLimiter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesToPrivateKey ¶
func BytesToPrivateKey(priv []byte) (*rsa.PrivateKey, error)
Convert bytes (pem) to private key
func BytesToPublicKey ¶
Convert bytes (pem) to public key
func DecryptWithPrivateKey ¶
func DecryptWithPrivateKey(ciphertext []byte, priv *rsa.PrivateKey) ([]byte, error)
Decrypt message using private key
func EncryptWithPublicKey ¶
Encrypt message using public key
func GenerateKeyPair ¶
Generates private and public key
func Identify ¶
func Identify() string
Identify returns name of package, file name and line number of place where panic occurs
func LimitIPMiddleware ¶
func LimitIPMiddleware(limiter *KeyRateLimiter) func(next http.Handler) http.Handler
func LogAllStatuses ¶
func LogEntrySetAttrs ¶
func LogEntrySetField ¶
func LogEntrySetFields ¶
func LogHeaders ¶
func NewStructuredLogger ¶
StructuredLogger is a simple, but powerful implementation of a custom structured logger backed on log/slog. I encourage users to copy it, adapt it and make it their own. Also take a look at https://github.com/go-chi/httplog for a dedicated pkg based on this work, designed for context-based http routers. Example: logger := slog.New(slog.NewJSONHandler(os.Stdout, nil)) slog.SetDefault(logger) hlog := NewStructuredLogger(slog.Default().Handler(), true)
func PrivateKeyToBytes ¶
func PrivateKeyToBytes(priv *rsa.PrivateKey) []byte
Convert private key to bytes (pem)
func PublicKeyToBytes ¶
Convert public key to bytes (pem)
func RealIPFromRequest ¶
func RequestHost ¶
func RequestProto ¶
Types ¶
type ErrResponse ¶
type ErrResponse struct { Err error `json:"-"` // low-level runtime error HTTPStatusCode int `json:"-"` // http response status code StatusText string `json:"status"` // user-level status message AppCode int64 `json:"code,omitempty"` // application-specific error code ErrorText string `json:"error,omitempty"` // application-level error message, for debugging }
func (*ErrResponse) Error ¶
func (e *ErrResponse) Error() string
func (*ErrResponse) Render ¶
func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error
type KeyCountLimiter ¶
type KeyCountLimiter struct {
// contains filtered or unexported fields
}
func NewKeyCountLimiter ¶
func NewKeyCountLimiter(b int) *KeyCountLimiter
func (*KeyCountLimiter) Allow ¶
func (i *KeyCountLimiter) Allow(key, countKey string) bool
type KeyRateLimiter ¶
type KeyRateLimiter struct {
// contains filtered or unexported fields
}
func NewKeyRateLimiter ¶
func NewKeyRateLimiter(r rate.Limit, b int) *KeyRateLimiter
func (*KeyRateLimiter) GetKeyLimiter ¶
func (i *KeyRateLimiter) GetKeyLimiter(key string) *rate.Limiter
type StringLimiter ¶
type StructuredLogger ¶
func (*StructuredLogger) NewLogEntry ¶
func (l *StructuredLogger) NewLogEntry(r *http.Request) middleware.LogEntry
type StructuredLoggerEntry ¶
func (*StructuredLoggerEntry) Panic ¶
func (l *StructuredLoggerEntry) Panic(v interface{}, stack []byte)