actually export everything
This commit is contained in:
@@ -7,34 +7,34 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// must panics if err is not nil
|
||||
func must[T any](t T, err error) T {
|
||||
// Must panics if err is not nil
|
||||
func Must[T any](t T, err error) T {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// attempt discards the value from a (value, err) function
|
||||
func attempt[T any](_ T, err error) error {
|
||||
// Attempt discards the value from a (value, err) function
|
||||
func Attempt[T any](_ T, err error) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// try discards the error from a (value, err) function
|
||||
func try[T any](t T, _ error) T {
|
||||
// Try discards the error from a (value, err) function
|
||||
func Try[T any](t T, _ error) T {
|
||||
return t
|
||||
}
|
||||
|
||||
// writeJSON encodes the provided value as json and responds 200
|
||||
func writeJSON(w http.ResponseWriter, v any) {
|
||||
// WriteJSON encodes the provided value as json and responds 200
|
||||
func WriteJSON(w http.ResponseWriter, v any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if err := json.NewEncoder(w).Encode(v); err != nil {
|
||||
log.Printf("writeJSON error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// writeError logs and responds with the given formatted error message as `{"error": msg}`
|
||||
func writeError(w http.ResponseWriter, code int, msg string, args ...any) {
|
||||
// WriteError logs and responds with the given formatted error message as `{"error": msg}`
|
||||
func WriteError(w http.ResponseWriter, code int, msg string, args ...any) {
|
||||
errMsg := fmt.Sprintf(msg, args...)
|
||||
log.Println(errMsg)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
Reference in New Issue
Block a user