actually export everything

This commit is contained in:
2026-05-08 22:50:19 -04:00
parent 83004c3098
commit 8d2ade4d2c
+10 -10
View File
@@ -7,34 +7,34 @@ import (
"net/http" "net/http"
) )
// must panics if err is not nil // Must panics if err is not nil
func must[T any](t T, err error) T { func Must[T any](t T, err error) T {
if err != nil { if err != nil {
panic(err) panic(err)
} }
return t return t
} }
// attempt discards the value from a (value, err) function // Attempt discards the value from a (value, err) function
func attempt[T any](_ T, err error) error { func Attempt[T any](_ T, err error) error {
return err return err
} }
// try discards the error from a (value, err) function // Try discards the error from a (value, err) function
func try[T any](t T, _ error) T { func Try[T any](t T, _ error) T {
return t return t
} }
// writeJSON encodes the provided value as json and responds 200 // WriteJSON encodes the provided value as json and responds 200
func writeJSON(w http.ResponseWriter, v any) { func WriteJSON(w http.ResponseWriter, v any) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(v); err != nil { if err := json.NewEncoder(w).Encode(v); err != nil {
log.Printf("writeJSON error: %v", err) log.Printf("writeJSON error: %v", err)
} }
} }
// writeError logs and responds with the given formatted error message as `{"error": msg}` // WriteError logs and responds with the given formatted error message as `{"error": msg}`
func writeError(w http.ResponseWriter, code int, msg string, args ...any) { func WriteError(w http.ResponseWriter, code int, msg string, args ...any) {
errMsg := fmt.Sprintf(msg, args...) errMsg := fmt.Sprintf(msg, args...)
log.Println(errMsg) log.Println(errMsg)
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")