Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { PanicHandler func(c Context, err error) Responder LogLevel LogLevel Logger Logger }
Config provides service configuration for service clients.
type Context ¶
type Context interface { // Request returns the http request. Request() Request // Response returns an http response with the given status code. // An options response body can be provided as the second // argument. Response(status int, body ...any) Responder // LogDebug logs the given message. Arguments are handled in the // manner of fmt.Printf. LogDebug(message string, args ...any) // LogInfo logs the given message. Arguments are handled in the // manner of fmt.Printf. LogInfo(message string, args ...any) // LogNotice logs the given message. Arguments are handled in the // manner of fmt.Printf. LogNotice(message string, args ...any) // LogWarning logs the given message. Arguments are handled in // the manner of fmt.Printf. LogWarning(message string, args ...any) // LogError logs the given message. Arguments are handled in the // manner of fmt.Printf. LogError(message string, args ...any) // LogCritical logs the given message. Arguments are handled in // the manner of fmt.Printf. LogCritical(message string, args ...any) // LogAlert logs the given message. Arguments are handled in the // manner of fmt.Printf. LogAlert(message string, args ...any) // LogEmergency logs the given message. Arguments are handled in // the manner of fmt.Printf. LogEmergency(message string, args ...any) }
Context is the central piece of golamb. It allows one to access a requests query parameters, path parameters, body, headers, and cookies. Messages can be logged to the provided logger according to the provided log level.
type DefaultLogger ¶ added in v0.1.5
type DefaultLogger struct {
// contains filtered or unexported fields
}
DefaultLogger logs messages to os.Stdout, which is sent to CloudWatch logs.
func (*DefaultLogger) Log ¶ added in v0.1.5
func (l *DefaultLogger) Log(level LogLevel, message any)
Log implements the Logger interface.
type LogLevel ¶ added in v0.1.5
type LogLevel int
LogLevel as defined in the RFC 5424 specification.
const ( // LogLevelDebug as defined in the RFC 5424 specification. LogLevelDebug LogLevel = 0 // LogLevelInfo as defined in the RFC 5424 specification. LogLevelInfo LogLevel = 1 // LogLevelNotice as defined in the RFC 5424 specification. LogLevelNotice LogLevel = 2 // LogLevelWarning as defined in the RFC 5424 specification. LogLevelWarning LogLevel = 3 // LogLevelError as defined in the RFC 5424 specification. LogLevelError LogLevel = 4 // LogLevelCritical as defined in the RFC 5424 specification. LogLevelCritical LogLevel = 5 // LogLevelAlert as defined in the RFC 5424 specification. LogLevelAlert LogLevel = 6 // LogLevelEmergency as defined in the RFC 5424 specification. LogLevelEmergency LogLevel = 7 // LogLevelSilent logs nothing. LogLevelSilent LogLevel = math.MaxInt )
type Logger ¶ added in v0.1.5
Logger is used to log messages.
func NewDefaultLogger ¶ added in v0.1.5
func NewDefaultLogger() Logger
NewDefaultLogger returns the default logger.
type Request ¶
type Request interface { // Query returns the query parameter with the given key. Query(key string) string // Path returns the path parameter with the given key. Path(key string) string // Body parses the JSON-encoded data and stores the result in the // value pointed to by v. Body(v any) error // Cookie returns the cookie with the given name. Cookie(name string) *http.Cookie // Header returns the header value with the given key. Header(key string) string // Headers returns a map of all the headers. Headers() map[string]string // RawPath returns the raw path. RawPath() string }
Request holds the http request data.
type Responder ¶
type Responder interface { // Respond responds to the http request. Respond() (*events.APIGatewayV2HTTPResponse, error) // SetHeader sets a response header with the given key and value. SetHeader(key string, value string) Responder // SetCookie sets a response cookie with the given key and value. SetCookie(cookie *http.Cookie) Responder }
Responder responds to the request.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.